]> git.proxmox.com Git - mirror_ovs.git/blobdiff - lib/daemon-windows.c
cirrus: Use FreeBSD 12.2.
[mirror_ovs.git] / lib / daemon-windows.c
index 7e2e9da95d3da296580d97c6e12b44b87225d382..7e5f264f5b9e7de52f51c5e16c2e887e2ba1bf4d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Nicira, Inc.
+ * Copyright (c) 2014, 2017 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <stdio.h>
 #include <io.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include "dirs.h"
+#include "fatal-signal.h"
 #include "ovs-thread.h"
-#include "poll-loop.h"
+#include "openvswitch/poll-loop.h"
 #include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(daemon_windows);
@@ -77,8 +79,15 @@ daemon_usage(void)
         "\nService options:\n"
         "  --service               run in background as a service.\n"
         "  --service-monitor       restart the service in case of an "
-                                   "unexpected failure. \n",
-        ovs_rundir(), program_name);
+                                   "unexpected failure. \n");
+}
+
+/* Sets up a following call to service_start() to detach from the foreground
+ * session, running this process in the background.  */
+void
+set_detach(void)
+{
+    detach = true;
 }
 
 /* Registers the call-back and configures the actions in case of a failure
@@ -137,12 +146,11 @@ service_start(int *argcp, char **argvp[])
         *argcp = sargc;
         *argvp = *sargvp;
 
-        /* XXX: Windows implementation cannot have a unixctl commands in the
-        * traditional sense of unix domain sockets. If an implementation is
-        * done that involves 'unixctl' vlog commands the following call is
-        * needed to make sure that the unixctl commands for vlog get
-        * registered in a daemon, even before the first log message. */
-        vlog_init();
+        /* Enable default error mode so we can take advantage of WER
+         * (Windows Error Reporting) crash dumps.
+         * Being a service it does not allow for WER window pop-up.
+         * XXX implement our on crash dump collection mechanism. */
+        SetErrorMode(0);
 
         return;
     }
@@ -197,6 +205,7 @@ control_handler(DWORD request)
         service_status.dwCurrentState = SERVICE_STOPPED;
         service_status.dwWin32ExitCode = NO_ERROR;
         SetEvent(wevent);
+        SetServiceStatus(hstatus, &service_status);
         break;
 
     default:
@@ -356,7 +365,7 @@ detach_process(int argc, char *argv[])
 
     /* We are only interested in the '--detach' and '--pipe-handle'. */
     for (i = 0; i < argc; i ++) {
-        if (!strcmp(argv[i], "--detach")) {
+        if (!detach && !strcmp(argv[i], "--detach")) {
             detach = true;
         } else if (!strncmp(argv[i], "--pipe-handle", 13)) {
             /* If running as a child, return. */
@@ -476,7 +485,7 @@ make_pidfile(void)
 
     fatal_signal_add_hook(unlink_pidfile, NULL, NULL, true);
 
-    fprintf(filep_pidfile, "%d\n", _getpid());
+    fprintf(filep_pidfile, "%ld\n", (long int) getpid());
     if (fflush(filep_pidfile) == EOF) {
         VLOG_FATAL("Failed to write into the pidfile %s", pidfile);
     }