From de58eff7c1523e99be6aa419f56846446d0faa29 Mon Sep 17 00:00:00 2001 From: Christian Kruse Date: Wed, 22 Jan 2014 14:30:38 +0100 Subject: [PATCH] added a chdir() for proper daemonizing --- repmgrd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/repmgrd.c b/repmgrd.c index df25de6b..3bf715b9 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -1322,7 +1322,9 @@ update_registration(void) static void do_daemonize() { + char *ptr, path[MAXLEN]; pid_t pid = fork(); + switch (pid) { case -1: @@ -1355,6 +1357,23 @@ do_daemonize() /* a child just flows along */ + memset(path, 0, MAXLEN); + + for (ptr = config_file + strlen(config_file); ptr > config_file; --ptr) + { + if (*ptr == '/') + { + strncpy(path, config_file, ptr - config_file); + } + } + + if (*path == '\0') + { + *path = '/'; + } + + chdir(path); + break; default: /* parent process */