]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
daemon: Fix log reload for relative paths.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 31 Dec 2017 20:56:35 +0000 (21:56 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 11 Feb 2018 10:28:17 +0000 (11:28 +0100)
If the argument to --logfile is a relative path, it is interpreted
as relative to the current working directory. In daemon mode, the
current working directory is changed to / during startup. Hence,
when para_server re-opens the log file after it received SIGHUP, the
logfile path will now be interpreted as relative to the the root of
the file system.

Fix this by remembering the original current working directory.
Opening "." as recommended in getcwd(3) is not an option here since the
whole point of changing the cwd to / is to prevent the daemon from
keeping the cwd busy.

daemon.c

index 49d2e1007fcf92c99c511fbcadbe0f461a05638d..ddfe680cebc63dc1c7af89fde333c665873765eb 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -30,6 +30,7 @@ struct daemon {
        char *hostname;
        /** Used for colored log messages. */
        char log_colors[NUM_LOGLEVELS][COLOR_MAXLEN];
        char *hostname;
        /** Used for colored log messages. */
        char log_colors[NUM_LOGLEVELS][COLOR_MAXLEN];
+       char *old_cwd;
 };
 
 static struct daemon the_daemon, *me = &the_daemon;
 };
 
 static struct daemon the_daemon, *me = &the_daemon;
@@ -117,7 +118,12 @@ void daemon_set_logfile(const char *logfile_name)
 {
        free(me->logfile_name);
        me->logfile_name = NULL;
 {
        free(me->logfile_name);
        me->logfile_name = NULL;
-       if (logfile_name)
+       if (!logfile_name)
+               return;
+       if (me->old_cwd && logfile_name[0] != '/')
+               me->logfile_name = make_message("%s/%s", me->old_cwd,
+                       logfile_name);
+       else
                me->logfile_name = para_strdup(logfile_name);
 }
 
                me->logfile_name = para_strdup(logfile_name);
 }
 
@@ -197,6 +203,7 @@ int daemonize(bool parent_waits)
        /* become session leader */
        if (setsid() < 0)
                goto err;
        /* become session leader */
        if (setsid() < 0)
                goto err;
+       me->old_cwd = getcwd(NULL, 0);
        if (chdir("/") < 0)
                goto err;
        null = open("/dev/null", O_RDWR);
        if (chdir("/") < 0)
                goto err;
        null = open("/dev/null", O_RDWR);