#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>
//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)
}
#endif
+#endif //PEGASUS_HAS_SIGNALS
+
+
#ifdef PEGASUS_OS_OS400
//l10n
//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
#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
#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
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"
}
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();