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 david 1.12 //Needed for SQL APIs
54 #include "sqlcli.h"
55
|
56 chuck 1.1 // Structure need for the CHGJOB(QWTCHGJB) API
57 typedef struct jobChangeInfo
58 {
59 Qus_Job_Change_Information_t fieldNum;
60 Qus_JOBC0100_t format;
61 char data[31];
62 } jobChangeInfo_t;
63
64 // Errorcode for system API calls
65 Qus_EC_t errorCode;
66
67 PEGASUS_USING_PEGASUS;
68 PEGASUS_USING_STD;
69
70 // Stub out all these functions. Not used on the iSeries.
71 void cim_server_service(int argc, char **argv ) { return; }
|
72 kumpf 1.3
73 // notify parent process to terminate so user knows that cimserver
74 // is ready to serve CIM requests. If this plateform needs to implement
75 // this functionality, please see sample implementation in cimserver_unix.cpp.
76 void notify_parent(void)
77 {
78 }
|
79 chuck 1.1
80 ///////////////////////////////////////////////////////////////////////
81 // cimserver_fork()
82 //
83 // The iSeries qycmctlcimCimomServer.C (QYCMCTLCIM program) code has
84 // already checked that the CIMOM server is not already running prior
85 // to calling the CIMOM server (QYCMCIMOM) and telling it to start itself.
86 // Therefore, no check is made in this method to ensure the CIMOM server
87 // is not already running.
88 //
89 // Note: This code was written because fork( ) is not supported on OS/400.
90 ///////////////////////////////////////////////////////////////////////
91 int cimserver_fork(void)
92 {
93 char rc5[3] = "05"; // rc5 means the CIMOM Server failed to start
94 char cppServ[10] = "QYCMCIMOM";
95 ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
96
97 // Submit the server job (QYCMCIMOM). The job is submitted with the
98 // daemon=false parameter to avoid an infinite loop of jobs being
99 // submitted by this code!
100 chuck 1.1 if (YCMJOB_SUBMIT_FAILED == cppJob.submit(YCMJOB_SRVR_PGM,
101 YCMJOB_QSYS_LIB,
102 "daemon=false",
103 YCMJOB_JOBD,
104 YCMJOB_QSYS_LIB,
105 YCMJOB_CCSID_37,
106 YCMJOB_THREAD_YES))
107 { // QYCMCIMOM Server Failed on Submit Job
|
108 david 1.10 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
109 david 1.9 "cimserver_os400::cimserver_fork() - SBMJOB failed to start the QYCMCIMOM server program!!");
110
|
111 chuck 1.1 std::string errCode = rc5;
112 std::string srvName = cppServ;
113 std::string replacementData = errCode + srvName;
114
|
115 chuck 1.5 ycmMessage message(msgCPDDF80,
|
116 chuck 1.1 CPDprefix,
117 replacementData,
118 "cimserver_os400::cimserver_fork()",
119 ycmCTLCIMID);
120 message.joblogIt(UserError,ycmMessage::Diagnostic);
121
122 // save the job log
123 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
124
|
125 david 1.9
|
126 chuck 1.1 return(-1); // -1 indicates to QYCMCIMOM that the server failed to start
127 }
128
129 // The QYCMCIMOM job was submitted with daemon=false. This job can now exit.
130 // This is similiar to what the unix version of this code does - the parent exits
131 // after the fork( )
|
132 diane 1.4 return(0);
|
133 chuck 1.1 }
134
135
136 ////////////////////////////////////////////////////
137 // CancelHandler
138 ////////////////////////////////////////////////////
139 void CancelHandler (_CNL_Hndlr_Parms_T *cancelParms)
140 { // make sure a job log gets saved too
141 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
142 }
143
144
|
145 chuck 1.2 ////////////////////////////////////////////////////
146 // iSeries-specific function to initialize the server.
147 // Does the following:
148 // -- Sets the server type to QIBM_CIMOM
149 // so that iNavigator can start/stop it.
150 // -- Swaps the job user to QSYS.
151 // -- Changes the authority of QYCMJOBD
152 ////////////////////////////////////////////////////
153 int cimserver_initialize(void)
|
154 chuck 1.1 {
|
155 david 1.12 SQLHENV henv; // SQL environment variable
156 long attr; // SQL attribute to be set
|
157 chuck 1.1
158 // setup cancel handler to make sure job log gets saved if we exit abnormally
159 // TODO: this is currently commented out because it causes build errors -
160 // it compiles just fine though. Hopefully this problem will be fixed
161 // (it's a known problem) and we can uncomment this #pragma.
162 // #pragma cancel_handler (CancelHandler, NULL)
|
163 david 1.9 try {
|
164 chuck 1.2
|
165 david 1.9 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
|
166 chuck 1.2 //////////////////////////////////////////
|
167 chuck 1.1 // Change Job API call
168 // Change the server type to QICM_CIMOM
169 //////////////////////////////////////////
170 jobChangeInfo_t chg = {1,
171 46,
172 1911,
173 'C',
174 0X40,0X40,0X40,30,
175 "QIBM_CIMOM ",
176 };
177
178 // Initialize the error code structure to signal exceptions
179 errorCode.Bytes_Provided = 0;
180
181 // Call CHGJOB API with Server Type field
182 EPTCALL(QWTCHGJB, ("* ",
183 " ",
184 "JOBC0200",
185 &chg,
186 &errorCode), OFF, OFF);
187
188 chuck 1.1 ////////////////////////////////////////////////////
189 // Change authority to the qypsjobd job description
190 ////////////////////////////////////////////////////
191 system("QSYS/GRTOBJAUT OBJ(QSYS/QYCMJOBD) OBJTYPE(*JOBD) USER(*PUBLIC) AUT(*EXCLUDE)");
|
192 david 1.12
193 SQLAllocEnv(&henv); // Allocating SQL environment variable
194 attr = SQL_TRUE; // Set SQL attribute to true
195
196 // Set the SQL server mode to true.
197 // This will allow multiple connections to the same data source.
198 SQLSetEnvAttr(henv,SQL_ATTR_SERVER_MODE, &attr,0);
|
199 chuck 1.1 }
200 catch (...)
201 {
|
202 david 1.10 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
203 david 1.9 "cimerver_os400::cimserver_os400_setup() - caught unknown exception\n");
204
205 return(-1);
|
206 chuck 1.1 }
207
208 // TODO: this is currently commented out because it causes build errors -
209 // it compiles just fine though. Hopefully this problem will be fixed
210 // (it's a known problem) and we can uncomment this #pragma.
211 // #pragma disable_handler
212
213 return(0);
214 }
215
216 ///////////////////////////////////////////////////////////////////////
217 // cimserver_kill()
218 //
219 // The iSeries qycmctlcimCimomServer.C (QYCMCTLCIM program) code has
220 // already checked that the CIMOM server is already running prior to
221 // calling the CIMOM server (QYCMCIMOM) and telling it to shutdown.
222 // However, a check is still made in this method because we have to
223 // find the job number in order to kill the job.
224 //
225 // For iSeries, this method is called regardless of whether we took
226 // errors trying to connect to the server - if the CIMOM server job
227 chuck 1.1 // is anywhere on the system, in any state, this method will find it
228 // and kill it dead!!
229 //
230 // NEVER call this method unless the server is unable to be shut down
231 // gracefully.
232 ///////////////////////////////////////////////////////////////////////
233 int cimserver_kill(void)
234 { // Need to kill the server
235 char rc2[3] = "02"; // CIMOM server failed to end
236 char cppServ[10] = "QYCMCIMOM";
237 std::string number = YCMJOB_ALL_NUMBERS; // parameter passed to job::find method
238
239 // Construct a ycmJob object
240 ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
241 // Find the QYCMCIMOM job
242 char cppStatus = cppJob.find(number);
243
244 if (cppStatus == YCMJOB_FOUND) // CIMOM Server is Running
245 {
246 if (cppJob.end(cppJob.getNumber(), 'C', 30) == YCMJOB_END_FAILED)
247 {
248 chuck 1.1 std::string errCode = rc2;
249 std::string srvName = cppServ;
250 std::string replacementData = errCode + srvName;
251
|
252 chuck 1.5 ycmMessage message(msgCPDDF81,
|
253 chuck 1.1 CPDprefix,
254 replacementData,
255 "cimserver_os400::cimserver_kill()",
256 ycmCTLCIMID);
257 message.joblogIt(UserError,ycmMessage::Diagnostic);
258
|
259 david 1.10 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
260 david 1.9 "cimserver_os400::cimserver_kill - FAILED to end the QYCMCIMOM job!!");
|
261 chuck 1.1
262 return -1; // Note: this return code is ignored by the CIMOM server.
263 }
264 }
265 // The case of the job not found is already handled in QYCMCTLCIM program
266 return(0);
267 }
268
|
269 chuck 1.2 ////////////////////////////////////////////////////
270 // Checks if the QYCMCIMOM server job is running.
271 ////////////////////////////////////////////////////
|
272 chuck 1.1 Boolean isCIMServerRunning(void)
273 {
274 std::string number = YCMJOB_ALL_NUMBERS; // parameter passed to job::find method
275
276 // Construct a ycmJob object
277 ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
278
279 // Find the QYCMCIMOM job
280 char cppStatus = cppJob.find(number);
281
282 if (cppStatus == YCMJOB_FOUND) // CIMOM Server is Running
283 {
284 return true;
285 }
286
287 return false;
288 }
289
|
290 humberto 1.11 ////////////////////////////////////////////////////
291 // Setup a fifo for process communication
292 ////////////////////////////////////////////////////
293 int init_fifo(const char * fifo_name){
294 int fifo = -1;
295 struct stat FIFO_STAT;
296 int stat_rc = stat( fifo_name, &FIFO_STAT );
297
298 // check if the FIFO already exists
299 if( S_ISFIFO( FIFO_STAT.st_mode ) ){
300 // prep FIFO, on this end we only want to write to it,
301 // set its I/O mode to not block on any reads
302 fifo = open(fifo_name, O_RDWR | O_NONBLOCK);
303 }
304 return fifo;
305 }
306
307
308 ////////////////////////////////////////////////////
309 // Sends return code back to caller before exiting...
310 ////////////////////////////////////////////////////
311 humberto 1.11 void cimserver_exitRC(int rc){
312 int fifo = init_fifo(QYCMSSERV_FIFO);
313
314 if( fifo != -1 ){
315 char rc_tmp[3];
316 memset(rc_tmp, 0, 3);
317 sprintf(rc_tmp,"%d",rc);
318 write(fifo,rc_tmp,strlen(rc_tmp));
319 }
320 }
|