Fix snapshot removal reason.
[dss.git] / daemon.c
index ba890fb..86e8906 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2010 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 #include <stdio.h>
 
 #include "gcc-compat.h"
-#include "error.h"
+#include "err.h"
 #include "log.h"
-#include "string.h"
+#include "str.h"
+#include "daemon.h"
 
 /**
  * Do the usual stuff to become a daemon.
@@ -35,7 +36,7 @@ void daemon_init(void)
        pid_t pid;
        int null;
 
-       DSS_INFO_LOG("daemonizing\n");
+       DSS_INFO_LOG(("daemonizing\n"));
        pid = fork();
        if (pid < 0)
                goto err;
@@ -44,10 +45,8 @@ void daemon_init(void)
        /* become session leader */
        if (setsid() < 0)
                goto err;
-       if (chdir("/") < 0)
-               goto err;
        umask(0);
-       null = open("/dev/null", O_RDONLY);
+       null = open("/dev/null", O_RDWR);
        if (null < 0)
                goto err;
        if (dup2(null, STDIN_FILENO) < 0)
@@ -59,7 +58,7 @@ void daemon_init(void)
        close(null);
        return;
 err:
-       DSS_EMERG_LOG("fatal: %s\n", strerror(errno));
+       DSS_EMERG_LOG(("fatal: %s\n", strerror(errno)));
        exit(EXIT_FAILURE);
 }
 
@@ -77,8 +76,8 @@ FILE *open_log(const char *logfile_name)
        assert(logfile_name);
        logfile = fopen(logfile_name, "a");
        if (!logfile) {
-               DSS_EMERG_LOG("can not open %s: %s\n", logfile_name,
-                       strerror(errno));
+               DSS_EMERG_LOG(("can not open %s: %s\n", logfile_name,
+                       strerror(errno)));
                exit(EXIT_FAILURE);
        }
        setlinebuf(logfile);
@@ -96,7 +95,7 @@ void close_log(FILE* logfile)
 {
        if (!logfile)
                return;
-       DSS_INFO_LOG("closing logfile\n");
+       DSS_INFO_LOG(("closing logfile\n"));
        fclose(logfile);
 }
 
@@ -105,11 +104,6 @@ void close_log(FILE* logfile)
  */
 void log_welcome(int loglevel)
 {
-       DSS_INFO_LOG("***** welcome to dss ******\n");
-       DSS_DEBUG_LOG("using loglevel %d\n", loglevel);
-}
-
-int com_daemon(int argc, char * const * argv)
-{
-       return 1;
+       DSS_INFO_LOG(("***** welcome to dss ******\n"));
+       DSS_DEBUG_LOG(("using loglevel %d\n", loglevel));
 }