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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2