# HG changeset patch # User Jun Wu <qu...@fb.com> # Date 1482185389 0 # Mon Dec 19 22:09:49 2016 +0000 # Node ID 24534dee38fe515f2c406e18153f623a074148b3 # Parent c543f9fd1a5b7657d4114e61e87a8d9bc32f7617 # Available At https://bitbucket.org/quark-zju/hg-draft # hg pull https://bitbucket.org/quark-zju/hg-draft -r 24534dee38fe chg: start server at a unique address
See the previous patch for motivation. Previously, the server is started at a globally shared address. This patch appends pid to the address so it becomes unique. Note: with Linux pid namespace, the address may be non-unique, but it does not affect correctness of chg - chg client will receive an redirection and that's it. diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c --- a/contrib/chg/chg.c +++ b/contrib/chg/chg.c @@ -32,4 +32,5 @@ struct cmdserveropts { char sockname[UNIX_PATH_MAX]; + char initsockname[UNIX_PATH_MAX]; char redirectsockname[UNIX_PATH_MAX]; char lockfile[UNIX_PATH_MAX]; @@ -164,4 +165,8 @@ static void setcmdserveropts(struct cmds if (r < 0 || (size_t)r >= sizeof(opts->lockfile)) abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r); + r = snprintf(opts->initsockname, sizeof(opts->initsockname), + "%s.%u", opts->sockname, (unsigned)getpid()); + if (r < 0 || (size_t)r >= sizeof(opts->initsockname)) + abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r); } @@ -224,5 +229,5 @@ static void execcmdserver(const struct c "serve", "--cmdserver", "chgunix", - "--address", opts->sockname, + "--address", opts->initsockname, "--daemon-postexec", "chdir:/", }; @@ -248,5 +253,5 @@ static hgclient_t *retryconnectcmdserver int pst = 0; - debugmsg("try connect to %s repeatedly", opts->sockname); + debugmsg("try connect to %s repeatedly", opts->initsockname); unsigned int timeoutsec = 60; /* default: 60 seconds */ @@ -256,7 +261,13 @@ static hgclient_t *retryconnectcmdserver for (unsigned int i = 0; !timeoutsec || i < timeoutsec * 100; i++) { - hgclient_t *hgc = hgc_open(opts->sockname); - if (hgc) + hgclient_t *hgc = hgc_open(opts->initsockname); + if (hgc) { + debugmsg("rename %s to %s", opts->initsockname, + opts->sockname); + int r = rename(opts->initsockname, opts->sockname); + if (r != 0) + abortmsgerrno("cannot rename"); return hgc; + } if (pid > 0) { @@ -270,5 +281,5 @@ static hgclient_t *retryconnectcmdserver } - abortmsg("timed out waiting for cmdserver %s", opts->sockname); + abortmsg("timed out waiting for cmdserver %s", opts->initsockname); return NULL; @@ -313,5 +324,5 @@ static hgclient_t *connectcmdserver(stru unlink(opts->sockname); - debugmsg("start cmdserver at %s", opts->sockname); + debugmsg("start cmdserver at %s", opts->initsockname); pid_t pid = fork(); _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel