commit 8e8b2e252c37a1e633c33ac923ab78c3f1e8ab31 from: Omar Polo date: Wed Apr 28 12:45:22 2021 UTC pidfile support with `-P pidfile' commit - 2ef7f631db592b0baf910eb2d05d9fa45f85c671 commit + 8e8b2e252c37a1e633c33ac923ab78c3f1e8ab31 blob - 5437a4c31bec0bfab50d8551aff8644174e17442 blob + 3200dc0bf628e78f072234290d017e22ef799655 --- ChangeLog +++ ChangeLog @@ -1,3 +1,7 @@ +2021-04-28 Omar Polo + + * gmid.c (main): pidfile support with `-P pidfile' + 2021-04-27 Omar Polo * parse.y (servopt): added ``env'' option to define environment vars for CGI scripts blob - cc42423baf6353a590b8bec86194c47f16650208 blob + 0e08e2ff01dc1070bc6f1db9d6a186fef39ebd2b --- gmid.1 +++ gmid.1 @@ -22,6 +22,7 @@ .Bk -words .Op Fl fnv .Op Fl c Ar config +.Op Fl P Ar pidfile .Ek .Nm .Bk -words @@ -51,6 +52,10 @@ Specify the configuration file. Stays and logs on the foreground. .It Fl n Check that the configuration is valid, but don't start the server. +.It Fl P Pa pidfile +Write +.Nm +pid to the given path. .El .Pp If no configuration file is given, blob - 7e221f5fa728a7c2cd11fc7a07ca7bc8d6903b11 blob + 30ffaa12cc982ecf17be00e213fce5d1324eb90b --- gmid.c +++ gmid.c @@ -328,7 +328,7 @@ static void usage(const char *me) { fprintf(stderr, - "USAGE: %s [-fn] [-c config] | [-6h] [-d certs-dir] [-H host]\n" + "USAGE: %s [-fn] [-c config] [-P pidfile] | [-6h] [-d certs-dir] [-H host]\n" " [-p port] [-x cgi] [dir]\n", me); } @@ -474,12 +474,12 @@ main(int argc, char **argv) { struct imsgbuf exibuf; int ch, conftest = 0, configless = 0; - int old_ipv6, old_port; - const char *cgi = NULL; + int pidfd, old_ipv6, old_port; + const char *pidfile = NULL, *cgi = NULL; init_config(); - while ((ch = getopt(argc, argv, "6c:d:fH:hnp:vx:")) != -1) { + while ((ch = getopt(argc, argv, "6c:d:fH:hnP:p:vx:")) != -1) { switch (ch) { case '6': conf.ipv6 = 1; @@ -512,6 +512,10 @@ main(int argc, char **argv) conftest = 1; break; + case 'P': + pidfile = optarg; + break; + case 'p': conf.port = parse_portno(optarg); configless = 1; @@ -576,6 +580,8 @@ main(int argc, char **argv) return 0; } + pidfd = write_pidfile(pidfile); + /* Linux seems to call the event handlers even when we're * doing a sigwait. These dummy handlers are here to avoid * being terminated on SIGHUP, SIGINT or SIGTERM. */ @@ -644,5 +650,8 @@ main(int argc, char **argv) imsg_compose(&logibuf, IMSG_QUIT, 0, 0, -1, NULL, 0); imsg_flush(&logibuf); + if (pidfd != -1) + close(pidfd); + return 0; }