chg: do not write pidfile
Current pidfile logic will only keep the pid of the newest server, which is
not very useful if we want to kill all servers, and will become outdated if
the server auto exits after being idle for too long.
Besides, the server-side pidfile writing logic runs before chgserver gets
confighash so it's not trivial to append confighash to pidfile basename like
we did for socket file.
This patch removes --pidfile from the command starting chgserver and switches
to an alternative way (unlink socket file) to stop the server.
--- a/contrib/chg/chg.c Thu Mar 10 00:12:33 2016 +0000
+++ b/contrib/chg/chg.c Thu Mar 10 00:19:55 2016 +0000
@@ -33,7 +33,6 @@
char sockname[UNIX_PATH_MAX];
char redirectsockname[UNIX_PATH_MAX];
char lockfile[UNIX_PATH_MAX];
- char pidfile[UNIX_PATH_MAX];
size_t argsize;
const char **args;
int lockfd;
@@ -149,16 +148,12 @@
const char *basename = (envsockname) ? envsockname : sockdir;
const char *sockfmt = (envsockname) ? "%s" : "%s/server";
const char *lockfmt = (envsockname) ? "%s.lock" : "%s/lock";
- const char *pidfmt = (envsockname) ? "%s.pid" : "%s/pid";
r = snprintf(opts->sockname, sizeof(opts->sockname), sockfmt, basename);
if (r < 0 || (size_t)r >= sizeof(opts->sockname))
abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
r = snprintf(opts->lockfile, sizeof(opts->lockfile), lockfmt, basename);
if (r < 0 || (size_t)r >= sizeof(opts->lockfile))
abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
- r = snprintf(opts->pidfile, sizeof(opts->pidfile), pidfmt, basename);
- if (r < 0 || (size_t)r >= sizeof(opts->pidfile))
- abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
}
/*
@@ -214,7 +209,6 @@
"--cmdserver", "chgunix",
"--address", opts->sockname,
"--daemon-postexec", "chdir:/",
- "--pid-file", opts->pidfile,
"--config", "extensions.chgserver=",
};
size_t baseargvsize = sizeof(baseargv) / sizeof(baseargv[0]);
@@ -314,21 +308,13 @@
return hgc;
}
-static void killcmdserver(const struct cmdserveropts *opts, int sig)
+static void killcmdserver(const struct cmdserveropts *opts)
{
- FILE *fp = fopen(opts->pidfile, "r");
- if (!fp)
- abortmsg("cannot open %s (errno = %d)", opts->pidfile, errno);
- int pid = 0;
- int n = fscanf(fp, "%d", &pid);
- fclose(fp);
- if (n != 1 || pid <= 0)
- abortmsg("cannot read pid from %s", opts->pidfile);
-
- if (kill((pid_t)pid, sig) < 0) {
- if (errno == ESRCH)
- return;
- abortmsg("cannot kill %d (errno = %d)", pid, errno);
+ /* resolve config hash */
+ char *resolvedpath = realpath(opts->sockname, NULL);
+ if (resolvedpath) {
+ unlink(resolvedpath);
+ free(resolvedpath);
}
}
@@ -536,11 +522,8 @@
setcmdserverargs(&opts, argc, argv);
if (argc == 2) {
- int sig = 0;
- if (strcmp(argv[1], "--kill-chg-daemon") == 0)
- sig = SIGTERM;
- if (sig > 0) {
- killcmdserver(&opts, sig);
+ if (strcmp(argv[1], "--kill-chg-daemon") == 0) {
+ killcmdserver(&opts);
return 0;
}
}
--- a/tests/run-tests.py Thu Mar 10 00:12:33 2016 +0000
+++ b/tests/run-tests.py Thu Mar 10 00:19:55 2016 +0000
@@ -2384,9 +2384,9 @@
def _killchgdaemons(self):
"""Kill all background chg command servers spawned by tests"""
for f in os.listdir(self._chgsockdir):
- if not f.endswith(b'.pid'):
+ if '.' in f:
continue
- killdaemons(os.path.join(self._chgsockdir, f))
+ os.unlink(os.path.join(self._chgsockdir, f))
def _outputcoverage(self):
"""Produce code coverage output."""