Patchwork [2,of,3,V2] chg: replace abortmsg showing errno with abortmsge

login
register
mail settings
Submitter Jun Wu
Date April 5, 2016, 4:47 p.m.
Message ID <94d4bd939733ded7d2c9.1459874875@x1c>
Download mbox | patch
Permalink /patch/14382/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - April 5, 2016, 4:47 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1459865761 -3600
#      Tue Apr 05 15:16:01 2016 +0100
# Node ID 94d4bd939733ded7d2c97c4b89b889775e565f11
# Parent  ff4f30f94e7d54bd36ed4a8a06faa99a0ac44298
chg: replace abortmsg showing errno with abortmsge

Since we have abortmsge now, use it to show human friendly error messages
across platforms.
Simon Farnsworth - April 5, 2016, 5:21 p.m.
On 05/04/2016 17:47, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1459865761 -3600
> #      Tue Apr 05 15:16:01 2016 +0100
> # Node ID 94d4bd939733ded7d2c97c4b89b889775e565f11
> # Parent  ff4f30f94e7d54bd36ed4a8a06faa99a0ac44298
> chg: replace abortmsg showing errno with abortmsge
>
> Since we have abortmsge now, use it to show human friendly error messages
> across platforms.
>

Trivial: s/abortmsge/abortmsgerrno/g in the commit message.

Otherwise, the patches look good to me.

> diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
> --- a/contrib/chg/chg.c
> +++ b/contrib/chg/chg.c
> @@ -114,13 +114,12 @@
>   	int r;
>   	r = mkdir(sockdir, 0700);
>   	if (r < 0 && errno != EEXIST)
> -		abortmsg("cannot create sockdir %s (errno = %d)",
> -			 sockdir, errno);
> +		abortmsgerrno("cannot create sockdir %s", sockdir);
>
>   	struct stat st;
>   	r = lstat(sockdir, &st);
>   	if (r < 0)
> -		abortmsg("cannot stat %s (errno = %d)", sockdir, errno);
> +		abortmsgerrno("cannot stat %s", sockdir);
>   	if (!S_ISDIR(st.st_mode))
>   		abortmsg("cannot create sockdir %s (file exists)", sockdir);
>   	if (st.st_uid != geteuid() || st.st_mode & 0077)
> @@ -166,11 +165,12 @@
>   	if (opts->lockfd == -1) {
>   		opts->lockfd = open(opts->lockfile, O_RDWR | O_CREAT | O_NOFOLLOW, 0600);
>   		if (opts->lockfd == -1)
> -			abortmsg("cannot create lock file %s", opts->lockfile);
> +			abortmsgerrno("cannot create lock file %s",
> +				      opts->lockfile);
>   	}
>   	int r = flock(opts->lockfd, LOCK_EX);
>   	if (r == -1)
> -		abortmsg("cannot acquire lock");
> +		abortmsgerrno("cannot acquire lock");
>   }
>
>   /*
> @@ -224,9 +224,9 @@
>   	argv[argsize - 1] = NULL;
>
>   	if (putenv("CHGINTERNALMARK=") != 0)
> -		abortmsg("failed to putenv (errno = %d)", errno);
> +		abortmsgerrno("failed to putenv");
>   	if (execvp(hgcmd, (char **)argv) < 0)
> -		abortmsg("failed to exec cmdserver (errno = %d)", errno);
> +		abortmsgerrno("failed to exec cmdserver");
>   	free(argv);
>   }
>
> @@ -325,7 +325,7 @@
>   {
>   	assert(peerpid > 0);
>   	if (kill(peerpid, sig) < 0)
> -		abortmsg("cannot kill %d (errno = %d)", peerpid, errno);
> +		abortmsgerrno("cannot kill %d", peerpid);
>   	debugmsg("forward signal %d", sig);
>   }
>
> @@ -358,7 +358,7 @@
>   	return;
>
>   error:
> -	abortmsg("failed to handle stop signal (errno = %d)", errno);
> +	abortmsgerrno("failed to handle stop signal");
>   }
>
>   static void setupsignalhandler(pid_t pid)
> @@ -397,7 +397,7 @@
>   	return;
>
>   error:
> -	abortmsg("failed to set up signal handlers (errno = %d)", errno);
> +	abortmsgerrno("failed to set up signal handlers");
>   }
>
>   /* This implementation is based on hgext/pager.py (pre 369741ef7253) */
> @@ -432,8 +432,7 @@
>
>   		int r = execlp("/bin/sh", "/bin/sh", "-c", pagercmd, NULL);
>   		if (r < 0) {
> -			abortmsg("cannot start pager '%s' (errno = %d)",
> -				 pagercmd, errno);
> +			abortmsgerrno("cannot start pager '%s'", pagercmd);
>   		}
>   		return;
>   	}
> @@ -441,7 +440,7 @@
>   error:
>   	close(pipefds[0]);
>   	close(pipefds[1]);
> -	abortmsg("failed to prepare pager (errno = %d)", errno);
> +	abortmsgerrno("failed to prepare pager");
>   }
>
>   /* Run instructions sent from the server like unlink and set redirect path
> @@ -514,7 +513,7 @@
>   {
>   	debugmsg("execute original hg");
>   	if (execvp(gethgcmd(), (char **)argv) < 0)
> -		abortmsg("failed to exec original hg (errno = %d)", errno);
> +		abortmsgerrno("failed to exec original hg");
>   }
>
>   int main(int argc, const char *argv[], const char *envp[])
> diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
> --- a/contrib/chg/hgclient.c
> +++ b/contrib/chg/hgclient.c
> @@ -141,7 +141,7 @@
>   	while (p < endp) {
>   		ssize_t r = send(sockfd, p, endp - p, 0);
>   		if (r < 0)
> -			abortmsg("cannot communicate (errno = %d)", errno);
> +			abortmsgerrno("cannot communicate");
>   		p += r;
>   	}
>   }
> @@ -374,7 +374,7 @@
>   	msgh.msg_controllen = cmsg->cmsg_len;
>   	ssize_t r = sendmsg(hgc->sockfd, &msgh, 0);
>   	if (r < 0)
> -		abortmsg("sendmsg failed (errno = %d)", errno);
> +		abortmsgerrno("sendmsg failed");
>
>   	handleresponse(hgc);
>   	int32_t n;
> @@ -389,7 +389,7 @@
>   static void chdirtocwd(hgclient_t *hgc)
>   {
>   	if (!getcwd(hgc->ctx.data, hgc->ctx.maxdatasize))
> -		abortmsg("failed to getcwd (errno = %d)", errno);
> +		abortmsgerrno("failed to getcwd");
>   	hgc->ctx.datasize = strlen(hgc->ctx.data);
>   	writeblockrequest(hgc, "chdir");
>   }
> @@ -414,15 +414,15 @@
>   {
>   	int fd = socket(AF_UNIX, SOCK_STREAM, 0);
>   	if (fd < 0)
> -		abortmsg("cannot create socket (errno = %d)", errno);
> +		abortmsgerrno("cannot create socket");
>
>   	/* don't keep fd on fork(), so that it can be closed when the parent
>   	 * process get terminated. */
>   	int flags = fcntl(fd, F_GETFD);
>   	if (flags < 0)
> -		abortmsg("cannot get flags of socket (errno = %d)", errno);
> +		abortmsgerrno("cannot get flags of socket");
>   	if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
> -		abortmsg("cannot set flags of socket (errno = %d)", errno);
> +		abortmsgerrno("cannot set flags of socket");
>
>   	struct sockaddr_un addr;
>   	addr.sun_family = AF_UNIX;
> @@ -434,8 +434,7 @@
>   		close(fd);
>   		if (errno == ENOENT || errno == ECONNREFUSED)
>   			return NULL;
> -		abortmsg("cannot connect to %s (errno = %d)",
> -			 addr.sun_path, errno);
> +		abortmsgerrno("cannot connect to %s", addr.sun_path);
>   	}
>   	debugmsg("connected to %s", addr.sun_path);
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=mEgSWILcY4c4W3zjApBQLA&m=gAfSCjc1l-rxs7HPmOaKDefhH7gcsKNyjbwdwF7QMGc&s=lda6nnfXbs1FvHkytUXFcQx8ax1J98Rm5lVhZgzK8EY&e=
>

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -114,13 +114,12 @@ 
 	int r;
 	r = mkdir(sockdir, 0700);
 	if (r < 0 && errno != EEXIST)
-		abortmsg("cannot create sockdir %s (errno = %d)",
-			 sockdir, errno);
+		abortmsgerrno("cannot create sockdir %s", sockdir);
 
 	struct stat st;
 	r = lstat(sockdir, &st);
 	if (r < 0)
-		abortmsg("cannot stat %s (errno = %d)", sockdir, errno);
+		abortmsgerrno("cannot stat %s", sockdir);
 	if (!S_ISDIR(st.st_mode))
 		abortmsg("cannot create sockdir %s (file exists)", sockdir);
 	if (st.st_uid != geteuid() || st.st_mode & 0077)
@@ -166,11 +165,12 @@ 
 	if (opts->lockfd == -1) {
 		opts->lockfd = open(opts->lockfile, O_RDWR | O_CREAT | O_NOFOLLOW, 0600);
 		if (opts->lockfd == -1)
-			abortmsg("cannot create lock file %s", opts->lockfile);
+			abortmsgerrno("cannot create lock file %s",
+				      opts->lockfile);
 	}
 	int r = flock(opts->lockfd, LOCK_EX);
 	if (r == -1)
-		abortmsg("cannot acquire lock");
+		abortmsgerrno("cannot acquire lock");
 }
 
 /*
@@ -224,9 +224,9 @@ 
 	argv[argsize - 1] = NULL;
 
 	if (putenv("CHGINTERNALMARK=") != 0)
-		abortmsg("failed to putenv (errno = %d)", errno);
+		abortmsgerrno("failed to putenv");
 	if (execvp(hgcmd, (char **)argv) < 0)
-		abortmsg("failed to exec cmdserver (errno = %d)", errno);
+		abortmsgerrno("failed to exec cmdserver");
 	free(argv);
 }
 
@@ -325,7 +325,7 @@ 
 {
 	assert(peerpid > 0);
 	if (kill(peerpid, sig) < 0)
-		abortmsg("cannot kill %d (errno = %d)", peerpid, errno);
+		abortmsgerrno("cannot kill %d", peerpid);
 	debugmsg("forward signal %d", sig);
 }
 
@@ -358,7 +358,7 @@ 
 	return;
 
 error:
-	abortmsg("failed to handle stop signal (errno = %d)", errno);
+	abortmsgerrno("failed to handle stop signal");
 }
 
 static void setupsignalhandler(pid_t pid)
@@ -397,7 +397,7 @@ 
 	return;
 
 error:
-	abortmsg("failed to set up signal handlers (errno = %d)", errno);
+	abortmsgerrno("failed to set up signal handlers");
 }
 
 /* This implementation is based on hgext/pager.py (pre 369741ef7253) */
@@ -432,8 +432,7 @@ 
 
 		int r = execlp("/bin/sh", "/bin/sh", "-c", pagercmd, NULL);
 		if (r < 0) {
-			abortmsg("cannot start pager '%s' (errno = %d)",
-				 pagercmd, errno);
+			abortmsgerrno("cannot start pager '%s'", pagercmd);
 		}
 		return;
 	}
@@ -441,7 +440,7 @@ 
 error:
 	close(pipefds[0]);
 	close(pipefds[1]);
-	abortmsg("failed to prepare pager (errno = %d)", errno);
+	abortmsgerrno("failed to prepare pager");
 }
 
 /* Run instructions sent from the server like unlink and set redirect path
@@ -514,7 +513,7 @@ 
 {
 	debugmsg("execute original hg");
 	if (execvp(gethgcmd(), (char **)argv) < 0)
-		abortmsg("failed to exec original hg (errno = %d)", errno);
+		abortmsgerrno("failed to exec original hg");
 }
 
 int main(int argc, const char *argv[], const char *envp[])
diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -141,7 +141,7 @@ 
 	while (p < endp) {
 		ssize_t r = send(sockfd, p, endp - p, 0);
 		if (r < 0)
-			abortmsg("cannot communicate (errno = %d)", errno);
+			abortmsgerrno("cannot communicate");
 		p += r;
 	}
 }
@@ -374,7 +374,7 @@ 
 	msgh.msg_controllen = cmsg->cmsg_len;
 	ssize_t r = sendmsg(hgc->sockfd, &msgh, 0);
 	if (r < 0)
-		abortmsg("sendmsg failed (errno = %d)", errno);
+		abortmsgerrno("sendmsg failed");
 
 	handleresponse(hgc);
 	int32_t n;
@@ -389,7 +389,7 @@ 
 static void chdirtocwd(hgclient_t *hgc)
 {
 	if (!getcwd(hgc->ctx.data, hgc->ctx.maxdatasize))
-		abortmsg("failed to getcwd (errno = %d)", errno);
+		abortmsgerrno("failed to getcwd");
 	hgc->ctx.datasize = strlen(hgc->ctx.data);
 	writeblockrequest(hgc, "chdir");
 }
@@ -414,15 +414,15 @@ 
 {
 	int fd = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (fd < 0)
-		abortmsg("cannot create socket (errno = %d)", errno);
+		abortmsgerrno("cannot create socket");
 
 	/* don't keep fd on fork(), so that it can be closed when the parent
 	 * process get terminated. */
 	int flags = fcntl(fd, F_GETFD);
 	if (flags < 0)
-		abortmsg("cannot get flags of socket (errno = %d)", errno);
+		abortmsgerrno("cannot get flags of socket");
 	if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
-		abortmsg("cannot set flags of socket (errno = %d)", errno);
+		abortmsgerrno("cannot set flags of socket");
 
 	struct sockaddr_un addr;
 	addr.sun_family = AF_UNIX;
@@ -434,8 +434,7 @@ 
 		close(fd);
 		if (errno == ENOENT || errno == ECONNREFUSED)
 			return NULL;
-		abortmsg("cannot connect to %s (errno = %d)",
-			 addr.sun_path, errno);
+		abortmsgerrno("cannot connect to %s", addr.sun_path);
 	}
 	debugmsg("connected to %s", addr.sun_path);