lib/netdev-dpdk: increase ring name length for dpdkr ports
[cascardo/ovs.git] / lib / daemon-windows.c
index 0893755..ac71aa1 100644 (file)
 
 #include <config.h>
 #include "daemon.h"
+#include "daemon-private.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include "dirs.h"
+#include "ovs-thread.h"
 #include "poll-loop.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 
-VLOG_DEFINE_THIS_MODULE(daemon);
+VLOG_DEFINE_THIS_MODULE(daemon_windows);
 
 static bool service_create;          /* Was --service specified? */
 static bool service_started;         /* Have we dispatched service to start? */
@@ -30,12 +33,12 @@ static bool service_started;         /* Have we dispatched service to start? */
  * unexpectedly? */
 static bool monitor;
 
-static bool detach; /* Was --detach specified? */
-static bool detached; /* Running as the child process. */
-static HANDLE write_handle; /* End of pipe to write to parent. */
+bool detach;                 /* Was --detach specified? */
+static bool detached;        /* Running as the child process. */
+static HANDLE write_handle;  /* End of pipe to write to parent. */
 
-static char *pidfile;         /* --pidfile: Name of pidfile (null if none). */
-static FILE *filep_pidfile;   /* File pointer to access the pidfile. */
+char *pidfile;                 /* --pidfile: Name of pidfile (null if none). */
+static FILE *filep_pidfile;    /* File pointer to access the pidfile. */
 
 /* Handle to the Services Manager and the created service. */
 static SC_HANDLE manager, service;
@@ -106,7 +109,7 @@ service_start(int *argcp, char **argvp[])
             VLOG_FATAL("Failed to create a event (%s).", msg_buf);
         }
 
-        poll_fd_wait_event(0, wevent, POLLIN);
+        poll_wevent_wait(wevent);
 
         /* Register the control handler. This function is called by the service
          * manager to stop the service. */
@@ -205,7 +208,7 @@ should_service_stop(void)
         if (service_status.dwCurrentState != SERVICE_RUNNING) {
             return true;
         } else {
-            poll_fd_wait_event(0, wevent, POLLIN);
+            poll_wevent_wait(wevent);
         }
     }
     return false;
@@ -217,6 +220,11 @@ should_service_stop(void)
 void
 service_stop()
 {
+    if (!service_started) {
+        return;
+    }
+    fatal_signal_atexit_handler();
+
     ResetEvent(wevent);
     CloseHandle(wevent);
 
@@ -395,25 +403,6 @@ detach_process(int argc, char *argv[])
     exit(0);
 }
 
-/* Will daemonize() really detach? */
-bool
-get_detach()
-{
-    return detach;
-}
-
-void
-daemon_save_fd(int fd OVS_UNUSED)
-{
-}
-
-void
-daemonize(void)
-{
-    daemonize_start();
-    daemonize_complete();
-}
-
 static void
 unlink_pidfile(void)
 {
@@ -458,7 +447,8 @@ make_pidfile(void)
     /* Don't close the pidfile till the process exits. */
 }
 
-void daemonize_start(void)
+void
+daemonize_start(bool access_datapath OVS_UNUSED)
 {
     if (pidfile) {
         make_pidfile();
@@ -472,6 +462,9 @@ daemonize_complete(void)
      * communicate with the parent to inform that the child is ready. */
     if (detached) {
         int error;
+
+        close_standard_fds();
+
         error = WriteFile(write_handle, "a", 1, NULL, NULL);
         if (!error) {
             VLOG_FATAL("Failed to communicate with the parent (%s)",
@@ -482,28 +475,25 @@ daemonize_complete(void)
     service_complete();
 }
 
+void
+daemon_become_new_user(bool access_datapath OVS_UNUSED)
+{
+}
+
 /* Returns the file name that would be used for a pidfile if 'name' were
  * provided to set_pidfile().  The caller must free the returned string. */
-static char *
+char *
 make_pidfile_name(const char *name)
 {
     if (name && strchr(name, ':')) {
-        return strdup(name);
+        return xstrdup(name);
     } else {
         return xasprintf("%s/%s.pid", ovs_rundir(), program_name);
     }
 }
 
-/* Sets up a following call to daemonize() to create a pidfile named 'name'.
- * If 'name' begins with '/', then it is treated as an absolute path.
- * Otherwise, it is taken relative to RUNDIR, which is $(prefix)/var/run by
- * default.
- *
- * If 'name' is null, then program_name followed by ".pid" is used. */
 void
-set_pidfile(const char *name)
+daemon_set_new_user(const char *user_spec OVS_UNUSED)
 {
-    assert_single_threaded();
-    free(pidfile);
-    pidfile = make_pidfile_name(name);
+    VLOG_FATAL("--user options is not currently supported.");
 }