From 419a4235208ba879e00b9a7c6065485e8e990814 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Wed, 28 Apr 2021 12:42:36 +0000 Subject: [PATCH] keep verbosity level after config reload --- gmid.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gmid.c b/gmid.c index fc155df..ec22fe4 100644 --- a/gmid.c +++ b/gmid.c @@ -244,11 +244,16 @@ free_config(void) { struct vhost *h, *th; struct location *l, *tl; + int v; + + v = conf.verbose; free(conf.chroot); free(conf.user); memset(&conf, 0, sizeof(conf)); + conf.verbose = v; + TAILQ_FOREACH_SAFE(h, &hosts, vhosts, th) { TAILQ_FOREACH_SAFE(l, &h->locations, locations, tl) { TAILQ_REMOVE(&h->locations, l, locations); @@ -411,6 +416,34 @@ serve(int argc, char **argv, struct imsgbuf *ibuf) _exit(executor_main(ibuf)); } +static int +write_pidfile(const char *pidfile) +{ + struct flock lock; + int fd; + + if (pidfile == NULL) + return -1; + + if ((fd = open(pidfile, O_WRONLY|O_CREAT|O_CLOEXEC, 0600)) == -1) + fatal("can't open pidfile %s: %s", pidfile, strerror(errno)); + + lock.l_start = 0; + lock.l_len = 0; + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + + if (fcntl(fd, F_SETLK, &lock) == -1) + fatal("can't lock %s, gmid is already running?", pidfile); + + if (ftruncate(fd, 0) == -1) + fatal("ftruncate: %s: %s", pidfile, strerror(errno)); + + dprintf(fd, "%d\n", getpid()); + + return fd; +} + static void setup_configless(int argc, char **argv, const char *cgi) {