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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2