aboutsummaryrefslogtreecommitdiff
path: root/gmid.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-04-28 12:42:36 +0000
committerOmar Polo <op@omarpolo.com>2021-04-28 12:42:36 +0000
commit419a4235208ba879e00b9a7c6065485e8e990814 (patch)
tree1925390557bc65e37042f4a14abf3fe27b5873a5 /gmid.c
parentc79b63f580e11d81ab3043fbf6a7339c5029080f (diff)
keep verbosity level after config reload
Diffstat (limited to 'gmid.c')
-rw-r--r--gmid.c33
1 files changed, 33 insertions, 0 deletions
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)
{