[Openvas-commits] r3464 - in trunk/openvas-manager: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon May 25 12:34:00 CEST 2009


Author: mattm
Date: 2009-05-25 12:34:00 +0200 (Mon, 25 May 2009)
New Revision: 3464

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/openvasmd.c
Log:
	* src/openvasmd.c (main): Fork into background on start, or stay in
	foreground if -f switch given.


Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-05-25 09:55:11 UTC (rev 3463)
+++ trunk/openvas-manager/ChangeLog	2009-05-25 10:34:00 UTC (rev 3464)
@@ -1,5 +1,10 @@
 2009-05-23  Matthew Mundell <mmundell at intevation.de>
 
+	* src/openvasmd.c (main): Fork into background on start, or stay in
+	foreground if -f switch given.
+
+2009-05-23  Matthew Mundell <mmundell at intevation.de>
+
 	* src/omp.c (STATUS_SERVICE_DOWN): New status code.
 	(omp_xml_handle_start_element): Initialise current_uuid in operations that
 	use it.

Modified: trunk/openvas-manager/src/openvasmd.c
===================================================================
--- trunk/openvas-manager/src/openvasmd.c	2009-05-25 09:55:11 UTC (rev 3463)
+++ trunk/openvas-manager/src/openvasmd.c	2009-05-25 10:34:00 UTC (rev 3464)
@@ -608,6 +608,7 @@
 
   /* Process options. */
 
+  static gboolean foreground = FALSE;
   static gboolean print_version = FALSE;
   static gchar *manager_address_string = NULL;
   static gchar *manager_port_string = NULL;
@@ -617,12 +618,13 @@
   GOptionContext *option_context;
   static GOptionEntry option_entries[]
     = {
+        { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Run in the foreground, instead of forking into the background.", NULL },
         { "listen", 'a', 0, G_OPTION_ARG_STRING, &manager_address_string, "Listen on <address>.", "<address>" },
         { "port", 'p', 0, G_OPTION_ARG_STRING, &manager_port_string, "Use port number <number>.", "<number>" },
         { "slisten", 'l', 0, G_OPTION_ARG_STRING, &server_address_string, "Server (openvasd) address.", "<address>" },
         { "sport", 's', 0, G_OPTION_ARG_STRING, &server_port_string, "Server (openvasd) port number.", "<number>" },
         { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Print progress messages.", NULL },
-        { "version", 0, 0, G_OPTION_ARG_NONE, &print_version, "Print version.", NULL },
+        { "version", 0, 0, G_OPTION_ARG_NONE, &print_version, "Print version and exit.", NULL },
         { NULL }
       };
 
@@ -694,6 +696,27 @@
   server.rules = NULL;
 #endif
 
+  if (foreground == FALSE)
+    {
+      /* Fork into the background. */
+      pid_t pid = fork ();
+      switch (pid)
+        {
+          case 0:
+            /* Child. */
+            break;
+          case -1:
+            /* Parent when error. */
+            perror ("Failed to fork into background");
+            exit (EXIT_FAILURE);
+            break;
+          default:
+            /* Parent. */
+            exit (EXIT_SUCCESS);
+            break;
+        }
+    }
+
   /* Initialise OMP daemon. */
 
   if (init_ompd ())



More information about the Openvas-commits mailing list