diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-08-13 03:50:44 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-08-13 03:50:44 +0200 |
commit | 47e185847e729d49e6aa376e8299fd66ef834a0a (patch) | |
tree | 6abfc9e9d5744e78b123c73182c30253c9a39681 /src/nix-daemon | |
parent | 5bed74d1b0acd8d8083fb82a31d907ad2348a91b (diff) |
Refactor option handling
Diffstat (limited to 'src/nix-daemon')
-rw-r--r-- | src/nix-daemon/nix-daemon.cc | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc index 69d5fd84e..3e6d6b2b1 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"; |