about summary refs log tree commit diff
path: root/src/nix-daemon/nix-daemon.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-daemon/nix-daemon.cc')
-rw-r--r--src/nix-daemon/nix-daemon.cc33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc
index 69d5fd84e000..3e6d6b2b1170 100644
--- a/src/nix-daemon/nix-daemon.cc
+++ b/src/nix-daemon/nix-daemon.cc
@@ -645,8 +645,10 @@ bool matchUser(const string & user, const string & group, const Strings & users)
 #define SD_LISTEN_FDS_START 3
 
 
-static void daemonLoop()
+static void daemonLoop(char * * argv)
 {
+    chdir("/");
+
     /* Get rid of children automatically; don't let them become
        zombies. */
     setSigChldAction(true);
@@ -766,9 +768,9 @@ static void daemonLoop()
                 setSigChldAction(false);
 
                 /* For debugging, stuff the pid into argv[1]. */
-                if (clientPid != -1 && argvSaved[1]) {
+                if (clientPid != -1 && argv[1]) {
                     string processName = int2String(clientPid);
-                    strncpy(argvSaved[1], processName.c_str(), strlen(argvSaved[1]));
+                    strncpy(argv[1], processName.c_str(), strlen(argv[1]));
                 }
 
                 /* Handle the connection. */
@@ -792,18 +794,27 @@ void run(Strings args)
 {
     for (Strings::iterator i = args.begin(); i != args.end(); ) {
         string arg = *i++;
-        if (arg == "--daemon") /* ignored for backwards compatibility */;
     }
 
-    chdir("/");
-    daemonLoop();
 }
 
 
-void printHelp()
+int main(int argc, char * * argv)
 {
-    showManPage("nix-daemon");
+    return handleExceptions(argv[0], [&]() {
+        initNix();
+
+        parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
+            if (*arg == "--daemon")
+                ; /* ignored for backwards compatibility */
+            else if (*arg == "--help")
+                showManPage("nix-daemon");
+            else if (*arg == "--version")
+                printVersion("nix-daemon");
+            else return false;
+            return true;
+        });
+
+        daemonLoop(argv);
+    });
 }
-
-
-string programId = "nix-daemon";