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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2