chg: replace abortmsg showing errno with abortmsgerrno

Since we have abortmsgerrno now, use it to show human friendly error messages
across platforms.
This commit is contained in:
Jun Wu 2016-04-05 15:16:01 +01:00
parent 0a8e7312da
commit 7aec0cb63d
2 changed files with 20 additions and 22 deletions

View File

@ -114,13 +114,12 @@ static void preparesockdir(const char *sockdir)
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 @@ static void lockcmdserver(struct cmdserveropts *opts)
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 @@ static void execcmdserver(const struct cmdserveropts *opts)
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 @@ static void forwardsignal(int sig)
{
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 @@ static void handlestopsignal(int sig)
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 @@ static void setupsignalhandler(pid_t pid)
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 @@ static void setuppager(hgclient_t *hgc, const char *const args[],
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 @@ static void setuppager(hgclient_t *hgc, const char *const args[],
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 @@ static void execoriginalhg(const char *argv[])
{
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[])

View File

@ -141,7 +141,7 @@ static void sendall(int sockfd, const void *data, size_t datasize)
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 @@ static void attachio(hgclient_t *hgc)
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 attachio(hgclient_t *hgc)
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 @@ hgclient_t *hgc_open(const char *sockname)
{
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 @@ hgclient_t *hgc_open(const char *sockname)
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);