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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2