1 karl 1.8 //%2006////////////////////////////////////////////////////////////////////////
|
2 h.sterling 1.1 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.8 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 h.sterling 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
|
33 kumpf 1.14
|
34 h.sterling 1.1 #include <fcntl.h>
35 #include <unistd.h>
|
36 kumpf 1.14
|
37 h.sterling 1.1 #include <Pegasus/Common/Signal.h>
|
38 kumpf 1.14
|
39 w.otsuka 1.4 #define MAX_WAIT_TIME 240
|
40 h.sterling 1.1
41 PEGASUS_USING_PEGASUS;
42 PEGASUS_USING_STD;
43
44 Boolean handleSigUsr1 = false;
45 Boolean graveError = false;
46
47 void sigUsr1Handler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig)
48 {
49 handleSigUsr1 = true;
50 }
51
52 void sigTermHandler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig)
53 {
54 graveError= handleSigUsr1=true;
55 }
56
57
58 //constructor
59 ServerProcess::ServerProcess() {}
60
61 h.sterling 1.1 //destructor
62 ServerProcess::~ServerProcess() {}
63
64 // no-ops
65 void ServerProcess::cimserver_set_process(void* p) {}
66 void ServerProcess::cimserver_exitRC(int rc) {}
67 int ServerProcess::cimserver_initialize(void) { return 1; }
|
68 marek 1.10
69 // for all OSes supporting signals provide a cimserver_wait function
70 // that waits to be awakened by signal PEGASUS_SIGTERM or PEGASUS_SIGHUP
71 #ifdef PEGASUS_HAS_SIGNALS
72 int ServerProcess::cimserver_wait(void)
73 {
74 int sig = -1;
75 sigset_t set;
76 sigemptyset(&set);
77 sigaddset(&set, PEGASUS_SIGTERM);
78 sigaddset(&set, PEGASUS_SIGHUP);
79 errno = 0;
80 do
81 {
82 #if defined(PEGASUS_OS_ZOS) || defined(PEGASUS_OS_SOLARIS)
83 sig = sigwait(&set);
84 #else // else for platforms = LINUX, HPUX, AIX
85 sigwait(&set, &sig);
86 #endif
87 } while (errno == EINTR);
88 return sig;
89 marek 1.10 }
90 #else
|
91 h.sterling 1.1 int ServerProcess::cimserver_wait(void) { return 1; }
|
92 marek 1.10 #endif
93
|
94 h.sterling 1.1 String ServerProcess::getHome(void) { return String::EMPTY; }
95
96 // daemon_init , RW Stevens, "Advance UNIX Programming"
97
98 int ServerProcess::cimserver_fork(void)
99 {
100 getSigHandle()->registerHandler(PEGASUS_SIGUSR1, sigUsr1Handler);
101 getSigHandle()->activate(PEGASUS_SIGUSR1);
102 getSigHandle()->registerHandler(SIGTERM, sigTermHandler);
103 getSigHandle()->activate(SIGTERM);
104
105 pid_t pid;
106 if( (pid = fork() ) < 0)
107 {
108 getSigHandle()->deactivate(PEGASUS_SIGUSR1);
109 getSigHandle()->deactivate(SIGTERM);
110 return(-1);
111 }
112 else if (pid != 0)
113 {
114 //
115 h.sterling 1.1 // parent wait for child
116 // if there is a problem with signal, parent process terminates
117 // when waitTime expires
118 //
119 Uint32 waitTime = MAX_WAIT_TIME;
120
121 while(!handleSigUsr1 && waitTime > 0)
122 {
123 sleep(1);
124 waitTime--;
125 }
|
126 w.otsuka 1.4 if( !handleSigUsr1 )
127 {
128 MessageLoaderParms parms("src.Service.ServerProcessUnix.CIMSERVER_START_TIMEOUT",
129 "The cimserver command timed out waiting for the CIM server to start.");
130 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
131 }
|
132 h.sterling 1.1 exit(graveError);
133 }
134
135 setsid();
|
136 marek 1.10 umask(S_IRWXG | S_IRWXO );
137
138 // spawned daemon process doesn't need the old signal handlers of its parent
139 getSigHandle()->deactivate(PEGASUS_SIGUSR1);
140 getSigHandle()->deactivate(SIGTERM);
|
141 h.sterling 1.1
142 return(0);
143 }
144
145
146 // notify parent process to terminate so user knows that cimserver
147 // is ready to serve CIM requests.
148 void ServerProcess::notify_parent(int id)
149 {
150 pid_t ppid = getppid();
151 if (id)
152 kill(ppid, SIGTERM);
153 else
154 kill(ppid, PEGASUS_SIGUSR1);
155 }
156
157
158 // Platform specific run
|
159 kumpf 1.7 int ServerProcess::platform_run(
160 int argc,
161 char** argv,
162 Boolean shutdownOption,
163 Boolean debugOutputOption)
|
164 h.sterling 1.1 {
|
165 kumpf 1.7 return cimserver_run(argc, argv, shutdownOption, debugOutputOption);
|
166 h.sterling 1.1 }
|