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.16 #include <Pegasus/Common/Executor.h>
|
39 kumpf 1.14
|
40 w.otsuka 1.4 #define MAX_WAIT_TIME 240
|
41 h.sterling 1.1
42 PEGASUS_USING_PEGASUS;
43 PEGASUS_USING_STD;
44
45 Boolean handleSigUsr1 = false;
46 Boolean graveError = false;
47
48 void sigUsr1Handler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig)
49 {
50 handleSigUsr1 = true;
51 }
52
53 void sigTermHandler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig)
54 {
55 graveError= handleSigUsr1=true;
56 }
57
58
59 //constructor
60 ServerProcess::ServerProcess() {}
61
62 h.sterling 1.1 //destructor
63 ServerProcess::~ServerProcess() {}
64
65 // no-ops
66 void ServerProcess::cimserver_set_process(void* p) {}
67 void ServerProcess::cimserver_exitRC(int rc) {}
68 int ServerProcess::cimserver_initialize(void) { return 1; }
|
69 marek 1.10
70 // for all OSes supporting signals provide a cimserver_wait function
71 // that waits to be awakened by signal PEGASUS_SIGTERM or PEGASUS_SIGHUP
72 #ifdef PEGASUS_HAS_SIGNALS
73 int ServerProcess::cimserver_wait(void)
74 {
75 int sig = -1;
76 sigset_t set;
77 sigemptyset(&set);
78 sigaddset(&set, PEGASUS_SIGTERM);
79 sigaddset(&set, PEGASUS_SIGHUP);
80 errno = 0;
81 do
82 {
83 #if defined(PEGASUS_OS_ZOS) || defined(PEGASUS_OS_SOLARIS)
84 sig = sigwait(&set);
85 #else // else for platforms = LINUX, HPUX, AIX
86 sigwait(&set, &sig);
87 #endif
88 } while (errno == EINTR);
89 return sig;
90 marek 1.10 }
91 #else
|
92 h.sterling 1.1 int ServerProcess::cimserver_wait(void) { return 1; }
|
93 marek 1.10 #endif
94
|
95 h.sterling 1.1 String ServerProcess::getHome(void) { return String::EMPTY; }
96
97 // daemon_init , RW Stevens, "Advance UNIX Programming"
98
99 int ServerProcess::cimserver_fork(void)
100 {
|
101 kumpf 1.15 getSigHandle()->registerHandler(SIGTERM, sigTermHandler);
102 getSigHandle()->activate(SIGTERM);
103 umask(S_IRWXG | S_IRWXO);
104
|
105 kumpf 1.16 if (Executor::detectExecutor() == 0)
106 {
107 // We don't need to fork if we're running with Privilege Separation
108 return 0;
109 }
|
110 kumpf 1.15
|
111 h.sterling 1.1 getSigHandle()->registerHandler(PEGASUS_SIGUSR1, sigUsr1Handler);
112 getSigHandle()->activate(PEGASUS_SIGUSR1);
113
114 pid_t pid;
115 if( (pid = fork() ) < 0)
116 {
117 getSigHandle()->deactivate(PEGASUS_SIGUSR1);
118 getSigHandle()->deactivate(SIGTERM);
119 return(-1);
120 }
121 else if (pid != 0)
122 {
123 //
124 // parent wait for child
125 // if there is a problem with signal, parent process terminates
126 // when waitTime expires
127 //
128 Uint32 waitTime = MAX_WAIT_TIME;
129
130 while(!handleSigUsr1 && waitTime > 0)
131 {
132 h.sterling 1.1 sleep(1);
133 waitTime--;
134 }
|
135 w.otsuka 1.4 if( !handleSigUsr1 )
136 {
137 MessageLoaderParms parms("src.Service.ServerProcessUnix.CIMSERVER_START_TIMEOUT",
138 "The cimserver command timed out waiting for the CIM server to start.");
139 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
140 }
|
141 h.sterling 1.1 exit(graveError);
142 }
143
144 setsid();
|
145 marek 1.10 umask(S_IRWXG | S_IRWXO );
146
147 // spawned daemon process doesn't need the old signal handlers of its parent
148 getSigHandle()->deactivate(PEGASUS_SIGUSR1);
149 getSigHandle()->deactivate(SIGTERM);
|
150 h.sterling 1.1
|
151 kumpf 1.16 return 0;
|
152 h.sterling 1.1 }
153
154
155 // notify parent process to terminate so user knows that cimserver
156 // is ready to serve CIM requests.
157 void ServerProcess::notify_parent(int id)
158 {
159 pid_t ppid = getppid();
160 if (id)
161 kill(ppid, SIGTERM);
162 else
163 kill(ppid, PEGASUS_SIGUSR1);
164 }
165
166
167 // Platform specific run
|
168 kumpf 1.7 int ServerProcess::platform_run(
169 int argc,
170 char** argv,
171 Boolean shutdownOption,
172 Boolean debugOutputOption)
|
173 h.sterling 1.1 {
|
174 kumpf 1.7 return cimserver_run(argc, argv, shutdownOption, debugOutputOption);
|
175 h.sterling 1.1 }
|