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

login
register
mail settings
Submitter Jun Wu
Date April 5, 2016, 2:21 p.m.
Message ID <a7d5ebda19b46b5ce15d.1459866078@x1c>
Download mbox | patch
Permalink /patch/14371/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

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

Since we have abortmsge now, use it to show human friendly error messages
across platforms.

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);
+		abortmsge("cannot create sockdir %s", sockdir);
 
 	struct stat st;
 	r = lstat(sockdir, &st);
 	if (r < 0)
-		abortmsg("cannot stat %s (errno = %d)", sockdir, errno);
+		abortmsge("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,11 @@ 
 	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);
+			abortmsge("cannot create lock file %s", opts->lockfile);
 	}
 	int r = flock(opts->lockfd, LOCK_EX);
 	if (r == -1)
-		abortmsg("cannot acquire lock");
+		abortmsge("cannot acquire lock");
 }
 
 /*
@@ -224,9 +223,9 @@ 
 	argv[argsize - 1] = NULL;
 
 	if (putenv("CHGINTERNALMARK=") != 0)
-		abortmsg("failed to putenv (errno = %d)", errno);
+		abortmsge("failed to putenv");
 	if (execvp(hgcmd, (char **)argv) < 0)
-		abortmsg("failed to exec cmdserver (errno = %d)", errno);
+		abortmsge("failed to exec cmdserver");
 	free(argv);
 }
 
@@ -325,7 +324,7 @@ 
 {
 	assert(peerpid > 0);
 	if (kill(peerpid, sig) < 0)
-		abortmsg("cannot kill %d (errno = %d)", peerpid, errno);
+		abortmsge("cannot kill %d", peerpid);
 	debugmsg("forward signal %d", sig);
 }
 
@@ -358,7 +357,7 @@ 
 	return;
 
 error:
-	abortmsg("failed to handle stop signal (errno = %d)", errno);
+	abortmsge("failed to handle stop signal");
 }
 
 static void setupsignalhandler(pid_t pid)
@@ -397,7 +396,7 @@ 
 	return;
 
 error:
-	abortmsg("failed to set up signal handlers (errno = %d)", errno);
+	abortmsge("failed to set up signal handlers");
 }
 
 /* This implementation is based on hgext/pager.py (pre 369741ef7253) */
@@ -432,8 +431,7 @@ 
 
 		int r = execlp("/bin/sh", "/bin/sh", "-c", pagercmd, NULL);
 		if (r < 0) {
-			abortmsg("cannot start pager '%s' (errno = %d)",
-				 pagercmd, errno);
+			abortmsge("cannot start pager '%s'", pagercmd);
 		}
 		return;
 	}
@@ -441,7 +439,7 @@ 
 error:
 	close(pipefds[0]);
 	close(pipefds[1]);
-	abortmsg("failed to prepare pager (errno = %d)", errno);
+	abortmsge("failed to prepare pager");
 }
 
 /* Run instructions sent from the server like unlink and set redirect path
@@ -514,7 +512,7 @@ 
 {
 	debugmsg("execute original hg");
 	if (execvp(gethgcmd(), (char **)argv) < 0)
-		abortmsg("failed to exec original hg (errno = %d)", errno);
+		abortmsge("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);
+			abortmsge("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);
+		abortmsge("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);
+		abortmsge("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);
+		abortmsge("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);
+		abortmsge("cannot get flags of socket");
 	if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
-		abortmsg("cannot set flags of socket (errno = %d)", errno);
+		abortmsge("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);
+		abortmsge("cannot connect to %s", addr.sun_path);
 	}
 	debugmsg("connected to %s", addr.sun_path);