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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2