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