]> granicus.if.org Git - pdns/commitdiff
dnsdist: Remove the --daemon option
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 26 Mar 2018 15:19:46 +0000 (17:19 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 26 Mar 2018 15:19:46 +0000 (17:19 +0200)
We keep finding bugs with this option because we don't use it on a
regular basis and most users run dnsdist under some kind of
supervision anyway.

pdns/dnsdist.cc
pdns/dnsdistdist/docs/manpages/dnsdist.1.rst

index fe665e5134ae2b69751b863d30835ae9bc5bd76f..fbde95d874e7d4614887452b706379b82d5de808 100644 (file)
@@ -723,41 +723,6 @@ shared_ptr<DownstreamState> roundrobin(const NumberedServerVector& servers, cons
   return (*res)[(counter++) % res->size()].second;
 }
 
-static void writepid(string pidfile) {
-  if (!pidfile.empty()) {
-    // Clean up possible stale file
-    unlink(pidfile.c_str());
-
-    // Write the pidfile
-    ofstream of(pidfile.c_str());
-    if (of) {
-      of << getpid();
-    } else {
-      errlog("Unable to write PID-file to '%s'.", pidfile);
-    }
-    of.close();
-  }
-}
-
-static void daemonize(void)
-{
-  if(fork())
-    _exit(0); // bye bye
-  /* We are child */
-
-  setsid(); 
-
-  int i=open("/dev/null",O_RDWR); /* open stdin */
-  if(i < 0) 
-    ; // L<<Logger::Critical<<"Unable to open /dev/null: "<<stringerror()<<endl;
-  else {
-    dup2(i,0); /* stdin */
-    dup2(i,1); /* stderr */
-    dup2(i,2); /* stderr */
-    close(i);
-  }
-}
-
 ComboAddress g_serverControl{"127.0.0.1:5199"};
 
 std::shared_ptr<ServerPool> createPoolIfNotExists(pools_t& pools, const string& poolName)
@@ -2019,10 +1984,8 @@ struct
   vector<string> locals;
   vector<string> remotes;
   bool checkConfig{false};
-  bool beDaemon{false};
   bool beClient{false};
   bool beSupervised{false};
-  string pidfile;
   string command;
   string config;
   string uid;
@@ -2034,8 +1997,8 @@ std::atomic<bool> g_configurationDone{false};
 static void usage()
 {
   cout<<endl;
-  cout<<"Syntax: dnsdist [-C,--config file] [-c,--client [IP[:PORT]]] [-d,--daemon]\n";
-  cout<<"[-p,--pidfile file] [-e,--execute cmd] [-h,--help] [-l,--local addr]\n";
+  cout<<"Syntax: dnsdist [-C,--config file] [-c,--client [IP[:PORT]]]\n";
+  cout<<"[-e,--execute cmd] [-h,--help] [-l,--local addr]\n";
   cout<<"[-v,--verbose] [--check-config]\n";
   cout<<"\n";
   cout<<"-a,--acl netmask      Add this netmask to the ACL\n";
@@ -2051,7 +2014,6 @@ static void usage()
   cout<<"--check-config        Validate the configuration file and exit. The exit-code\n";
   cout<<"                      reflects the validation, 0 is OK, 1 means an error.\n";
   cout<<"                      Any errors are printed as well.\n";
-  cout<<"-d,--daemon           Operate as a daemon\n";
   cout<<"-e,--execute cmd      Connect to dnsdist and execute 'cmd'\n";
   cout<<"-g,--gid gid          Change the process group ID after binding sockets\n";
   cout<<"-h,--help             Display this helpful message\n";
@@ -2060,7 +2022,6 @@ static void usage()
   cout<<"                        (use with e.g. systemd and daemontools)\n";
   cout<<"--disable-syslog      Don't log to syslog, only to stdout\n";
   cout<<"                        (use with e.g. systemd)\n";
-  cout<<"-p,--pidfile file     Write a pidfile, works only with --daemon\n";
   cout<<"-u,--uid uid          Change the process user ID after binding sockets\n";
   cout<<"-v,--verbose          Enable verbose mode\n";
 }
@@ -2107,8 +2068,6 @@ try
     {"setkey",  required_argument, 0, 'k'},
 #endif
     {"local",  required_argument, 0, 'l'},
-    {"daemon", 0, 0, 'd'},
-    {"pidfile",  required_argument, 0, 'p'},
     {"supervised", 0, 0, 's'},
     {"disable-syslog", 0, 0, 2},
     {"uid",  required_argument, 0, 'u'},
@@ -2140,9 +2099,6 @@ try
     case 'c':
       g_cmdLine.beClient=true;
       break;
-    case 'd':
-      g_cmdLine.beDaemon=true;
-      break;
     case 'e':
       g_cmdLine.command=optarg;
       break;
@@ -2170,9 +2126,6 @@ try
     case 'l':
       g_cmdLine.locals.push_back(trim_copy(string(optarg)));
       break;
-    case 'p':
-      g_cmdLine.pidfile=optarg;
-      break;
     case 's':
       g_cmdLine.beSupervised=true;
       break;
@@ -2564,24 +2517,17 @@ try
     }
   }
 
-  if(g_cmdLine.beDaemon) {
-    g_console=false;
-    daemonize();
-    writepid(g_cmdLine.pidfile);
-  }
-  else {
-    vinfolog("Running in the foreground");
-    warnlog("dnsdist %s comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it according to the terms of the GPL version 2", VERSION);
-    vector<string> vec;
-    std::string acls;
-    g_ACL.getLocal()->toStringVector(&vec);
-    for(const auto& s : vec) {
-      if (!acls.empty())
-        acls += ", ";
-      acls += s;
-    }
-    infolog("ACL allowing queries from: %s", acls.c_str());
+  vinfolog("Running in the foreground");
+  warnlog("dnsdist %s comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it according to the terms of the GPL version 2", VERSION);
+  vector<string> vec;
+  std::string acls;
+  g_ACL.getLocal()->toStringVector(&vec);
+  for(const auto& s : vec) {
+    if (!acls.empty())
+      acls += ", ";
+    acls += s;
   }
+  infolog("ACL allowing queries from: %s", acls.c_str());
 
   uid_t newgid=0;
   gid_t newuid=0;
@@ -2662,7 +2608,7 @@ try
   
   thread healththread(healthChecksThread);
 
-  if(g_cmdLine.beDaemon || g_cmdLine.beSupervised) {
+  if(g_cmdLine.beSupervised) {
 #ifdef HAVE_SYSTEMD
     sd_notify(0, "READY=1");
 #endif
index 52c9fa1c7512fcce1c68dd6bd144814ea59b3869..fab321ff7edec6e9ac7d4012ff53c9eed1662f14 100644 (file)
@@ -58,7 +58,6 @@ Options
                                        that is used on the server (set with **setKey()**). Note that this
                                        will leak the key into your shell's history. Only available when
                                        dnsdist is compiled with libsodium support.
--d, --daemon                           Operate as a daemon.
 -e, --execute <command>                Connect to dnsdist and execute *command*.
 -h, --help                             Display a helpful message and exit.
 -l, --local <address>                  Bind to *address*, Supply as many addresses (using multiple
@@ -68,9 +67,7 @@ Options
                                        run dnsdist inside a supervisor (use with e.g. systemd and
                                        daemontools).
 --disable-syslog                       Disable logging to syslog. Use this when running inside a supervisor
-                                       that handles logging (like systemd). Do not use in combination with
-                                       **--daemon**.
--p, --pidfile <file>                   Write a pidfile to *file*, works only with **--daemon**.
+                                       that handles logging (like systemd).
 -u, --uid <uid>                        Change the process user to *uid* after binding sockets. *uid* can be
                                        a name or number.
 -g, --gid <gid>                        Change the process group to *gid* after binding sockets. *gid* Can