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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2