changeset 28789:7f6e0a15189b

chg: replace abortmsg showing errno with abortmsgerrno Since we have abortmsgerrno now, use it to show human friendly error messages across platforms.
author Jun Wu <quark@fb.com>
date Tue, 05 Apr 2016 15:16:01 +0100
parents 57a78a64de44
children b0cc9652e8dc
files contrib/chg/chg.c contrib/chg/hgclient.c
diffstat 2 files changed, 20 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/chg.c	Tue Apr 05 17:25:39 2016 +0100
+++ b/contrib/chg/chg.c	Tue Apr 05 15:16:01 2016 +0100
@@ -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[])
--- a/contrib/chg/hgclient.c	Tue Apr 05 17:25:39 2016 +0100
+++ b/contrib/chg/hgclient.c	Tue Apr 05 15:16:01 2016 +0100
@@ -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);