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

  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 chuck 1.1 //%/////////////////////////////////////////////////////////////////////////////
 31           
 32           #include <sys/types.h>
 33           #include <sys/stat.h>
 34           #include <fcntl.h>
 35           #include <unistd.h>
 36           #include <Pegasus/Common/Config.h>
 37           #include <Pegasus/Common/String.h>
 38 david 1.9 #include <Pegasus/Common/Logger.h>
 39 chuck 1.1 #include <except.h>
 40           
 41           #include "qycmjobjobJob.H"
 42           #include "qycmmsgclsMessage.H"
 43           #include "licall.h"        // EPTCALL macros.
 44           
 45           // Needed for QWTCHGJB API
 46           #include <qwtchgjb.cleinc>
 47           #include "qushdler.H"
 48           
 49           // Structure need for the CHGJOB(QWTCHGJB) API
 50           typedef struct jobChangeInfo
 51           {
 52              Qus_Job_Change_Information_t  fieldNum;
 53              Qus_JOBC0100_t                format;
 54              char                          data[31];
 55           } jobChangeInfo_t;
 56           
 57           // Errorcode for system API calls
 58           Qus_EC_t errorCode;
 59           
 60 chuck 1.1 PEGASUS_USING_PEGASUS;
 61           PEGASUS_USING_STD;
 62           
 63           // Stub out all these functions.  Not used on the iSeries.
 64           void cim_server_service(int argc, char **argv ) { return; }  
 65 kumpf 1.3 
 66           // notify parent process to terminate so user knows that cimserver
 67           // is ready to serve CIM requests. If this plateform needs to implement
 68           // this functionality, please see sample implementation in cimserver_unix.cpp.
 69           void notify_parent(void)
 70           {
 71           }
 72 chuck 1.1 
 73           ///////////////////////////////////////////////////////////////////////
 74           // cimserver_fork()
 75           //
 76           // The iSeries qycmctlcimCimomServer.C (QYCMCTLCIM program) code has
 77           // already checked that the CIMOM server is not already running prior
 78           // to calling the CIMOM server (QYCMCIMOM) and telling it to start itself.
 79           // Therefore, no check is made in this method to ensure the CIMOM server
 80           // is not already running.
 81           //
 82           // Note: This code was written because fork( ) is not supported on OS/400.
 83           ///////////////////////////////////////////////////////////////////////
 84           int cimserver_fork(void) 
 85           {
 86             char rc5[3] = "05"; // rc5 means the CIMOM Server failed to start
 87             char cppServ[10] = "QYCMCIMOM";
 88             ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
 89           
 90             // Submit the server job (QYCMCIMOM).  The job is submitted with the
 91             // daemon=false parameter to avoid an infinite loop of jobs being
 92             // submitted by this code!
 93 chuck 1.1   if (YCMJOB_SUBMIT_FAILED == cppJob.submit(YCMJOB_SRVR_PGM,
 94           					    YCMJOB_QSYS_LIB,
 95           					    "daemon=false",
 96           					    YCMJOB_JOBD,
 97           					    YCMJOB_QSYS_LIB,
 98           					    YCMJOB_CCSID_37,
 99           					    YCMJOB_THREAD_YES))
100             {  // QYCMCIMOM Server Failed on Submit Job
101 david 1.9      Logger::put(Logger::ERROR_LOG, "", Logger::SEVERE,
102           		 "cimserver_os400::cimserver_fork() - SBMJOB failed to start the QYCMCIMOM server program!!");
103           
104 chuck 1.1      std::string errCode = rc5;
105                std::string srvName = cppServ;
106                std::string replacementData = errCode + srvName;
107           
108 chuck 1.5      ycmMessage message(msgCPDDF80,
109 chuck 1.1                         CPDprefix,
110                                   replacementData,
111                                   "cimserver_os400::cimserver_fork()",
112                                   ycmCTLCIMID);
113                message.joblogIt(UserError,ycmMessage::Diagnostic);
114           
115                // save the job log
116                system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
117           
118 david 1.9 
119 chuck 1.1      return(-1);	// -1 indicates to QYCMCIMOM that the server failed to start
120             }
121           
122             // The QYCMCIMOM job was submitted with daemon=false.  This job can now exit.
123             // This is similiar to what the unix version of this code does - the parent exits
124             // after the fork( )
125 diane 1.4   return(0);
126 chuck 1.1 }
127           
128           
129           ////////////////////////////////////////////////////
130           //  CancelHandler
131           ////////////////////////////////////////////////////
132           void CancelHandler (_CNL_Hndlr_Parms_T *cancelParms)
133           {  // make sure a job log gets saved too
134              system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
135           }
136           
137           
138 chuck 1.2 ////////////////////////////////////////////////////
139           // iSeries-specific function to initialize the server.
140           // Does the following:
141           //    -- Sets the server type to QIBM_CIMOM
142           //       so that iNavigator can start/stop it.
143           //    -- Swaps the job user to QSYS. 
144           //    -- Changes the authority of QYCMJOBD
145           ////////////////////////////////////////////////////
146           int cimserver_initialize(void)
147 chuck 1.1 {
148 david 1.9 
149 chuck 1.1 
150              // setup cancel handler to make sure job log gets saved if we exit abnormally
151              // TODO:  this is currently commented out because it causes build errors -
152              //        it compiles just fine though.  Hopefully this problem will be fixed
153              //        (it's a known problem) and we can uncomment this #pragma. 
154           //   #pragma cancel_handler (CancelHandler, NULL)
155 david 1.9     try {
156 chuck 1.2 
157 david 1.9    system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
158 chuck 1.2    //////////////////////////////////////////
159 chuck 1.1    // Change Job API call
160              // Change the server type to QICM_CIMOM
161              ////////////////////////////////////////// 
162              jobChangeInfo_t chg = {1,
163                                     46,
164                                     1911,
165                                     'C',
166                                     0X40,0X40,0X40,30,
167                                     "QIBM_CIMOM                    ",
168                                    };
169           
170              // Initialize the error code structure to signal exceptions
171              errorCode.Bytes_Provided = 0;
172           
173              // Call CHGJOB API with Server Type field
174              EPTCALL(QWTCHGJB, ("*                         ",
175                       "                ",
176                       "JOBC0200",
177                       &chg,
178                       &errorCode), OFF, OFF); 
179           
180 chuck 1.1    ////////////////////////////////////////////////////
181              // Change authority to the qypsjobd job description
182              //////////////////////////////////////////////////// 
183              system("QSYS/GRTOBJAUT OBJ(QSYS/QYCMJOBD) OBJTYPE(*JOBD) USER(*PUBLIC) AUT(*EXCLUDE)");
184            }
185             catch (...)
186             {
187 david 1.9       Logger::put(Logger::ERROR_LOG, "", Logger::SEVERE,
188           		  "cimerver_os400::cimserver_os400_setup() - caught unknown exception\n");
189           
190                 return(-1);
191 chuck 1.1   }
192           
193              // TODO:  this is currently commented out because it causes build errors -
194              //        it compiles just fine though.  Hopefully this problem will be fixed
195              //        (it's a known problem) and we can uncomment this #pragma. 
196           //  #pragma disable_handler
197           
198               return(0);
199           }
200           
201           ///////////////////////////////////////////////////////////////////////
202           // cimserver_kill()
203           //
204           // The iSeries qycmctlcimCimomServer.C (QYCMCTLCIM program) code has
205           // already checked that the CIMOM server is already running prior to
206           // calling the CIMOM server (QYCMCIMOM) and telling it to shutdown.
207           // However, a check is still made in this method because we have to
208           // find the job number in order to kill the job.
209           //
210           // For iSeries, this method is called regardless of whether we took
211           // errors trying to connect to the server - if the CIMOM server job
212 chuck 1.1 // is anywhere on the system, in any state, this method will find it
213           // and kill it dead!!
214           //
215           // NEVER call this method unless the server is unable to be shut down
216           // gracefully.
217           ///////////////////////////////////////////////////////////////////////
218           int cimserver_kill(void)
219           {  // Need to kill the server
220             char rc2[3] = "02"; // CIMOM server failed to end
221             char cppServ[10] = "QYCMCIMOM";
222             std::string number = YCMJOB_ALL_NUMBERS; // parameter passed to job::find method
223           
224             // Construct a ycmJob object
225             ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
226             // Find the QYCMCIMOM job
227             char cppStatus  = cppJob.find(number);
228           
229             if (cppStatus == YCMJOB_FOUND)       // CIMOM Server is Running
230             {
231               if (cppJob.end(cppJob.getNumber(), 'C', 30) == YCMJOB_END_FAILED)
232               {
233 chuck 1.1       std::string errCode = rc2;
234                 std::string srvName = cppServ;
235                 std::string replacementData = errCode + srvName;
236           
237 chuck 1.5       ycmMessage message(msgCPDDF81,
238 chuck 1.1                          CPDprefix,
239                                    replacementData,
240                                    "cimserver_os400::cimserver_kill()",
241                                    ycmCTLCIMID);
242                 message.joblogIt(UserError,ycmMessage::Diagnostic);
243           
244 david 1.9       Logger::put(Logger::ERROR_LOG, "", Logger::SEVERE,
245           		  "cimserver_os400::cimserver_kill - FAILED to end the QYCMCIMOM job!!");
246 chuck 1.1 
247                 return -1; // Note: this return code is ignored by the CIMOM server.
248               }
249             }
250             // The case of the job not found is already handled in QYCMCTLCIM program
251               return(0);
252           }
253           
254 chuck 1.2 ////////////////////////////////////////////////////
255           //  Checks if the QYCMCIMOM server job is running.
256           ////////////////////////////////////////////////////
257 chuck 1.1 Boolean isCIMServerRunning(void)
258           {
259             std::string number = YCMJOB_ALL_NUMBERS; // parameter passed to job::find method
260           
261             // Construct a ycmJob object
262             ycmJob cppJob(YCMJOB_SRVNAME_10, YCMJOB_SRVUSER_10);
263           
264             // Find the QYCMCIMOM job
265             char cppStatus  = cppJob.find(number);
266           
267             if (cppStatus == YCMJOB_FOUND)       // CIMOM Server is Running
268             {
269                 return true; 
270             }
271           
272             return false;
273           }
274           

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2