added a chdir() for proper daemonizing

This commit is contained in:
Christian Kruse
2014-01-22 14:30:38 +01:00
parent f2a0b31a20
commit de58eff7c1

View File

@@ -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 */