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

   1 karl  1.179 //%2006////////////////////////////////////////////////////////////////////////
   2 mike  1.32  //
   3 karl  1.141 // 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.121 // IBM Corp.; EMC Corporation, The Open Group.
   7 karl  1.141 // 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.149 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11 karl  1.179 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  12             // EMC Corporation; Symantec Corporation; The Open Group.
  13 mike  1.32  //
  14             // Permission is hereby granted, free of charge, to any person obtaining a copy
  15 kumpf 1.58  // of this software and associated documentation files (the "Software"), to
  16             // deal in the Software without restriction, including without limitation the
  17             // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  18 mike  1.32  // sell copies of the Software, and to permit persons to whom the Software is
  19             // furnished to do so, subject to the following conditions:
  20 karl  1.179 // 
  21 kumpf 1.58  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  22 mike  1.32  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  23             // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  24 kumpf 1.58  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  25             // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  26             // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27 mike  1.32  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28             // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29             //
  30             //==============================================================================
  31             //
  32             //%/////////////////////////////////////////////////////////////////////////////
  33             
  34             
  35             //////////////////////////////////////////////////////////////////////
  36             //
  37 carolann.graves 1.171 // Notes on daemon operation (Unix) and service operation (Win 32):
  38 mike            1.32  //
  39 david.dillard   1.165 // To run pegasus as a daemon on Unix platforms:
  40 mike            1.32  //
  41 kumpf           1.60  // cimserver
  42 mike            1.32  //
  43 kumpf           1.60  // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
  44                       // property to false:
  45                       //
  46                       // cimserver daemon=false
  47                       //
  48 david.dillard   1.165 // The daemon config property has no effect on windows operation.
  49 mike            1.32  //
  50 mike            1.35  // To shutdown pegasus, use the -s option:
  51 david.dillard   1.165 //
  52                       // cimserver -s
  53 mike            1.35  //
  54 mike            1.32  // To run pegasus as an NT service, there are FOUR  different possibilities:
  55                       //
  56 david.dillard   1.165 // To INSTALL the Pegasus service,
  57 mike            1.32  //
  58                       // cimserver -install
  59                       //
  60 david.dillard   1.165 // To REMOVE the Pegasus service,
  61 mike            1.32  //
  62                       // cimserver -remove
  63                       //
  64 david.dillard   1.165 // To START the Pegasus service,
  65 mike            1.32  //
  66                       // net start cimserver
  67 s.hills         1.117 // or
  68                       // cimserver -start
  69 mike            1.32  //
  70 david.dillard   1.165 // To STOP the Pegasus service,
  71 mike            1.32  //
  72                       // net stop cimserver
  73 s.hills         1.117 // or
  74                       // cimserver -stop
  75 mike            1.32  //
  76 david.dillard   1.165 // Alternatively, you can use the windows service manager. Pegasus shows up
  77 mike            1.32  // in the service database as "Pegasus CIM Object Manager"
  78                       //
  79                       // Mike Day, mdday@us.ibm.com
  80 david.dillard   1.165 //
  81 mike            1.32  //////////////////////////////////////////////////////////////////////
  82                       
  83                       
  84 mike            1.35  #include <Pegasus/Common/Config.h>
  85 kumpf           1.59  #include <Pegasus/Common/Constants.h>
  86 jim.wunderlich  1.172 #include <Pegasus/Common/PegasusAssert.h>
  87 mike            1.32  #include <cstdlib>
  88                       #include <Pegasus/Common/FileSystem.h>
  89 mike            1.35  #include <Pegasus/Common/Monitor.h>
  90 mike            1.32  #include <Pegasus/Common/PegasusVersion.h>
  91                       #include <Pegasus/Common/Logger.h>
  92                       #include <Pegasus/Common/System.h>
  93 mike            1.35  #include <Pegasus/Common/Tracer.h>
  94 kumpf           1.174 #include <Pegasus/Common/LanguageParser.h>
  95 mike            1.35  #include <Pegasus/Config/ConfigManager.h>
  96                       #include <Pegasus/Client/CIMClient.h>
  97                       #include <Pegasus/Server/ShutdownService.h>
  98 h.sterling      1.153 #include <Pegasus/Server/CIMServer.h>
  99                       #include <Service/ServerProcess.h>
 100 mike            1.32  
 101 chuck           1.155 #if defined(PEGASUS_OS_OS400)
 102                       #  include "vfyptrs.cinc"
 103                       #  include "OS400ConvertChar.h"
 104                       #endif
 105                       
 106 thilo.boehm     1.185 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) 
 107                       #include <Service/ARM_zOS.h>
 108 marek           1.186 # ifdef PEGASUS_ZOS_SECURITY
 109                       // This include file will not be provided in the OpenGroup CVS for now.
 110                       // Do NOT try to include it in your compile
 111                       #  include <Pegasus/Common/safCheckzOS_inline.h>
 112                       # endif
 113 thilo.boehm     1.185 #endif
 114                       
 115 kumpf           1.178 #if defined(PEGASUS_OS_TYPE_UNIX)
 116                       # if defined(PEGASUS_OS_OS400)
 117 mateus.baur     1.175 #  include <unistd.cleinc>
 118 kumpf           1.178 # else
 119 mateus.baur     1.175 #  include <unistd.h>
 120 kumpf           1.178 # endif
 121                       # include <sys/types.h>
 122                       # include <sys/stat.h>
 123                       # include <fcntl.h>
 124 mateus.baur     1.175 #endif
 125                       
 126 mike            1.191.2.2 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 127 mike            1.191.2.7 # define PEGASUS_PROCESS_NAME "cimservermain"
 128 mike            1.191.2.2 #else
 129 mike            1.191.2.7 # define PEGASUS_PROCESS_NAME "cimserver"
 130 mike            1.191.2.2 #endif
 131 mike            1.32      
 132 mike            1.191.2.15 #include <Pegasus/Common/Executor.h>
 133                            
 134 mike            1.191.2.5  PEGASUS_USING_PEGASUS;
 135                            PEGASUS_USING_STD;
 136                            
 137 h.sterling      1.153      //Windows service variables are not defined elsewhere in the product
 138                            //enable ability to override these
 139                            #ifndef PEGASUS_SERVICE_NAME
 140                            #define PEGASUS_SERVICE_NAME "Pegasus CIM Object Manager";
 141 chuck           1.66       #endif
 142 h.sterling      1.153      #ifndef PEGASUS_SERVICE_DESCRIPTION
 143                            #define PEGASUS_SERVICE_DESCRIPTION "Pegasus CIM Object Manager Service";
 144 mike            1.32       #endif
 145                            
 146 h.sterling      1.153      class CIMServerProcess : public ServerProcess
 147                            {
 148                            public:
 149                            
 150                                CIMServerProcess(void)
 151                                {
 152                                    cimserver_set_process(this);
 153                                }
 154                            
 155                                virtual ~CIMServerProcess(void)
 156                                {
 157                                }
 158                            
 159                                //defined in PegasusVersion.h
 160                                virtual const char* getProductName() const
 161                                {
 162                                    return PEGASUS_PRODUCT_NAME;
 163                                }
 164                            
 165                                virtual const char* getExtendedName() const
 166                                {
 167 h.sterling      1.153              return PEGASUS_SERVICE_NAME;
 168                                }
 169                            
 170                                virtual const char* getDescription() const
 171                                {
 172                                    return PEGASUS_SERVICE_DESCRIPTION;
 173                                }
 174 david.dillard   1.165      
 175 h.sterling      1.153          //defined in PegasusVersion.h
 176 jim.wunderlich  1.180          virtual const char* getCompleteVersion() const
 177                                {
 178 jim.wunderlich  1.181            if (*PEGASUS_PRODUCT_STATUS == '\0' )
 179 jim.wunderlich  1.180      	return PEGASUS_PRODUCT_VERSION;
 180                                  else
 181                            	return PEGASUS_PRODUCT_VERSION " " PEGASUS_PRODUCT_STATUS;      
 182                                }
 183                            
 184                                //defined in PegasusVersion.h
 185 h.sterling      1.153          virtual const char* getVersion() const
 186                                {
 187                                    return PEGASUS_PRODUCT_VERSION;
 188                                }
 189                            
 190                                virtual const char* getProcessName() const
 191                                {
 192                                    return PEGASUS_PROCESS_NAME;
 193                                }
 194                            
 195 kumpf           1.184          //defined in Constants.h
 196 h.sterling      1.153          virtual const char* getPIDFileName() const
 197                                {
 198 kumpf           1.184              return PEGASUS_CIMSERVER_START_FILE;
 199 h.sterling      1.153          }
 200                            
 201 kumpf           1.178          int cimserver_run(
 202                                    int argc,
 203                                    char** argv,
 204                                    Boolean shutdownOption,
 205                                    Boolean debugOutputOption);
 206 h.sterling      1.153      
 207                                void cimserver_stop(void);
 208                            };
 209                            
 210                            AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
 211                            static CIMServer* _cimServer = 0;
 212 konrad.r        1.163      static Monitor* _monitor = 0;
 213 konrad.r        1.166      static Thread* dummyInitialThread = 0;
 214 mike            1.35       //
 215                            //  The command name.
 216                            //
 217                            static const char COMMAND_NAME []    = "cimserver";
 218                            
 219                            //
 220                            //  The constant defining usage string.
 221                            //
 222                            static const char USAGE []           = "Usage: ";
 223                            
 224                            /**
 225                            Constants representing the command line options.
 226                            */
 227                            static const char OPTION_VERSION     = 'v';
 228                            
 229                            static const char OPTION_HELP        = 'h';
 230                            
 231                            static const char OPTION_HOME        = 'D';
 232                            
 233                            static const char OPTION_SHUTDOWN    = 's';
 234                            
 235 a.arora         1.142      static const char   LONG_HELP []  = "help";
 236                            
 237                            static const char   LONG_VERSION []  = "version";
 238                            
 239 kumpf           1.178      static const char OPTION_DEBUGOUTPUT = 'X';
 240 kumpf           1.48       
 241 kumpf           1.54       static const String PROPERTY_TIMEOUT = "shutdownTimeout";
 242 mike            1.35       
 243                            ConfigManager*    configManager;
 244                            
 245 mike            1.32       /** GetOptions function - This function defines the Options Table
 246 mike            1.35           and sets up the options from that table using the config manager.
 247 mike            1.32       */
 248                            void GetOptions(
 249 mike            1.35           ConfigManager* cm,
 250 mike            1.32           int& argc,
 251 s.hills         1.117          char** argv)
 252 mike            1.32       {
 253 mike            1.35           try
 254 mike            1.32           {
 255 kumpf           1.38               cm->mergeConfigFiles();
 256 mike            1.33       
 257 mike            1.35               cm->mergeCommandLine(argc, argv);
 258                                }
 259 kumpf           1.122          catch (NoSuchFile&)
 260 mike            1.35           {
 261 kumpf           1.122              throw;
 262 mike            1.35           }
 263 kumpf           1.122          catch (FileNotReadable&)
 264 mike            1.35           {
 265 kumpf           1.122              throw;
 266 mike            1.35           }
 267 kumpf           1.122          catch (CannotRenameFile&)
 268 mike            1.35           {
 269 kumpf           1.122              throw;
 270 mike            1.35           }
 271 kumpf           1.122          catch (ConfigFileSyntaxError&)
 272 mike            1.35           {
 273 kumpf           1.122              throw;
 274 mike            1.35           }
 275 kumpf           1.122          catch(UnrecognizedConfigProperty&)
 276 mike            1.35           {
 277 kumpf           1.122              throw;
 278 mike            1.35           }
 279 kumpf           1.122          catch(InvalidPropertyValue&)
 280 mike            1.35           {
 281 kumpf           1.122              throw;
 282 mike            1.35           }
 283 kumpf           1.123          catch (CannotOpenFile&)
 284                                {
 285                                    throw;
 286                                }
 287 mike            1.32       }
 288                            
 289                            /* PrintHelp - This is temporary until we expand the options manager to allow
 290                               options help to be defined with the OptionRow entries and presented from
 291                               those entries.
 292                            */
 293                            void PrintHelp(const char* arg0)
 294                            {
 295 mike            1.35           String usage = String (USAGE);
 296                                usage.append (COMMAND_NAME);
 297                                usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
 298                                usage.append ("  options\n");
 299 a.arora         1.142          usage.append ("    -v, --version   - displays CIM Server version number\n");
 300                                usage.append ("    -h, --help      - prints this help message\n");
 301 humberto        1.97           usage.append ("    -s              - shuts down CIM Server\n");
 302 kumpf           1.138      #if !defined(PEGASUS_USE_RELEASE_DIRS)
 303                                usage.append ("    -D [home]       - sets pegasus home directory\n");
 304 humberto        1.97       #endif
 305                            #if defined(PEGASUS_OS_TYPE_WINDOWS)
 306 joyce.j         1.148          usage.append ("    -install [name] - installs pegasus as a Windows Service\n");
 307 humberto        1.97           usage.append ("                      [name] is optional and overrides the\n");
 308                                usage.append ("                      default CIM Server Service Name\n");
 309 aruran.ms       1.183          usage.append ("                      by appending [name]\n");
 310 joyce.j         1.148          usage.append ("    -remove [name]  - removes pegasus as a Windows Service\n");
 311 humberto        1.97           usage.append ("                      [name] is optional and overrides the\n");
 312                                usage.append ("                      default CIM Server Service Name\n");
 313 aruran.ms       1.183          usage.append ("                      by appending [name]\n");
 314 joyce.j         1.148          usage.append ("    -start [name]   - starts pegasus as a Windows Service\n");
 315 humberto        1.97           usage.append ("                      [name] is optional and overrides the\n");
 316                                usage.append ("                      default CIM Server Service Name\n");
 317 aruran.ms       1.183          usage.append ("                      by appending [name]\n");
 318 joyce.j         1.148          usage.append ("    -stop [name]    - stops pegasus as a Windows Service\n");
 319 humberto        1.97           usage.append ("                      [name] is optional and overrides the\n");
 320 aruran.ms       1.183          usage.append ("                      default CIM Server Service Name\n");
 321                                usage.append ("                      by appending [name]\n\n");
 322 humberto        1.97       #endif
 323                                usage.append ("  configProperty=value\n");
 324                                usage.append ("                    - sets CIM Server configuration property\n");
 325                            
 326                                cout << endl;
 327 jim.wunderlich  1.180          cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getCompleteVersion() << endl;
 328 humberto        1.97           cout << endl;
 329 david.dillard   1.165      
 330 humberto        1.97       #if defined(PEGASUS_OS_TYPE_WINDOWS)
 331 humberto        1.104          MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
 332 kumpf           1.152      #elif defined(PEGASUS_USE_RELEASE_DIRS)
 333 kumpf           1.138          MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
 334 humberto        1.97       #else
 335 kumpf           1.138          MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
 336 humberto        1.97       #endif
 337                                cout << MessageLoader::getMessage(parms) << endl;
 338 mike            1.35       }
 339                            
 340 h.sterling      1.156      //This needs to be called at various points in the code depending on the platform and error conditions.
 341                            //We need to delete the _cimServer reference on exit in order for the destructors to get called.
 342                            void deleteCIMServer()
 343                            {
 344                                if (_cimServer)
 345                                {
 346                                    delete _cimServer;
 347                                    _cimServer = 0;
 348 carolann.graves 1.171      
 349                            #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) \
 350                            || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
 351                            || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
 352                                    //
 353                                    //  Remove the PID file to indicate CIMServer termination
 354                                    //
 355                                    FileSystem::removeFile(_cimServerProcess->getPIDFileName());
 356                            #endif
 357 h.sterling      1.156          }
 358 kumpf           1.182          delete _monitor;
 359 konrad.r        1.166         if (dummyInitialThread)
 360                               {
 361                            	Thread::clearLanguages();
 362                            	delete dummyInitialThread;
 363                               }
 364 h.sterling      1.156      }
 365                            
 366 chuck           1.96       // l10n
 367                            //
 368                            // Dummy function for the Thread object associated with the initial thread.
 369                            // Since the initial thread is used to process CIM requests, this is
 370                            // needed to localize the exceptions thrown during CIM request processing.
 371 david.dillard   1.165      // Note: This function should never be called!
 372                            //
 373 mike            1.188      ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
 374 chuck           1.96       {
 375 mike            1.188         return((ThreadReturnType)0);
 376 chuck           1.96       }
 377                            
 378 carolann.graves 1.171      //
 379                            //  Waits until either the CIM Server has terminated, or the shutdown timeout
 380                            //  has expired.  If the shutdown timeout has expired, and the CIM Server is
 381                            //  still running, kills the cimserver process.
 382                            //
 383                            void _waitForTerminationOrTimeout (Uint32 maxWaitTime)
 384                            {
 385                                //
 386                                //  If the CIM Server is still running, and the shutdown timeout has not
 387                                //  expired, loop and wait one second until either the CIM Server has
 388                                //  terminated, or the shutdown timeout has expired
 389                                //
 390                                Boolean running = _cimServerProcess->isCIMServerRunning ();
 391                                while (running && (maxWaitTime > 0))
 392                                {
 393                                    System::sleep (1);
 394                                    running = _cimServerProcess->isCIMServerRunning ();
 395                                    maxWaitTime--;
 396                                }
 397                            
 398                                //
 399 carolann.graves 1.171          //  If the shutdown timeout has expired, and the CIM Server is still
 400                                //  running, kill the cimserver process
 401                                //
 402                                if (running)
 403                                {
 404                                    int kill_rc = _cimServerProcess->cimserver_kill (0);
 405                            
 406                            #ifdef PEGASUS_OS_OS400
 407                                    if (kill_rc == -1)
 408                                    {
 409                                        _cimServerProcess->cimserver_exitRC (2);
 410                                    }
 411                                    _cimServerProcess->cimserver_exitRC (1);
 412                            #endif
 413                            
 414                            #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
 415                            || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_SOLARIS) \
 416                            || defined (PEGASUS_OS_VMS)
 417                                    if (kill_rc != -1)
 418                                    {
 419                                        //l10n - TODO
 420 carolann.graves 1.171                  Logger::put_l (Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 421                                            "src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 422                                            "Shutdown timeout expired.  Forced shutdown initiated.");
 423                                        MessageLoaderParms parms
 424                                            ("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 425                                            "Shutdown timeout expired.  Forced shutdown initiated.");
 426                                        cout << MessageLoader::getMessage(parms) << endl;
 427                                        exit (0);
 428                                    }
 429                            #endif
 430                                }
 431                            }
 432                            
 433 kumpf           1.52       void shutdownCIMOM(Uint32 timeoutValue)
 434 mike            1.35       {
 435                                //
 436                                // Create CIMClient object
 437                                //
 438 kumpf           1.42           CIMClient client;
 439 mike            1.35       
 440                                //
 441 kumpf           1.53           // Get local host name
 442 mike            1.35           //
 443                                String hostStr = System::getHostName();
 444                            
 445                                //
 446 david.dillard   1.165          // open connection to CIMOM
 447 mike            1.35           //
 448                                try
 449                                {
 450 kumpf           1.43               client.connectLocal();
 451 kumpf           1.52       
 452                                    //
 453 kumpf           1.63               // set client timeout to 2 seconds
 454 kumpf           1.52               //
 455 kumpf           1.71               client.setTimeout(2000);
 456 mike            1.35           }
 457 s.hills         1.117          catch(Exception&)
 458 mike            1.35           {
 459 david           1.85       #ifdef PEGASUS_OS_OS400
 460 h.sterling      1.153          //l10n
 461                                //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 462                                        //"Unable to connect to CIM Server.  CIM Server may not be running." );
 463                                Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 464                                        "src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
 465                                        "Unable to connect to CIM Server.  CIM Server may not be running." );
 466                                // The server job may still be active but not responding.
 467                                // Kill the job if it exists.
 468                                if(_cimServerProcess->cimserver_kill(0) == -1)
 469                                   _cimServerProcess->cimserver_exitRC(2);
 470                                _cimServerProcess->cimserver_exitRC(1);
 471 david           1.85       #else
 472 humberto        1.97               //l10n
 473                                    //PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
 474                                    //PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
 475                                    MessageLoaderParms parms("src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
 476 kumpf           1.105                                                               "Unable to connect to CIM Server.\nCIM Server may not be running.\n");
 477 humberto        1.97               PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
 478 s.hills         1.117              exit(1);
 479 chuck           1.66       #endif
 480 mike            1.35           }
 481                            
 482                                try
 483                                {
 484                                    //
 485 kumpf           1.52               // construct CIMObjectPath
 486 mike            1.35               //
 487                                    String referenceStr = "//";
 488                                    referenceStr.append(hostStr);
 489 david.dillard   1.165              referenceStr.append("/");
 490 kumpf           1.72               referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
 491 kumpf           1.53               referenceStr.append(":");
 492 kumpf           1.72               referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
 493 kumpf           1.50               CIMObjectPath reference(referenceStr);
 494 mike            1.35       
 495                                    //
 496                                    // issue the invokeMethod request on the shutdown method
 497                                    //
 498                                    Array<CIMParamValue> inParams;
 499                                    Array<CIMParamValue> outParams;
 500                            
 501 kumpf           1.52               // set force option to true for now
 502 kumpf           1.40               inParams.append(CIMParamValue("force",
 503 kumpf           1.52                   CIMValue(Boolean(true))));
 504 mike            1.35       
 505 kumpf           1.40               inParams.append(CIMParamValue("timeout",
 506 kumpf           1.39                   CIMValue(Uint32(timeoutValue))));
 507 mike            1.35       
 508                                    CIMValue retValue = client.invokeMethod(
 509 kumpf           1.59                   PEGASUS_NAMESPACENAME_SHUTDOWN,
 510 mike            1.35                   reference,
 511                                        "shutdown",
 512                                        inParams,
 513                                        outParams);
 514 kumpf           1.43           }
 515 kumpf           1.65           catch(CIMException& e)
 516 kumpf           1.46           {
 517 david           1.85       #ifdef PEGASUS_OS_OS400
 518                            
 519 h.sterling      1.153          if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 520                                {
 521                                    //l10n
 522                                    //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 523                                        //"Failed to shutdown server: $0", "The repository may be empty.");
 524                                    Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 525                                        "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
 526                                        "Error in server shutdown: The repository may be empty.");
 527                                }
 528                                else
 529                                {
 530                                    //l10n
 531                                    //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 532                                        //"Failed to shutdown server: $0", e.getMessage());
 533                                    Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 534                                        "src.Server.cimserver.SHUTDOWN_FAILED",
 535                                        "Error in server shutdown: $0", e.getMessage());
 536                                }
 537                                // Kill the server job.
 538                                if(_cimServerProcess->cimserver_kill(0) == -1)
 539                                   _cimServerProcess->cimserver_exitRC(2);
 540 david           1.85       #else
 541 kumpf           1.105              //l10n - TODO
 542 humberto        1.97               MessageLoaderParms parms("src.Server.cimserver.SHUTDOWN_FAILED",
 543 kumpf           1.105                                       "Error in server shutdown: ");
 544 humberto        1.97               PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
 545 kumpf           1.63               if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 546                                    {
 547 kumpf           1.105                  //
 548 david.dillard   1.165                  // Repository may be empty.
 549 kumpf           1.105                  //
 550                                        //l10n - TODO
 551                                        Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 552                                            "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
 553                                            "Error in server shutdown: The repository may be empty.");
 554 humberto        1.97                   MessageLoaderParms parms("src.Server.cimserver.REPOSITORY_EMPTY",
 555 kumpf           1.105                                           "The repository may be empty.");
 556                                        PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
 557 kumpf           1.63               }
 558                                    else
 559                                    {
 560 kumpf           1.105                  //l10n - TODO
 561                                        Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 562                                            "src.Server.cimserver.SHUTDOWN_FAILED",
 563                                            "Error in server shutdown: $0", e.getMessage());
 564 kumpf           1.63                   PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
 565                                    }
 566 kumpf           1.105      
 567 david.dillard   1.165          // Kill the cimserver process
 568 h.sterling      1.153          if (_cimServerProcess->cimserver_kill(0) == 0)
 569 kumpf           1.105              {
 570                                        //l10n - TODO
 571                                        Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 572                                            "src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
 573 h.sterling      1.153                  "Forced shutdown initiated.");
 574 kumpf           1.105                  MessageLoaderParms parms("src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
 575                                                                 "Forced shutdown initiated.");
 576                                        PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
 577                                    }
 578 s.hills         1.117              exit(1);
 579 chuck           1.66       #endif
 580 kumpf           1.46           }
 581 mike            1.191.2.6      catch(Exception& e)
 582 kumpf           1.45           {
 583 mike            1.191.2.6          cerr << "Shutdown failed: " << e.getMessage() << endl;
 584 kumpf           1.45               //
 585 kumpf           1.91               // This may mean that the CIM Server has terminated, causing this
 586                                    // client to get a "Empty HTTP response message" exception.  It may
 587 david.dillard   1.165              // also mean that the CIM Server is taking longer than 2 seconds
 588                                    // (client timeout value) to terminate, causing this client to
 589 kumpf           1.91               // timeout with a "connection timeout" exception.
 590 kumpf           1.45               //
 591 carolann.graves 1.171              //  Wait until either the CIM Server has terminated, or the shutdown
 592                                    //  timeout has expired.  If the timeout has expired and the CIM Server
 593                                    //  is still running, kill the cimserver process.
 594                                    //
 595                                    _waitForTerminationOrTimeout (timeoutValue - 2);
 596 kumpf           1.168          }
 597                            
 598 carolann.graves 1.171          //
 599                                //  InvokeMethod succeeded.
 600                                //  Wait until either the CIM Server has terminated, or the shutdown
 601                                //  timeout has expired.  If the timeout has expired and the CIM Server
 602                                //  is still running, kill the cimserver process.
 603                                //
 604                                _waitForTerminationOrTimeout (timeoutValue);
 605 mike            1.35           return;
 606 mike            1.32       }
 607                            
 608 mike            1.191.2.1  #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 609                            
 610 mike            1.191.2.10 static int _extractExecutorSockOpt(int& argc, char**& argv)
 611 mike            1.191.2.1  {
 612 mike            1.191.2.6      // Extract the "-x <sock>" option if any. This indicates that the
 613                                // e[x]ecutor is running. The option argument is the socket used
 614                                // to communicate with the executor. Remove the option from the
 615                                // argv list and decrease argc by two.
 616                            
 617                                int sock = -1;
 618                            
 619                                for (int i = 1; i < argc; i++)
 620 mike            1.191.2.1      {
 621 mike            1.191.2.6          if (strcmp(argv[i], "-x") == 0)
 622                                    {
 623                                        // Check for missing option argument.
 624                            
 625                                        if (i + 1 == argc)
 626                                        {
 627                                            fprintf(stderr, 
 628                                                "%s: missing option argument for -x\n", argv[0]);
 629                                            exit(1);
 630                                        }
 631                            
 632                                        // Convert argument to integer.
 633                            
 634                                        char* end;
 635                                        unsigned long x = strtoul(argv[i+1], &end, 10);
 636                            
 637                                        // Check whether option argument will fit in integer.
 638                            
 639                                        if (*end != '\0' || x > 2147483647)
 640                                        {
 641                                            fprintf(stderr, 
 642 mike            1.191.2.6                      "%s: bad -x option argument: %s\n", argv[0], argv[i+1]);
 643                                            exit(1);
 644                                        }
 645                            
 646                                        sock = int(x);
 647                            
 648                                        // Remove "-x <sock>" from argv-argc.
 649                            
 650                                        memmove(argv + i, argv + i + 2, sizeof(char*) * (argc - i - 1));
 651                                        argc -= 2;
 652                                        break;
 653                                    }
 654 mike            1.191.2.1      }
 655 mike            1.191.2.6  
 656                                return sock;
 657 mike            1.191.2.1  }
 658                            
 659                            #endif /* PEGASUS_ENABLE_PRIVILEGE_SEPARATION */
 660 mike            1.35       
 661 mike            1.33       /////////////////////////////////////////////////////////////////////////
 662 mike            1.32       //  MAIN
 663                            //////////////////////////////////////////////////////////////////////////
 664 mike            1.191.2.6  
 665 mike            1.32       int main(int argc, char** argv)
 666                            {
 667 mike            1.191.2.1  #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 668 mike            1.191.2.6  
 669 mike            1.191.2.13     // If invoked with "-x <socket>" option, then use executor.
 670 mike            1.191.2.8  
 671 mike            1.191.2.14     Executor::setSock(_extractExecutorSockOpt(argc, argv));
 672 mike            1.191.2.8  
 673 mike            1.191.2.14 #endif /* !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) */
 674 mike            1.191.2.6  
 675                                // Ping executor to be sure the sock was valid.
 676                            
 677 mike            1.191.2.9      if (Executor::ping() != 0)
 678 mike            1.191.2.6      {
 679                                    fprintf(stderr, 
 680                                        "%s: failed to ping executor on socket given by -x option\n", 
 681                                        argv[0]);
 682                                    exit(1);
 683                                }
 684                            
 685 mike            1.35           String pegasusHome  = String::EMPTY;
 686                                Boolean shutdownOption = false;
 687 kumpf           1.178          Boolean debugOutputOption = false;
 688 mday            1.47       
 689 humberto        1.97       //l10n
 690                            // Set Message loading to process locale
 691 david.dillard   1.165      MessageLoader::_useProcessLocale = true;
 692 humberto        1.97       //l10n
 693                            
 694 kv.le           1.140      //l10n
 695                            #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
 696                            setlocale(LC_ALL, "");
 697                            #endif
 698                            
 699 chuck           1.66       #ifdef PEGASUS_OS_OS400
 700 david           1.120      
 701                              VFYPTRS_INCDCL;               // VFYPTRS local variables
 702                            
 703                              // verify pointers
 704                              #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\
 705                                0,_C2_MH_ESCAPE)
 706                                for( int arg_index = 1; arg_index < argc; arg_index++ ){
 707 h.sterling      1.153          VFYPTRS(VERIFY_SPP_NULL(argv[arg_index]));
 708 david           1.120          }
 709                              #pragma disable_handler
 710                            
 711 david           1.100          // Convert the args to ASCII
 712                                for(Uint32 i = 0;i< argc;++i)
 713                                {
 714 h.sterling      1.153          EtoA(argv[i]);
 715 david           1.100          }
 716                            
 717 chuck           1.66           // Initialize Pegasus home to the shipped OS/400 directory.
 718                                pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 719                            #endif
 720                            
 721 kv.le           1.134      
 722 tony            1.82       #ifndef PEGASUS_OS_TYPE_WINDOWS
 723 kumpf           1.38           //
 724                                // Get environment variables:
 725                                //
 726 david           1.100      #ifdef PEGASUS_OS_OS400
 727                            #pragma convert(37)
 728                                const char* tmp = getenv("PEGASUS_HOME");
 729                            #pragma convert(0)
 730                                char home[256] = {0};
 731                                if (tmp && strlen(tmp) < 256)
 732                                {
 733 h.sterling      1.153          strcpy(home, tmp);
 734                                EtoA(home);
 735                                pegasusHome = home;
 736 david           1.100          }
 737                            #else
 738 kv.le           1.134        #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
 739                                pegasusHome = AIX_RELEASE_PEGASUS_HOME;
 740 marek           1.170        #elif !defined(PEGASUS_USE_RELEASE_DIRS) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 741 kumpf           1.38           const char* tmp = getenv("PEGASUS_HOME");
 742                            
 743                                if (tmp)
 744                                {
 745                                    pegasusHome = tmp;
 746                                }
 747 kv.le           1.134        #endif
 748 david           1.100      #endif
 749 kumpf           1.38       
 750                                FileSystem::translateSlashes(pegasusHome);
 751 tony            1.82       #else
 752 kumpf           1.38       
 753 tony            1.82         // windows only
 754 h.sterling      1.153        //setHome(pegasusHome);
 755                              pegasusHome = _cimServerProcess->getHome();
 756 tony            1.82       #endif
 757 mike            1.32       
 758 kumpf           1.60               // Get help, version, and shutdown options
 759 mike            1.35       
 760                                    for (int i = 1; i < argc; )
 761                                    {
 762                                        const char* arg = argv[i];
 763 a.arora         1.142                  if(String::equal(arg,"--help"))
 764                                        {
 765                                                PrintHelp(argv[0]);
 766                                                exit(0);
 767                                        }
 768                                        else if(String::equal(arg,"--version"))
 769                                        {
 770 jim.wunderlich  1.180                      cout << _cimServerProcess->getCompleteVersion() << endl;
 771 a.arora         1.142                      exit(0);
 772                                        }
 773 mike            1.35                   // Check for -option
 774 a.arora         1.142                  else if (*arg == '-')
 775 mike            1.35                   {
 776                                            // Get the option
 777                                            const char* option = arg + 1;
 778                            
 779                                            //
 780                                            // Check to see if user asked for the version (-v option):
 781                                            //
 782 tony            1.83                       if (*option == OPTION_VERSION &&
 783                                                strlen(option) == 1)
 784 mike            1.35                       {
 785 jim.wunderlich  1.180                          cout << _cimServerProcess->getCompleteVersion() << endl;
 786 mike            1.35                           exit(0);
 787                                            }
 788                                            //
 789                                            // Check to see if user asked for help (-h option):
 790                                            //
 791 tony            1.83                       else if (*option == OPTION_HELP &&
 792                                                    (strlen(option) == 1))
 793 mike            1.35                       {
 794                                                PrintHelp(argv[0]);
 795                                                exit(0);
 796                                            }
 797 kumpf           1.138      #if !defined(PEGASUS_USE_RELEASE_DIRS)
 798 tony            1.83                       else if (*option == OPTION_HOME &&
 799                                                    (strlen(option) == 1))
 800 mike            1.35                       {
 801 kumpf           1.60                           if (i + 1 < argc)
 802 mike            1.35                           {
 803                                                    pegasusHome.assign(argv[i + 1]);
 804                                                }
 805                                                else
 806                                                {
 807 humberto        1.97                               //l10n
 808                                                    //cout << "Missing argument for option -" << option << endl;
 809 humberto        1.99                               String opt(option);
 810 humberto        1.97                               MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
 811 h.sterling      1.153                                               "Missing argument for option -$0",
 812                                                                     opt);
 813                                                    cout << MessageLoader::getMessage(parms) << endl;
 814 mike            1.35                               exit(0);
 815                                                }
 816                            
 817                                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 818                                                argc -= 2;
 819                                            }
 820 kumpf           1.63       #endif
 821 kumpf           1.48                       //
 822 kumpf           1.178                      // Check to see if user asked for debug output (-X option):
 823 kumpf           1.48                       //
 824 kumpf           1.178                      else if (*option == OPTION_DEBUGOUTPUT &&
 825 tony            1.83                               (strlen(option) == 1))
 826 kumpf           1.48                       {
 827 kumpf           1.178                          MessageLoaderParms parms(
 828                                                    "src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 829                                                    "Unsupported debug output option is enabled.");
 830 h.sterling      1.153                          cout << MessageLoader::getMessage(parms) << endl;
 831 kumpf           1.178      
 832                                                debugOutputOption = true;
 833                            
 834                            #if defined(PEGASUS_OS_HPUX)
 835                                                System::bindVerbose = true;
 836                            #endif
 837                            
 838 kumpf           1.48                           // remove the option from the command line
 839                                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 840 david.dillard   1.165                          argc--;
 841 kumpf           1.48                       }
 842 mike            1.35                       //
 843                                            // Check to see if user asked for shutdown (-s option):
 844                                            //
 845 tony            1.82                       else if (*option == OPTION_SHUTDOWN &&
 846                                                    (strlen(option) == 1))
 847 mike            1.35                       {
 848                                                //
 849 kumpf           1.52                           // Check to see if shutdown has already been specified:
 850 mike            1.35                           //
 851 kumpf           1.52                           if (shutdownOption)
 852 mike            1.35                           {
 853 humberto        1.97                               //l10n
 854                                                    //cout << "Duplicate shutdown option specified." << endl;
 855                                                    MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 856 h.sterling      1.153                                                       "Duplicate shutdown option specified.");
 857 david.dillard   1.165      
 858 humberto        1.97                               cout << MessageLoader::getMessage(parms) << endl;
 859 mike            1.35                               exit(0);
 860                                                }
 861                            
 862 kumpf           1.52                           shutdownOption = true;
 863 david.dillard   1.165      
 864 mike            1.35                           // remove the option from the command line
 865                                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 866 david.dillard   1.165                          argc--;
 867 mike            1.35                       }
 868                                            else
 869                                                i++;
 870                                        }
 871                                        else
 872                                            i++;
 873 mike            1.32               }
 874 mike            1.35       
 875 kumpf           1.38           //
 876                                // Set the value for pegasusHome property
 877                                //
 878                                ConfigManager::setPegasusHome(pegasusHome);
 879 mike            1.32       
 880 mike            1.35           //
 881 carolann.graves 1.171          // Do the platform specific run
 882 s.hills         1.117          //
 883                            
 884 kumpf           1.178          return _cimServerProcess->platform_run(
 885                                    argc, argv, shutdownOption, debugOutputOption);
 886 s.hills         1.117      }
 887                            
 888 h.sterling      1.153      void CIMServerProcess::cimserver_stop()
 889                            {
 890                                _cimServer->shutdownSignal();
 891                            }
 892 s.hills         1.117      
 893                            //
 894                            // The main, common, running code
 895                            //
 896 david.dillard   1.165      // NOTE: Do NOT call exit().  Use return(), otherwise some platforms
 897 s.hills         1.117      // will fail to shutdown properly/cleanly.
 898                            //
 899 david.dillard   1.165      // TODO: Current change minimal for platform "service" shutdown bug fixes.
 900 carolann.graves 1.171      // Perhaps further extract out common stuff and put into main(), put
 901 david.dillard   1.165      // daemon stuff into platform specific platform_run(), etc.
 902                            // Note: make sure to not put error handling stuff that platform
 903 carolann.graves 1.171      // specific runs may need to deal with better (instead of exit(), etc).
 904 s.hills         1.117      //
 905                            
 906 kumpf           1.178      int CIMServerProcess::cimserver_run(
 907                                int argc,
 908                                char** argv,
 909                                Boolean shutdownOption,
 910                                Boolean debugOutputOption)
 911 s.hills         1.117      {
 912                                String logsDirectory = String::EMPTY;
 913                                Boolean daemonOption = false;
 914                            
 915                                //
 916 mike            1.35           // Get an instance of the Config Manager.
 917                                //
 918                                configManager = ConfigManager::getInstance();
 919 kumpf           1.136          configManager->useConfigFiles = true;
 920 mike            1.35       
 921 lucier          1.130      #ifdef PEGASUS_OS_OS400
 922                                // In a special startup case for IBM OS400, when the server is
 923                                // automatically started when the machine starts up the config
 924                                // file cannot be read because of access restrictions for the
 925                                // user starting the server.  In this case, we need to skip
 926                                // reading the config options and therefore any use of the config
 927                                // manager also.  To make this determinations we will check to see
 928                                // if the daemon flag is set to true.  If so, then there will be a
 929                                // series of checks to bracket all the calls to the configManager
 930                                // which would otherwise fail.  All this will only be done for
 931                                // IBM OS400.
 932                            
 933                                Boolean os400StartupOption = false;
 934                                // loop through args to check for daemon=true
 935                                for (int i=1; i < argc; i++)
 936                                  if (strcmp(argv[i], "daemon=true") == 0)
 937                                  {
 938                                    os400StartupOption = true;
 939                                    daemonOption = true;
 940                                  }
 941 chuck           1.164      
 942                                if (!os400StartupOption)
 943                                {
 944                                    // If this is the server job, then set the job
 945                                    // to save the job log.
 946                                    system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
 947                                }
 948 david.dillard   1.165      #endif
 949 lucier          1.130      
 950 mike            1.35           //
 951 mike            1.32           // Get options (from command line and from configuration file); this
 952 mike            1.35           // removes corresponding options and their arguments from the command
 953 mike            1.32           // line.
 954 mike            1.35           //
 955 mike            1.32           try
 956                                {
 957 lucier          1.130      #ifdef PEGASUS_OS_OS400
 958                                if (os400StartupOption == false)
 959 david.dillard   1.165      #endif
 960 s.hills         1.117              GetOptions(configManager, argc, argv);
 961 mike            1.32           }
 962                                catch (Exception& e)
 963                                {
 964 kumpf           1.127              Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 965                                        "src.Server.cimserver.SERVER_NOT_STARTED",
 966 mike            1.191.2.12             "cimserver not started:  $0", e.getMessage());
 967 kumpf           1.127      
 968                            #if !defined(PEGASUS_OS_OS400)
 969                                    MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 970 mike            1.191.2.12             "cimserver not started: $0", e.getMessage());
 971 kumpf           1.127      
 972                                    PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 973                                        << PEGASUS_STD(endl);
 974 david           1.85       #endif
 975 kumpf           1.127      
 976 s.hills         1.117              return(1);
 977 mike            1.32           }
 978                            
 979 chuck           1.94       // l10n
 980 h.sterling      1.153          // Set the home directory, msg sub-dir, into the MessageLoader.
 981 david.dillard   1.165          // This will be the default directory where the resource bundles
 982                                // are found.
 983 h.sterling      1.153          MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
 984 david.dillard   1.165              ConfigManager::getInstance()->getCurrentValue("messageDir")));
 985 chuck           1.94       
 986 lucier          1.130      #ifdef PEGASUS_OS_OS400
 987                                // Still need to declare and set the connection variables.
 988                                // Will initialize to false since they are fixed at false for OS400.
 989                            
 990                                // NOTE:  OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
 991                                // the test will not be compiled in.  If OS400 ever turns off that
 992                                // define, then we will need to change this code path to insure that
 993 david.dillard   1.165          // one of the variables is true.
 994 lucier          1.130          Boolean enableHttpConnection = false;
 995                                Boolean enableHttpsConnection = false;
 996                            
 997                                if (os400StartupOption == false)
 998                                {
 999 kumpf           1.187            enableHttpConnection = ConfigManager::parseBooleanValue(
1000                                      configManager->getCurrentValue("enableHttpConnection"));
1001                                  enableHttpsConnection = ConfigManager::parseBooleanValue(
1002                                      configManager->getCurrentValue("enableHttpsConnection"));
1003 lucier          1.130          }
1004                            #else
1005 kumpf           1.187          Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
1006                                    configManager->getCurrentValue("enableHttpConnection"));
1007                                Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
1008                                    configManager->getCurrentValue("enableHttpsConnection"));
1009 lucier          1.130      #endif
1010 kumpf           1.86       
1011                                // Make sure at least one connection is enabled
1012 h.sterling      1.159      #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1013 kumpf           1.86           if (!enableHttpConnection && !enableHttpsConnection)
1014                                {
1015 humberto        1.97               //l10n
1016                                    //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1017                                        //"Neither HTTP nor HTTPS connection is enabled.  "
1018                                        //"CIMServer will not be started.");
1019                                    Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1020 h.sterling      1.153                  "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
1021 humberto        1.97                   "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
1022                                    //cerr << "Neither HTTP nor HTTPS connection is enabled.  "
1023                                        //"CIMServer will not be started." << endl;
1024                                    MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
1025 h.sterling      1.153                                       "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
1026 humberto        1.97               cerr << MessageLoader::getMessage(parms) << endl;
1027 s.hills         1.117              return(1);
1028 kumpf           1.86           }
1029                            #endif
1030                            
1031 mike            1.35           try
1032 mike            1.32           {
1033 mike            1.35               //
1034 kumpf           1.187              // Check to see if we should start Pegasus as a daemon
1035 mike            1.35               //
1036                            
1037 kumpf           1.187              daemonOption = ConfigManager::parseBooleanValue(
1038                                        configManager->getCurrentValue("daemon"));
1039 david.dillard   1.165      
1040 lucier          1.130      #ifdef PEGASUS_OS_OS400
1041                                if (os400StartupOption == false)
1042                                {
1043 david.dillard   1.165      #endif
1044 kumpf           1.36               // Get the log file directory definition.
1045                                    // We put String into Cstring because
1046                                    // Directory functions only handle Cstring.
1047                                    // ATTN-KS: create String based directory functions.
1048 konrad.r        1.161      #if !defined(PEGASUS_USE_SYSLOGS)
1049                            		// When using syslog facility. No files anymore.
1050 kumpf           1.36               logsDirectory = configManager->getCurrentValue("logdir");
1051 david.dillard   1.165              logsDirectory =
1052 h.sterling      1.153              ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
1053 konrad.r        1.161      #endif
1054 lucier          1.130      #ifdef PEGASUS_OS_OS400
1055                                }  // end if (os400StartupOption == false)
1056                            #endif
1057 kumpf           1.36       
1058                                    // Set up the Logger. This does not open the logs
1059                                    // Might be more logical to clean before set.
1060                                    // ATTN: Need tool to completely disable logging.
1061                            
1062 david           1.85       #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
1063 konrad.r        1.161      !defined(PEGASUS_OS_OS400) && !defined(PEGASUS_USE_SYSLOGS)
1064 kumpf           1.36               Logger::setHomeDirectory(logsDirectory);
1065 kumpf           1.57       #endif
1066 kumpf           1.36       
1067                                    //
1068 david.dillard   1.165              // Check to see if we need to shutdown CIMOM
1069 mike            1.35               //
1070                                    if (shutdownOption)
1071                                    {
1072 david.dillard   1.165                  String configTimeout =
1073 kumpf           1.60                       configManager->getCurrentValue("shutdownTimeout");
1074 s.hills         1.117                  Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
1075 dave.sudlik     1.191      // To deregister Pegasus with SLP
1076                            #ifdef PEGASUS_SLP_REG_TIMEOUT
1077                                        unregisterPegasusFromSLP();
1078                            #endif
1079 david.dillard   1.165      
1080 kumpf           1.52                   shutdownCIMOM(timeoutValue);
1081 kumpf           1.45       
1082 david           1.85       #ifdef PEGASUS_OS_OS400
1083 h.sterling      1.153              //l10n
1084                                    //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
1085 david.dillard   1.165                  //"CIM Server stopped.");
1086 h.sterling      1.153              Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
1087                                        "src.Server.cimserver.SERVER_STOPPED",
1088                                        "CIM Server stopped.");
1089 s.hills         1.117                  cimserver_exitRC(0);
1090 david           1.85       #else
1091 h.sterling      1.153                  //l10n
1092 humberto        1.97                   //cout << "CIM Server stopped." << endl;
1093                                        MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
1094 h.sterling      1.153                                           "CIM Server stopped.");
1095 humberto        1.106      
1096 humberto        1.97                   cout << MessageLoader::getMessage(parms) << endl;
1097 s.hills         1.117                  return(0);
1098 diane           1.81       #endif
1099 mike            1.35               }
1100 mike            1.32       
1101 kumpf           1.139      #if defined(PEGASUS_DEBUG)
1102 kumpf           1.36               // Leave this in until people get familiar with the logs.
1103 humberto        1.97               //l10n
1104                                    //cout << "Logs Directory = " << logsDirectory << endl;
1105 konrad.r        1.161      #if !defined(PEGASUS_USE_SYSLOGS)
1106 humberto        1.97               MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
1107 h.sterling      1.153                                       "Logs Directory = ");
1108 humberto        1.97               cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
1109 kumpf           1.57       #endif
1110 konrad.r        1.161      #endif
1111 mike            1.32           }
1112 kumpf           1.122          catch (UnrecognizedConfigProperty& e)
1113 mike            1.32           {
1114 marek           1.186              // UnrecognizedConfigProperty is already translated
1115                                    // thus, just output the message
1116                                    Logger::put(Logger::ERROR_LOG,
1117                                                System::CIMSERVER,
1118                                                Logger::SEVERE,
1119                                                e.getMessage());
1120                            #ifndef PEGASUS_OS_OS400
1121                                    cout << e.getMessage() << endl;
1122                            #endif
1123                                }
1124                                catch (Exception& ex)
1125                                {
1126                                    Logger::put(Logger::ERROR_LOG,
1127                                                  System::CIMSERVER,
1128                                                  Logger::SEVERE,
1129                                                  ex.getMessage());
1130                            #ifndef PEGASUS_OS_OS400
1131                                    cout << ex.getMessage() << endl;
1132                            #endif
1133                                    exit(1);
1134                                }
1135 david           1.85       
1136 marek           1.186      #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && defined(PEGASUS_ZOS_SECURITY)
1137                                startupCheckBPXServer(true);
1138                                startupCheckProfileCIMSERVclassWBEM();
1139                                startupEnableMSC();
1140 david           1.85       #endif
1141 mike            1.32       
1142 h.sterling      1.158          // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
1143                                // 1) If the user explicitly specified a port, use it.
1144                                // 2) If the user did not specify a port, get the port from the services file.
1145                                // 3) If no value is specified in the services file, use the IANA WBEM default port.
1146                                // Note that 2 and 3 are done within the System::lookupPort method
1147                                // An empty string from the ConfigManager implies that the user did not specify a port.
1148                            
1149 w.otsuka        1.147          Uint32 portNumberHttps=0;
1150                                Uint32 portNumberHttp=0;
1151                                Uint32 portNumberExportHttps=0;
1152 kumpf           1.53       
1153 kumpf           1.86           if (enableHttpsConnection)
1154 kumpf           1.53           {
1155 kumpf           1.86               String httpsPort = configManager->getCurrentValue("httpsPort");
1156 h.sterling      1.158              if (httpsPort == String::EMPTY)
1157 joyce.j         1.144              {
1158 h.sterling      1.158                  //
1159                                        // Look up the WBEM-HTTPS port number
1160                                        //
1161                                        portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1162                            
1163                                    } else
1164 david.dillard   1.165              {
1165 h.sterling      1.158                  //
1166                                        // user-specified
1167                                        //
1168                                        CString portString = httpsPort.getCString();
1169                                        char* end = 0;
1170                                        portNumberHttps = strtol(portString, &end, 10);
1171                                        if(!(end != 0 && *end == '\0'))
1172                                        {
1173 joyce.j         1.160                      InvalidPropertyValue e("httpsPort", httpsPort);
1174 aruran.ms       1.173                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1175                                                          "src.Server.cimserver.SERVER_NOT_STARTED",
1176                                                          "cimserver not started:  $0", e.getMessage());
1177                            #if !defined(PEGASUS_OS_OS400)
1178                                            MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
1179                                                                     "cimserver not started: $0", e.getMessage());
1180                                            PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
1181                                                              << PEGASUS_STD(endl);
1182                            #endif
1183 h.sterling      1.158                      exit(1);
1184                                        }
1185 joyce.j         1.144              }
1186 kumpf           1.53           }
1187 kumpf           1.86       
1188                                if (enableHttpConnection)
1189 kumpf           1.53           {
1190 kumpf           1.86               String httpPort = configManager->getCurrentValue("httpPort");
1191 h.sterling      1.158              if (httpPort == String::EMPTY)
1192 joyce.j         1.144              {
1193 h.sterling      1.158                  //
1194                                        // Look up the WBEM-HTTP port number
1195                                        //
1196                                        portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1197                            
1198                                    } else
1199                                    {
1200                                        //
1201                                        // user-specified
1202                                        //
1203                                        CString portString = httpPort.getCString();
1204                                        char* end = 0;
1205                                        portNumberHttp = strtol(portString, &end, 10);
1206                                        if(!(end != 0 && *end == '\0'))
1207                                        {
1208 joyce.j         1.160                      InvalidPropertyValue e("httpPort", httpPort);
1209 aruran.ms       1.173                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1210                                                          "src.Server.cimserver.SERVER_NOT_STARTED",
1211                                                          "cimserver not started:  $0", e.getMessage());
1212                            #if !defined(PEGASUS_OS_OS400)
1213                                            MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
1214                                                                         "cimserver not started: $0", e.getMessage());
1215                                            PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
1216                                                              << PEGASUS_STD(endl);
1217                            #endif
1218 h.sterling      1.158                      exit(1);
1219                                        }
1220 joyce.j         1.144              }
1221 kumpf           1.53           }
1222 kumpf           1.139      #if defined(PEGASUS_DEBUG)
1223 mike            1.32           // Put out startup up message.
1224 jim.wunderlich  1.180          cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getCompleteVersion() << endl;
1225 humberto        1.97           //l10n
1226                                //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
1227                                //cout <<"Starting..."
1228                                MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
1229 h.sterling      1.153                                   "Built $0 $1\nStarting...",
1230                                                         __DATE__,
1231                                                         __TIME__);
1232 humberto        1.97       #endif
1233                            
1234                            //l10n
1235                            // reset message loading to NON-process locale
1236 david.dillard   1.165      MessageLoader::_useProcessLocale = false;
1237 humberto        1.97       //l10n
1238 mike            1.32       
1239 kumpf           1.137          // Get the parent's PID before forking
1240 h.sterling      1.154          _cimServerProcess->set_parent_pid(System::getPID());
1241 david.dillard   1.165      
1242 mike            1.191.2.5  // Do not fork when using privilege separation (executor will daemonize itself
1243                            // later).
1244 kumpf           1.63           if (daemonOption)
1245                                {
1246 h.sterling      1.153              if(-1 == _cimServerProcess->cimserver_fork())
1247 mike            1.191.2.5  # ifndef PEGASUS_OS_OS400
1248 mike            1.191.2.1              return(-1);
1249 mike            1.191.2.5  # else
1250 david           1.85                   return(-1);
1251 mike            1.191.2.1          else
1252                                        return(0);
1253 mike            1.191.2.5  # endif
1254 kumpf           1.63           }
1255 chuck           1.66       
1256 chuck           1.96       // l10n
1257                                // Now we are after the fork...
1258                                // Create a dummy Thread object that can be used to store the
1259 kumpf           1.176          // AcceptLanguageList object for CIM requests that are serviced
1260 chuck           1.96           // by this thread (initial thread of server).  Need to do this
1261                                // because this thread is not in a ThreadPool, but is used
1262                                // to service CIM requests.
1263                                // The run function for the dummy Thread should never be called,
1264 konrad.r        1.166          dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
1265 david.dillard   1.165          Thread::setCurrent(dummyInitialThread);
1266 kumpf           1.176          AcceptLanguageList default_al;
1267 humberto        1.108          try{
1268 kumpf           1.174               default_al = LanguageParser::getDefaultAcceptLanguages();
1269 kumpf           1.176               Thread::setLanguages(new AcceptLanguageList(default_al));
1270 kumpf           1.122          }catch(InvalidAcceptLanguageHeader& e){
1271 h.sterling      1.153                Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1272                                              "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
1273 david.dillard   1.165                        "Could not convert the system process locale into a valid AcceptLanguage format.");
1274 h.sterling      1.153                Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1275 david.dillard   1.165                                   e.getMessage());
1276 humberto        1.108          }
1277 david.dillard   1.165      
1278                            
1279 chuck           1.96       
1280 chuck           1.66       #ifdef PEGASUS_OS_OS400
1281                                // Special server initialization code for OS/400.
1282                                if (cimserver_initialize() != 0)
1283                                {
1284 h.sterling      1.153          // do some logging here!
1285                                //l10n
1286                                //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1287 david.dillard   1.165                  //"CIM Server failed to initialize");
1288 h.sterling      1.153          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1289                                              "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
1290 david.dillard   1.165                        "CIM Server failed to initialize");
1291 h.sterling      1.153          return(-1);
1292 david.dillard   1.165          }
1293 chuck           1.66       #endif
1294 chuck           1.96       
1295 kumpf           1.167      #ifndef PEGASUS_OS_TYPE_WINDOWS
1296                                umask(S_IRWXG|S_IRWXO);
1297                            #endif
1298 mday            1.62       
1299 mateus.baur     1.175      
1300                            #if defined(PEGASUS_OS_TYPE_UNIX)
1301                              //    
1302                              // CRITICAL SECTION BEGIN
1303                              //
1304                              // This is the beginning of the critical section regarding the
1305                              // access to pidfile (file to indicate that the cimserver has started).
1306                              // Sometimes, when 2 or more cimserver processes are started at the same 
1307                              // time, they can't detect the concurrent process execution because the 
1308                              // logic fails when pidfile is accessed concurrently.
1309                            
1310                              FILE *startupLockFile;
1311                            
1312 denise.eckstein 1.177        if ((startupLockFile = fopen(ConfigManager::getHomedPath(
1313                                      CIMSERVER_LOCK_FILE).getCString(), "w")) != 0)
1314 mateus.baur     1.175        {
1315                                  lockf(fileno(startupLockFile), F_LOCK, 0);
1316                              }
1317                            #endif
1318                            
1319 gs.keenan       1.150      #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1320                            || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1321 jim.wunderlich  1.169      || defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS)
1322 kumpf           1.79       
1323                                //
1324                                // check if CIMServer is already running
1325 david.dillard   1.165          // if CIMServer is already running, print message and
1326 kumpf           1.79           // notify parent process (if there is a parent process) to terminate
1327                                //
1328 h.sterling      1.153          if(_cimServerProcess->isCIMServerRunning())
1329 kumpf           1.79           {
1330 h.sterling      1.153          //l10n
1331                                    //cout << "Unable to start CIMServer." << endl;
1332                                    //cout << "CIMServer is already running." << endl;
1333                                    MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1334                                                 "Unable to start CIMServer.\nCIMServer is already running.");
1335                                PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1336 kumpf           1.79       
1337 h.sterling      1.153          //
1338 kumpf           1.79               // notify parent process (if there is a parent process) to terminate
1339                                    //
1340                                    if (daemonOption)
1341 h.sterling      1.153                      _cimServerProcess->notify_parent(1);
1342 kumpf           1.79       
1343 s.hills         1.117              return(1);
1344 kumpf           1.79           }
1345 david.dillard   1.165      
1346 kumpf           1.63       #endif
1347 kumpf           1.51       
1348 mike            1.32           // try loop to bind the address, and run the server
1349                                try
1350                                {
1351 mday            1.116      
1352 konrad.r        1.163          _monitor  = new Monitor();
1353 h.sterling      1.153          //PEP#222
1354                                //CIMServer server(&monitor);
1355                                //CimserverHolder cimserverHolder( &server );
1356 konrad.r        1.163          _cimServer = new CIMServer(_monitor);
1357 mday            1.111      
1358 kumpf           1.41       
1359 kumpf           1.86               if (enableHttpConnection)
1360                                    {
1361 sushma.fernandes 1.189                  _cimServer->addAcceptor(false, portNumberHttp, false);
1362 humberto         1.97                   //l10n
1363                                         //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1364                                                     //"Listening on HTTP port $0.", portNumberHttp);
1365 david.dillard    1.165      
1366 humberto         1.97                   Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1367 h.sterling       1.153                                  "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1368                                                         "Listening on HTTP port $0.", portNumberHttp);
1369 kumpf            1.86               }
1370                                     if (enableHttpsConnection)
1371                                     {
1372 sushma.fernandes 1.189                  _cimServer->addAcceptor(false, portNumberHttps, true);
1373 humberto         1.97                   //l10n
1374                                         //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1375                                                     //"Listening on HTTPS port $0.", portNumberHttps);
1376                                         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1377 h.sterling       1.153                                  "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1378                                                         "Listening on HTTPS port $0.", portNumberHttps);
1379 kumpf            1.86               }
1380 kumpf            1.135      
1381 h.sterling       1.159      #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1382 sushma.fernandes 1.189              _cimServer->addAcceptor(true, 0, false);
1383 humberto         1.97               //l10n
1384                                     //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1385                                                 //"Listening on local connection socket.");
1386                                     Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1387 h.sterling       1.153                    "src.Server.cimserver.LISTENING_ON_LOCAL",
1388                                           "Listening on local connection socket.");
1389 kumpf            1.41       #endif
1390 kumpf            1.86       
1391 kumpf            1.139      #if defined(PEGASUS_DEBUG)
1392 kumpf            1.86               if (enableHttpConnection)
1393                                     {
1394 humberto         1.97                   //l10n
1395                                         //cout << "Listening on HTTP port " << portNumberHttp << endl;
1396 h.sterling       1.153            MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1397                                                "Listening on HTTP port $0.", portNumberHttp);
1398                                         cout << MessageLoader::getMessage(parms) << endl;
1399 kumpf            1.86               }
1400                                     if (enableHttpsConnection)
1401                                     {
1402 humberto         1.97                   //l10n
1403                                         //cout << "Listening on HTTPS port " << portNumberHttps << endl;
1404 humberto         1.103                  MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1405 h.sterling       1.153                           "Listening on HTTPS port $0.", portNumberHttps);
1406                                         cout << MessageLoader::getMessage(parms) << endl;
1407 kumpf            1.86               }
1408 kumpf            1.135      
1409 h.sterling       1.159      # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1410 humberto         1.97               //l10n
1411                                     //cout << "Listening on local connection socket" << endl;
1412                                     MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
1413 h.sterling       1.153                       "Listening on local connection socket.");
1414 humberto         1.97               cout << MessageLoader::getMessage(parms) << endl;
1415 kumpf            1.86       # endif
1416 david            1.85       #endif
1417 mike             1.35       
1418 kumpf            1.86               // bind throws an exception if the bind fails
1419 david.dillard    1.165      	try {
1420 konrad.r         1.163                 _cimServer->bind();
1421                             	} catch (const BindFailedException &e)
1422                             	{
1423                             #ifdef PEGASUS_DEBUG
1424                                     MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED",
1425                                              "Could not bind: $0.", e.getMessage());
1426                                     cout << MessageLoader::getMessage(parms) << endl;
1427                             #endif
1428                                     Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1429                                         "src.Server.cimserver.BIND.FAILED",
1430                                         "Could not bind:  $0", e.getMessage());
1431 kumpf            1.73       
1432 konrad.r         1.163      	   deleteCIMServer();
1433                             	   return 1;
1434                             	}
1435 david.dillard    1.165          // notify parent process (if there is a parent process) to terminate
1436 konrad.r         1.95               // so user knows that there is cimserver ready to serve CIM requests.
1437 mike             1.191.2.5  #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION)
1438                                 if (daemonOption)
1439 mike             1.191.2.9          Executor::daemonizeExecutor();
1440 mike             1.191.2.5  #else
1441 h.sterling       1.153          if (daemonOption)
1442                                     _cimServerProcess->notify_parent(0);
1443 mike             1.191.2.5  #endif
1444 mike             1.32       
1445 h.sterling       1.153          time_t last = 0;
1446 mike             1.35       
1447 gs.keenan        1.150      #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \
1448 jim.wunderlich   1.169          || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_SOLARIS) \
1449 gs.keenan        1.150          || defined(PEGASUS_OS_VMS)
1450 kumpf            1.45               //
1451 kumpf            1.56               // create a file to indicate that the cimserver has started and
1452                                     // save the process id of the cimserver process in the file
1453 kumpf            1.45               //
1454 kumpf            1.56               // remove the old file if it exists
1455 h.sterling       1.153              System::removeFile(_cimServerProcess->getPIDFileName());
1456 kumpf            1.56       
1457                                     // open the file
1458 h.sterling       1.153              FILE *pid_file = fopen(_cimServerProcess->getPIDFileName(), "w");
1459 kumpf            1.91       
1460 kumpf            1.56               if (pid_file)
1461 kumpf            1.45               {
1462 kumpf            1.56                   // save the pid in the file
1463 h.sterling       1.153                  fprintf(pid_file, "%ld\n", _cimServerProcess->get_server_pid());
1464 kumpf            1.56                   fclose(pid_file);
1465 kumpf            1.45               }
1466                             #endif
1467 kumpf            1.91       
1468 kumpf            1.139      #if defined(PEGASUS_DEBUG)
1469 h.sterling       1.153          cout << "Started. " << endl;
1470 kumpf            1.63       #endif
1471 david.dillard    1.165      
1472 mateus.baur      1.175      #if defined(PEGASUS_OS_TYPE_UNIX)    
1473                                 //
1474                                 // CRITICAL SECTION END
1475                                 // 
1476                                 // Here is the unlock of file 'lock_file'. It closes the
1477                                 // the critical section that guarantees the non concurrent access to
1478                                 // pid file (file to indicate that the cimserver has started).
1479                                 //
1480                             
1481                                 if (startupLockFile)
1482                                 {
1483                                    lockf(fileno(startupLockFile), F_ULOCK, 0);
1484                                    fclose(startupLockFile);
1485                                 }
1486                             #endif
1487                             
1488                             
1489 kumpf            1.54               // Put server started message to the logger
1490 kumpf            1.143              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1491                                         Logger::INFORMATION,
1492                                         "src.Server.cimserver.STARTED_VERSION",
1493                                         "Started $0 version $1.",
1494 jim.wunderlich   1.180      		      _cimServerProcess->getProductName(), _cimServerProcess->getCompleteVersion());
1495 kumpf            1.45       
1496 marek            1.190      #if defined(PEGASUS_OS_TYPE_UNIX) && !defined(PEGASUS_OS_ZOS)
1497 kumpf            1.178              if (daemonOption && !debugOutputOption)
1498                                     { 
1499                                         // Direct standard input, output, and error to /dev/null,
1500                                         // since we are running as a daemon.
1501                                         close(0);
1502                                         open("/dev/null", O_RDONLY);
1503                                         close(1);
1504                                         open("/dev/null", O_RDWR);
1505                                         close(2);
1506                                         open("/dev/null", O_RDWR);
1507                                     }
1508                             #endif
1509                             
1510 thilo.boehm      1.185      #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1511                             
1512                                     // ARM is a z/OS internal restart facility. 
1513                                     // This is a z/OS specific change. 
1514                             
1515                                     // Instatiating the automatic restart manager for zOS
1516                                     ARM_zOS automaticRestartManager;
1517                             
1518                                     // register to zOS ARM
1519                                     automaticRestartManager.Register();
1520                             
1521                             #endif
1522                             
1523 mike             1.35               //
1524                                     // Loop to call CIMServer's runForever() method until CIMServer
1525                                     // has been shutdown
1526                                     //
1527 h.sterling       1.153          while( !_cimServer->terminated() )
1528                                 {
1529 mday             1.116      
1530 h.sterling       1.153            _cimServer->runForever();
1531 mday             1.112      
1532 h.sterling       1.153          }
1533 carson.hovey     1.157      
1534 kumpf            1.45               //
1535                                     // normal termination
1536 carson.hovey     1.157              //
1537 thilo.boehm      1.185      #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1538                             
1539                                     // ARM is a z/OS internal restart facility. 
1540                                     // This is a z/OS specific change. 
1541                             
1542                                     // register to zOS ARM
1543                                     automaticRestartManager.DeRegister();
1544                             
1545                             #endif
1546 kumpf            1.143      
1547 kumpf            1.54               // Put server shutdown message to the logger
1548 kumpf            1.143              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1549                                         Logger::INFORMATION, "src.Server.cimserver.STOPPED",
1550 h.sterling       1.153                  "$0 stopped.", _cimServerProcess->getProductName());
1551 kumpf            1.45       
1552 carolann.graves  1.171      #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) \
1553 gs.keenan        1.150      || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1554 jim.wunderlich   1.169      || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
1555 kumpf            1.45               //
1556 carolann.graves  1.171              //  Note: do not remove the PID file created at startup time, since
1557                                     //  shutdown is not complete until the CIMServer destructor completes.
1558 kumpf            1.45               //
1559                             #endif
1560 mike             1.32           }
1561                                 catch(Exception& e)
1562                                 {
1563 david            1.100      
1564 h.sterling       1.153          //l10n
1565                                 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1566 david.dillard    1.165                  //"Error: $0", e.getMessage());
1567 h.sterling       1.153          Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1568                                         "src.Server.cimserver.ERROR",
1569 david.dillard    1.165                  "Error: $0", e.getMessage());
1570 konrad.r         1.95       
1571                             #ifndef PEGASUS_OS_OS400
1572 h.sterling       1.153          //l10n
1573                                 //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1574                                 MessageLoaderParms parms("src.Server.cimserver.ERROR",
1575                                                          "Error: $0", e.getMessage());
1576                                 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1577 david            1.100      
1578 david            1.85       #endif
1579 kumpf            1.77       
1580 h.sterling       1.153          //
1581 kumpf            1.77               // notify parent process (if there is a parent process) to terminate
1582                                     //
1583                                     if (daemonOption)
1584 h.sterling       1.153                      _cimServerProcess->notify_parent(1);
1585 kumpf            1.77       
1586 h.sterling       1.156              deleteCIMServer();
1587 kumpf            1.54               return 1;
1588 mike             1.32           }
1589                             
1590 h.sterling       1.156          deleteCIMServer();
1591 mike             1.32           return 0;
1592                             }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2