(file) Return to cimserver_os400.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Server

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2