about summary refs log tree commit homepage
path: root/svc.c
diff options
context:
space:
mode:
Diffstat (limited to 'svc.c')
-rw-r--r--svc.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/svc.c b/svc.c
index 4a44493..86f69db 100644
--- a/svc.c
+++ b/svc.c
@@ -69,6 +69,35 @@ static void svc_once(void)
         atexit(svc_atexit);
 }
 
+bool mog_svc_atfork_child(void *svc_ptr, void *parent)
+{
+        struct mog_svc *svc = svc_ptr;
+        pid_t ppid = *((pid_t *)parent);
+        const char *failfn;
+
+        if (closedir(svc->dir) < 0) {
+                failfn = "closedir";
+                goto err;
+        }
+
+        svc->dir = opendir(svc->docroot);
+        if (svc->dir == NULL) {
+                failfn = "opendir";
+                goto err;
+        }
+
+        svc->docroot_fd = dirfd(svc->dir);
+        if (svc->docroot_fd < 0) {
+                failfn = "dirfd";
+                goto err;
+        }
+        return true;
+err:
+        syslog(LOG_ERR, "%s(%s) failed with: %m", failfn, svc->docroot);
+        kill(ppid, SIGTERM);
+        return false;
+}
+
 struct mog_svc * mog_svc_new(const char *docroot)
 {
         struct mog_svc *svc;