gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6438 - GNUnet/src/applications/fs/tools


From: gnunet
Subject: [GNUnet-SVN] r6438 - GNUnet/src/applications/fs/tools
Date: Sun, 24 Feb 2008 08:51:17 -0700 (MST)

Author: durner
Date: 2008-02-24 08:51:17 -0700 (Sun, 24 Feb 2008)
New Revision: 6438

Modified:
   GNUnet/src/applications/fs/tools/gnunet-auto-share.c
Log:
fix build problems

Modified: GNUnet/src/applications/fs/tools/gnunet-auto-share.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-auto-share.c        2008-02-24 
14:06:12 UTC (rev 6437)
+++ GNUnet/src/applications/fs/tools/gnunet-auto-share.c        2008-02-24 
15:51:17 UTC (rev 6438)
@@ -71,7 +71,15 @@
 
 static FILE *myout;
 
+#ifdef MINGW
 /**
+ * Windows service information
+ */
+static SERVICE_STATUS theServiceStatus;
+static SERVICE_STATUS_HANDLE hService;
+#endif
+
+/**
  * Print progess message.
  */
 static void *
@@ -427,14 +435,91 @@
   return errorCode;
 }
 
+void auto_share_shutdown_initiate ()
+{
+  // FIXME
+}
+
+/**
+ * Shutdown gnunetd
+ * @param cfg configuration, may be NULL if in service mode
+ * @param sig signal code that causes shutdown, optional
+ */
+void
+auto_share_shutdown_request (struct GNUNET_GC_Configuration *cfg, int sig)
+{
 #ifdef MINGW
+  if (!cfg || GNUNET_GC_get_configuration_value_yesno (cfg,
+                                                       "GNUNET-AUTO-SHARE",
+                                                       "WINSERVICE",
+                                                       GNUNET_NO) ==
+      GNUNET_YES)
+    {
+      /* If GNUnet runs as service, only the
+         Service Control Manager is allowed
+         to kill us. */
+      if (sig != SERVICE_CONTROL_STOP)
+        {
+          SERVICE_STATUS theStat;
+
+          /* Init proper shutdown through the SCM */
+          if (GNControlService (hService, SERVICE_CONTROL_STOP, &theStat))
+            {
+              /* Success */
+
+              /* The Service Control Manager will call
+                 gnunetd.c::ServiceCtrlHandler(), which calls
+                 this function again. We then stop the gnunetd. */
+              return;
+            }
+          /* We weren't able to tell the SCM to stop the service,
+             but we don't care.
+             Just shut the gnunetd process down. */
+        }
+
+      /* Acknowledge the shutdown request */
+      theServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
+      GNSetServiceStatus (hService, &theServiceStatus);
+    }
+#endif
+
+  auto_share_shutdown_initiate ();
+}
+
+#ifdef MINGW
 /**
- * Main method of the windows service
+ * This function is called from the Windows Service Control Manager
+ * when a service has to shutdown
  */
-void WINAPI
+static void WINAPI
+ServiceCtrlHandler (DWORD dwOpcode)
+{
+  if (dwOpcode == SERVICE_CONTROL_STOP)
+    auto_share_shutdown_request (NULL, dwOpcode);
+}
+
+/**
+ * called by gnunetd.c::ServiceMain()
+ */
+void
 ServiceMain (DWORD argc, LPSTR * argv)
 {
-  GNUNET_CORE_w32_service_main (auto_share_main);
+  memset (&theServiceStatus, 0, sizeof (theServiceStatus));
+  theServiceStatus.dwServiceType = SERVICE_WIN32;
+  theServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+  theServiceStatus.dwCurrentState = SERVICE_RUNNING;
+
+  hService = GNRegisterServiceCtrlHandler ("GNUnet Auto Share", 
ServiceCtrlHandler);
+  if (!hService)
+    return;
+
+  GNSetServiceStatus (hService, &theServiceStatus);
+
+  // FIXME
+  auto_share_main ("FIXME");
+
+  theServiceStatus.dwCurrentState = SERVICE_STOPPED;
+  GNSetServiceStatus (hService, &theServiceStatus);
 }
 #endif
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]