1 chuck 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
|
4 diane 1.4 // The Open Group, Tivoli Systems
|
5 chuck 1.1 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Diane Olson (dianeols@us.ibm.com)
25 //
|
26 kumpf 1.3 // Modified By: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
|
27 chuck 1.1 //
|
28 david 1.9 // Modified By: Dave Rosckes (rosckes@us.ibm.com)
29 //
|
30 humberto 1.11 // Modified By: Bert Rivero (hurivero@us.ibm.com)
31 //
|
32 chuck 1.1 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <Pegasus/Common/Config.h>
39 #include <Pegasus/Common/String.h>
|
40 david 1.9 #include <Pegasus/Common/Logger.h>
|
41 chuck 1.1 #include <except.h>
42
|
43 humberto 1.11 #include <stdio.h>
44 #include "qycmutiltyUtility.H"
|
45 chuck 1.1 #include "qycmjobjobJob.H"
46 #include "qycmmsgclsMessage.H"
47 #include "licall.h" // EPTCALL macros.
48
49 // Needed for QWTCHGJB API
50 #include <qwtchgjb.cleinc>
51 #include "qushdler.H"
52
53 // Structure need for the CHGJOB(QWTCHGJB) API
54 typedef struct jobChangeInfo
55 {
56 Qus_Job_Change_Information_t fieldNum;
57 Qus_JOBC0100_t format;
58 char data[31];
59 } jobChangeInfo_t;
60
61 // Errorcode for system API calls
62 Qus_EC_t errorCode;
63
64 PEGASUS_USING_PEGASUS;
65 PEGASUS_USING_STD;
66 chuck 1.1
67 // Stub out all these functions. Not used on the iSeries.
68 void cim_server_service(int argc, char **argv ) { return; }
|
69 kumpf 1.3
70 // notify parent process to terminate so user knows that cimserver
71 // is ready to serve CIM requests. If this plateform needs to implement
72 // this functionality, please see sample implementation in cimserver_unix.cpp.
73 void notify_parent(void)
74 {
75 }
|
76 chuck 1.1
77 ///////////////////////////////////////////////////////////////////////
78 // cimserver_fork()
79 //
80 // The iSeries qycmctlcimCimomServer.C (QYCMCTLCIM program) code has
81 // already checked that the CIMOM server is not already running prior
82 // to calling the CIMOM server (QYCMCIMOM) and telling it to start itself.
83 // Therefore, no check is made in this method to ensure the CIMOM server
84 // is not already running.
85 //
86 // Note: This code was written because fork( ) is not supported on OS/400.
87 ///////////////////////////////////////////////////////////////////////
88 int cimserver_fork(void)
89 {
90 char rc5[3] = "05"; // rc5 means the CIMOM Server failed to start
91 char cppServ[10] = "QYCMCIMOM";
92 ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
93
94 // Submit the server job (QYCMCIMOM). The job is submitted with the
95 // daemon=false parameter to avoid an infinite loop of jobs being
96 // submitted by this code!
97 chuck 1.1 if (YCMJOB_SUBMIT_FAILED == cppJob.submit(YCMJOB_SRVR_PGM,
98 YCMJOB_QSYS_LIB,
99 "daemon=false",
100 YCMJOB_JOBD,
101 YCMJOB_QSYS_LIB,
102 YCMJOB_CCSID_37,
103 YCMJOB_THREAD_YES))
104 { // QYCMCIMOM Server Failed on Submit Job
|
105 david 1.10 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
106 david 1.9 "cimserver_os400::cimserver_fork() - SBMJOB failed to start the QYCMCIMOM server program!!");
107
|
108 chuck 1.1 std::string errCode = rc5;
109 std::string srvName = cppServ;
110 std::string replacementData = errCode + srvName;
111
|
112 chuck 1.5 ycmMessage message(msgCPDDF80,
|
113 chuck 1.1 CPDprefix,
114 replacementData,
115 "cimserver_os400::cimserver_fork()",
116 ycmCTLCIMID);
117 message.joblogIt(UserError,ycmMessage::Diagnostic);
118
119 // save the job log
120 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
121
|
122 david 1.9
|
123 chuck 1.1 return(-1); // -1 indicates to QYCMCIMOM that the server failed to start
124 }
125
126 // The QYCMCIMOM job was submitted with daemon=false. This job can now exit.
127 // This is similiar to what the unix version of this code does - the parent exits
128 // after the fork( )
|
129 diane 1.4 return(0);
|
130 chuck 1.1 }
131
132
133 ////////////////////////////////////////////////////
134 // CancelHandler
135 ////////////////////////////////////////////////////
136 void CancelHandler (_CNL_Hndlr_Parms_T *cancelParms)
137 { // make sure a job log gets saved too
138 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
139 }
140
141
|
142 chuck 1.2 ////////////////////////////////////////////////////
143 // iSeries-specific function to initialize the server.
144 // Does the following:
145 // -- Sets the server type to QIBM_CIMOM
146 // so that iNavigator can start/stop it.
147 // -- Swaps the job user to QSYS.
148 // -- Changes the authority of QYCMJOBD
149 ////////////////////////////////////////////////////
150 int cimserver_initialize(void)
|
151 chuck 1.1 {
|
152 david 1.9
|
153 chuck 1.1
154 // setup cancel handler to make sure job log gets saved if we exit abnormally
155 // TODO: this is currently commented out because it causes build errors -
156 // it compiles just fine though. Hopefully this problem will be fixed
157 // (it's a known problem) and we can uncomment this #pragma.
158 // #pragma cancel_handler (CancelHandler, NULL)
|
159 david 1.9 try {
|
160 chuck 1.2
|
161 david 1.9 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
|
162 chuck 1.2 //////////////////////////////////////////
|
163 chuck 1.1 // Change Job API call
164 // Change the server type to QICM_CIMOM
165 //////////////////////////////////////////
166 jobChangeInfo_t chg = {1,
167 46,
168 1911,
169 'C',
170 0X40,0X40,0X40,30,
171 "QIBM_CIMOM ",
172 };
173
174 // Initialize the error code structure to signal exceptions
175 errorCode.Bytes_Provided = 0;
176
177 // Call CHGJOB API with Server Type field
178 EPTCALL(QWTCHGJB, ("* ",
179 " ",
180 "JOBC0200",
181 &chg,
182 &errorCode), OFF, OFF);
183
184 chuck 1.1 ////////////////////////////////////////////////////
185 // Change authority to the qypsjobd job description
186 ////////////////////////////////////////////////////
187 system("QSYS/GRTOBJAUT OBJ(QSYS/QYCMJOBD) OBJTYPE(*JOBD) USER(*PUBLIC) AUT(*EXCLUDE)");
188 }
189 catch (...)
190 {
|
191 david 1.10 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
192 david 1.9 "cimerver_os400::cimserver_os400_setup() - caught unknown exception\n");
193
194 return(-1);
|
195 chuck 1.1 }
196
197 // TODO: this is currently commented out because it causes build errors -
198 // it compiles just fine though. Hopefully this problem will be fixed
199 // (it's a known problem) and we can uncomment this #pragma.
200 // #pragma disable_handler
201
202 return(0);
203 }
204
205 ///////////////////////////////////////////////////////////////////////
206 // cimserver_kill()
207 //
208 // The iSeries qycmctlcimCimomServer.C (QYCMCTLCIM program) code has
209 // already checked that the CIMOM server is already running prior to
210 // calling the CIMOM server (QYCMCIMOM) and telling it to shutdown.
211 // However, a check is still made in this method because we have to
212 // find the job number in order to kill the job.
213 //
214 // For iSeries, this method is called regardless of whether we took
215 // errors trying to connect to the server - if the CIMOM server job
216 chuck 1.1 // is anywhere on the system, in any state, this method will find it
217 // and kill it dead!!
218 //
219 // NEVER call this method unless the server is unable to be shut down
220 // gracefully.
221 ///////////////////////////////////////////////////////////////////////
222 int cimserver_kill(void)
223 { // Need to kill the server
224 char rc2[3] = "02"; // CIMOM server failed to end
225 char cppServ[10] = "QYCMCIMOM";
226 std::string number = YCMJOB_ALL_NUMBERS; // parameter passed to job::find method
227
228 // Construct a ycmJob object
229 ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
230 // Find the QYCMCIMOM job
231 char cppStatus = cppJob.find(number);
232
233 if (cppStatus == YCMJOB_FOUND) // CIMOM Server is Running
234 {
235 if (cppJob.end(cppJob.getNumber(), 'C', 30) == YCMJOB_END_FAILED)
236 {
237 chuck 1.1 std::string errCode = rc2;
238 std::string srvName = cppServ;
239 std::string replacementData = errCode + srvName;
240
|
241 chuck 1.5 ycmMessage message(msgCPDDF81,
|
242 chuck 1.1 CPDprefix,
243 replacementData,
244 "cimserver_os400::cimserver_kill()",
245 ycmCTLCIMID);
246 message.joblogIt(UserError,ycmMessage::Diagnostic);
247
|
248 david 1.10 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
249 david 1.9 "cimserver_os400::cimserver_kill - FAILED to end the QYCMCIMOM job!!");
|
250 chuck 1.1
251 return -1; // Note: this return code is ignored by the CIMOM server.
252 }
253 }
254 // The case of the job not found is already handled in QYCMCTLCIM program
255 return(0);
256 }
257
|
258 chuck 1.2 ////////////////////////////////////////////////////
259 // Checks if the QYCMCIMOM server job is running.
260 ////////////////////////////////////////////////////
|
261 chuck 1.1 Boolean isCIMServerRunning(void)
262 {
263 std::string number = YCMJOB_ALL_NUMBERS; // parameter passed to job::find method
264
265 // Construct a ycmJob object
266 ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
267
268 // Find the QYCMCIMOM job
269 char cppStatus = cppJob.find(number);
270
271 if (cppStatus == YCMJOB_FOUND) // CIMOM Server is Running
272 {
273 return true;
274 }
275
276 return false;
277 }
278
|
279 humberto 1.11 ////////////////////////////////////////////////////
280 // Setup a fifo for process communication
281 ////////////////////////////////////////////////////
282 int init_fifo(const char * fifo_name){
283 int fifo = -1;
284 struct stat FIFO_STAT;
285 int stat_rc = stat( fifo_name, &FIFO_STAT );
286
287 // check if the FIFO already exists
288 if( S_ISFIFO( FIFO_STAT.st_mode ) ){
289 // prep FIFO, on this end we only want to write to it,
290 // set its I/O mode to not block on any reads
291 fifo = open(fifo_name, O_RDWR | O_NONBLOCK);
292 }
293 return fifo;
294 }
295
296
297 ////////////////////////////////////////////////////
298 // Sends return code back to caller before exiting...
299 ////////////////////////////////////////////////////
300 humberto 1.11 void cimserver_exitRC(int rc){
301 int fifo = init_fifo(QYCMSSERV_FIFO);
302
303 if( fifo != -1 ){
304 char rc_tmp[3];
305 memset(rc_tmp, 0, 3);
306 sprintf(rc_tmp,"%d",rc);
307 write(fifo,rc_tmp,strlen(rc_tmp));
308 }
309 }
|