BUG#:5399 RELEASE_2_5_3-RC1
authormarek <marek>
Fri, 18 Aug 2006 17:40:38 +0000 (17:40 +0000)
committermarek <marek>
Fri, 18 Aug 2006 17:40:38 +0000 (17:40 +0000)
TITLE: enable signal support in cimlistener

DESCRIPTION:

src/Pegasus/DynListener/Service/cimlistener.cpp
src/Service/ServerProcessUnix.cpp

index 69ba2c6f89809dc91717b03c168edd26695f2b2e..1db78db46a786799ca022f3b0c6d74d88cf26adc 100644 (file)
 #include <Pegasus/Common/Thread.h>
 #include <Pegasus/Common/LanguageParser.h>
 #include <Pegasus/Common/PegasusVersion.h>
+#include <Pegasus/Common/Signal.h>
 #include <Pegasus/DynListener/DynamicListener.h>
 #include <Pegasus/DynListener/DynamicListenerConfig.h>
 #include <Service/ServerProcess.h>
@@ -642,8 +643,31 @@ int CIMListenerProcess::cimserver_run(
         //gracefully exit
         //Uncomment the following line when signals are implemented on all platforms.
         //The workaround is to use a file.
-        //cimserver_kill(1);
+#ifdef PEGASUS_HAS_SIGNALS
+        FILE *pid_file;
+        pid_t pid = 0;
+
+        // open the file containing the CIMServer process ID
+        pid_file = fopen(getPIDFileName(), "r");
+        if (!pid_file) 
+        {
+            return (-1);
+        }
+
+        // get the pid from the file
+        fscanf(pid_file, "%d\n", &pid);
 
+        fclose(pid_file);
+
+        if (pid == 0)
+        {
+           System::removeFile(getPIDFileName());
+           return (-1);
+        }
+
+        kill(pid, PEGASUS_SIGTERM);
+        //cimserver_kill(1);
+#else
 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \
     || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_SOLARIS) \
     || defined(PEGASUS_OS_VMS)
@@ -669,6 +693,9 @@ int CIMListenerProcess::cimserver_run(
         }
 #endif
 
+#endif //PEGASUS_HAS_SIGNALS
+
+
 #ifdef PEGASUS_OS_OS400
     //l10n
     //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
@@ -981,6 +1008,8 @@ MessageLoader::_useProcessLocale = false;
 
 #if !defined(PEGASUS_OS_TYPE_WINDOWS)
 
+// if signals are defined, do not use old file creation mechanism
+#ifndef PEGASUS_HAS_SIGNALS
 #if defined(PEGASUS_DEBUG)
         printf("Blocking until shutdown signal\n");
 #endif
@@ -999,20 +1028,22 @@ MessageLoader::_useProcessLocale = false;
 #endif
         FileSystem::removeFile(LISTENER_STOP_FILE);
         _cimListener->stop();
+#else // defined(PEGASUS_HAS_SIGNALS)
 
-
-        //Uncomment this block of code when signals are implemented on all platforms.
         //Temporary workaround is to use a file, as specified above.
         //wait until signalled to terminate
-        /*int sig = _cimListenerProcess->cimserver_wait();
+        int sig = _cimListenerProcess->cimserver_wait();
+#if defined(PEGASUS_DEBUG)
         printf("Returned from sigwait %d\n", sig);
-
-        if (sig == SIGUSR1)
+#endif
+        if ((sig == PEGASUS_SIGTERM) || (sig == PEGASUS_SIGHUP))
         {
+#if defined(PEGASUS_DEBUG)
             printf("Graceful shutdown\n");
+#endif            
             _cimListener->stop();
         }
-        */
+#endif
 #else
         //ATTN: Implement cimserver_wait for windows so we don't have to loop here
         //The listener is stopped in the cimserver_stop method by the service control manager
index 001bdc3de564582eec3283e47cb047b9064022e5..336f165f5782229e2c0348a43e3f9ed9982ccfcd 100644 (file)
@@ -85,7 +85,32 @@ ServerProcess::~ServerProcess() {}
 void ServerProcess::cimserver_set_process(void* p) {}
 void ServerProcess::cimserver_exitRC(int rc) {}
 int ServerProcess::cimserver_initialize(void) { return 1; }
+
+// for all OSes supporting signals provide a cimserver_wait function
+// that waits to be awakened by signal PEGASUS_SIGTERM or PEGASUS_SIGHUP
+#ifdef PEGASUS_HAS_SIGNALS
+int ServerProcess::cimserver_wait(void)
+{
+    int sig = -1;
+    sigset_t set;
+    sigemptyset(&set);
+    sigaddset(&set, PEGASUS_SIGTERM);
+    sigaddset(&set, PEGASUS_SIGHUP);
+    errno = 0;
+    do
+    {
+#if defined(PEGASUS_OS_ZOS) || defined(PEGASUS_OS_SOLARIS)
+        sig = sigwait(&set);
+#else // else for platforms = LINUX, HPUX, AIX
+        sigwait(&set, &sig);
+#endif
+    } while (errno == EINTR);
+    return sig;
+}
+#else
 int ServerProcess::cimserver_wait(void) { return 1; }
+#endif
+
 String ServerProcess::getHome(void) { return String::EMPTY; }
 
 // daemon_init , RW Stevens, "Advance UNIX Programming"
@@ -128,7 +153,11 @@ int ServerProcess::cimserver_fork(void)
   }
   
   setsid();
-  umask(0);
+  umask(S_IRWXG | S_IRWXO );
+
+  // spawned daemon process doesn't need the old signal handlers of its parent
+  getSigHandle()->deactivate(PEGASUS_SIGUSR1);
+  getSigHandle()->deactivate(SIGTERM);
 
   // get the pid of the cimserver process
   server_pid = getpid();