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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2