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

   1 martin 1.226 //%LICENSE////////////////////////////////////////////////////////////////
   2 martin 1.227 //
   3 martin 1.226 // Licensed to The Open Group (TOG) under one or more contributor license
   4              // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   5              // this work for additional information regarding copyright ownership.
   6              // Each contributor licenses this file to you under the OpenPegasus Open
   7              // Source License; you may not use this file except in compliance with the
   8              // License.
   9 martin 1.227 //
  10 martin 1.226 // Permission is hereby granted, free of charge, to any person obtaining a
  11              // copy of this software and associated documentation files (the "Software"),
  12              // to deal in the Software without restriction, including without limitation
  13              // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14              // and/or sell copies of the Software, and to permit persons to whom the
  15              // Software is furnished to do so, subject to the following conditions:
  16 martin 1.227 //
  17 martin 1.226 // The above copyright notice and this permission notice shall be included
  18              // in all copies or substantial portions of the Software.
  19 martin 1.227 //
  20 martin 1.226 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21 martin 1.227 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22 martin 1.226 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23              // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24              // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25              // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26              // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27 martin 1.227 //
  28 martin 1.226 //////////////////////////////////////////////////////////////////////////
  29 mike   1.32  //
  30              //%/////////////////////////////////////////////////////////////////////////////
  31              
  32              
  33              //////////////////////////////////////////////////////////////////////
  34              //
  35 carolann.graves 1.171 // Notes on daemon operation (Unix) and service operation (Win 32):
  36 mike            1.32  //
  37 david.dillard   1.165 // To run pegasus as a daemon on Unix platforms:
  38 mike            1.32  //
  39 kumpf           1.60  // cimserver
  40 mike            1.32  //
  41 kumpf           1.60  // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
  42                       // property to false:
  43                       //
  44                       // cimserver daemon=false
  45                       //
  46 kumpf           1.215 // The daemon config property has no effect on windows operation or when
  47                       // privilege separation is enabled.
  48 mike            1.32  //
  49 mike            1.35  // To shutdown pegasus, use the -s option:
  50 david.dillard   1.165 //
  51                       // cimserver -s
  52 mike            1.35  //
  53 mike            1.32  // To run pegasus as an NT service, there are FOUR  different possibilities:
  54                       //
  55 david.dillard   1.165 // To INSTALL the Pegasus service,
  56 mike            1.32  //
  57                       // cimserver -install
  58                       //
  59 david.dillard   1.165 // To REMOVE the Pegasus service,
  60 mike            1.32  //
  61                       // cimserver -remove
  62                       //
  63 david.dillard   1.165 // To START the Pegasus service,
  64 mike            1.32  //
  65                       // net start cimserver
  66 s.hills         1.117 // or
  67                       // cimserver -start
  68 mike            1.32  //
  69 david.dillard   1.165 // To STOP the Pegasus service,
  70 mike            1.32  //
  71                       // net stop cimserver
  72 s.hills         1.117 // or
  73                       // cimserver -stop
  74 mike            1.32  //
  75 david.dillard   1.165 // Alternatively, you can use the windows service manager. Pegasus shows up
  76 mike            1.32  // in the service database as "Pegasus CIM Object Manager"
  77                       //
  78                       //////////////////////////////////////////////////////////////////////
  79                       
  80                       
  81 mike            1.35  #include <Pegasus/Common/Config.h>
  82 kumpf           1.59  #include <Pegasus/Common/Constants.h>
  83 jim.wunderlich  1.172 #include <Pegasus/Common/PegasusAssert.h>
  84 mike            1.32  #include <Pegasus/Common/FileSystem.h>
  85                       #include <Pegasus/Common/PegasusVersion.h>
  86                       #include <Pegasus/Common/Logger.h>
  87 denise.eckstein 1.218 #include <Pegasus/Common/StringConversion.h>
  88 mike            1.32  #include <Pegasus/Common/System.h>
  89 mike            1.35  #include <Pegasus/Common/Tracer.h>
  90 kumpf           1.174 #include <Pegasus/Common/LanguageParser.h>
  91 mike            1.35  #include <Pegasus/Config/ConfigManager.h>
  92                       #include <Pegasus/Client/CIMClient.h>
  93 h.sterling      1.153 #include <Pegasus/Server/CIMServer.h>
  94                       #include <Service/ServerProcess.h>
  95 kumpf           1.198 #include <Service/ServerShutdownClient.h>
  96                       #include <Service/ServerRunStatus.h>
  97 mike            1.32  
  98 r.kieninger     1.223 #if defined(PEGASUS_OS_ZOS)
  99 thilo.boehm     1.235 #include <Pegasus/General/SetFileDescriptorToEBCDICEncoding.h>
 100 thilo.boehm     1.185 #include <Service/ARM_zOS.h>
 101 marek           1.236 #include <Service/TimeZone_zOS.h>
 102 thilo.boehm     1.237 #include <Service/WaitForTCPIP_zOS.h>
 103 marek           1.186 # ifdef PEGASUS_ZOS_SECURITY
 104                       // This include file will not be provided in the OpenGroup CVS for now.
 105                       // Do NOT try to include it in your compile
 106                       #  include <Pegasus/Common/safCheckzOS_inline.h>
 107                       # endif
 108 thilo.boehm     1.185 #endif
 109                       
 110 kumpf           1.178 #if defined(PEGASUS_OS_TYPE_UNIX)
 111 ouyang.jian     1.200 # include <unistd.h>
 112 kumpf           1.178 # include <sys/types.h>
 113                       # include <sys/stat.h>
 114                       # include <fcntl.h>
 115 mateus.baur     1.175 #endif
 116                       
 117 kumpf           1.199 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 118                       # define PEGASUS_PROCESS_NAME "cimservermain"
 119                       #else
 120                       # define PEGASUS_PROCESS_NAME "cimserver"
 121                       #endif
 122                       
 123                       #include <Pegasus/Common/Executor.h>
 124                       
 125 ouyang.jian     1.206 #ifdef PEGASUS_OS_PASE
 126                       # include <ILEWrapper/ILEUtilities2.h>
 127                       # include <ILEWrapper/qumemultiutil.h>
 128                       #endif
 129                       
 130 kumpf           1.119 PEGASUS_USING_PEGASUS;
 131                       PEGASUS_USING_STD;
 132                       
 133 h.sterling      1.153 //Windows service variables are not defined elsewhere in the product
 134                       //enable ability to override these
 135 venkat.puvvada  1.239 #ifndef PEGASUS_FLAVOR
 136 h.sterling      1.153 #ifndef PEGASUS_SERVICE_NAME
 137                       #define PEGASUS_SERVICE_NAME "Pegasus CIM Object Manager";
 138 chuck           1.66  #endif
 139 h.sterling      1.153 #ifndef PEGASUS_SERVICE_DESCRIPTION
 140                       #define PEGASUS_SERVICE_DESCRIPTION "Pegasus CIM Object Manager Service";
 141 mike            1.32  #endif
 142 venkat.puvvada  1.239 #else
 143                       #ifndef PEGASUS_SERVICE_NAME
 144                       #define PEGASUS_SERVICE_NAME PEGASUS_FLAVOR " Pegasus CIM Object Manager"
 145                       #endif
 146                       #ifndef PEGASUS_SERVICE_DESCRIPTION
 147                       #define PEGASUS_SERVICE_DESCRIPTION PEGASUS_FLAVOR \
 148                                   " Pegasus CIM Object Manager Service";
 149                       #endif
 150                       #endif
 151 mike            1.32  
 152 ouyang.jian     1.206 #ifdef PEGASUS_OS_PASE
 153                       #include <as400_protos.h> //for _SETCCSID
 154                       #endif
 155                       
 156 h.sterling      1.153 class CIMServerProcess : public ServerProcess
 157                       {
 158                       public:
 159                       
 160 kumpf           1.203     CIMServerProcess()
 161 h.sterling      1.153     {
 162                               cimserver_set_process(this);
 163                           }
 164                       
 165 kumpf           1.203     virtual ~CIMServerProcess()
 166 h.sterling      1.153     {
 167                           }
 168                       
 169                           //defined in PegasusVersion.h
 170                           virtual const char* getProductName() const
 171                           {
 172                               return PEGASUS_PRODUCT_NAME;
 173                           }
 174                       
 175                           virtual const char* getExtendedName() const
 176                           {
 177                               return PEGASUS_SERVICE_NAME;
 178                           }
 179                       
 180                           virtual const char* getDescription() const
 181                           {
 182                               return PEGASUS_SERVICE_DESCRIPTION;
 183                           }
 184 david.dillard   1.165 
 185 h.sterling      1.153     //defined in PegasusVersion.h
 186 jim.wunderlich  1.180     virtual const char* getCompleteVersion() const
 187                           {
 188 jim.wunderlich  1.181       if (*PEGASUS_PRODUCT_STATUS == '\0' )
 189 kumpf           1.199         return PEGASUS_PRODUCT_VERSION;
 190 jim.wunderlich  1.180       else
 191 kumpf           1.202         return PEGASUS_PRODUCT_VERSION " " PEGASUS_PRODUCT_STATUS;
 192 jim.wunderlich  1.180     }
 193                       
 194                           //defined in PegasusVersion.h
 195 h.sterling      1.153     virtual const char* getVersion() const
 196                           {
 197                               return PEGASUS_PRODUCT_VERSION;
 198                           }
 199                       
 200                           virtual const char* getProcessName() const
 201                           {
 202                               return PEGASUS_PROCESS_NAME;
 203                           }
 204                       
 205 kumpf           1.178     int cimserver_run(
 206                               int argc,
 207                               char** argv,
 208                               Boolean shutdownOption,
 209                               Boolean debugOutputOption);
 210 h.sterling      1.153 
 211 kumpf           1.203     void cimserver_stop();
 212 h.sterling      1.153 };
 213                       
 214 kumpf           1.198 ServerRunStatus _serverRunStatus(
 215                           PEGASUS_PROCESS_NAME, PEGASUS_CIMSERVER_START_FILE);
 216 h.sterling      1.153 AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
 217                       static CIMServer* _cimServer = 0;
 218 konrad.r        1.166 static Thread* dummyInitialThread = 0;
 219 kumpf           1.203 
 220 mike            1.35  //
 221                       //  The command name.
 222                       //
 223                       static const char COMMAND_NAME []    = "cimserver";
 224                       
 225                       //
 226                       //  The constant defining usage string.
 227                       //
 228                       static const char USAGE []           = "Usage: ";
 229                       
 230                       /**
 231                       Constants representing the command line options.
 232                       */
 233                       static const char OPTION_VERSION     = 'v';
 234                       
 235                       static const char OPTION_HELP        = 'h';
 236                       
 237                       static const char OPTION_HOME        = 'D';
 238                       
 239                       static const char OPTION_SHUTDOWN    = 's';
 240                       
 241 kumpf           1.203 static const char LONG_HELP[]        = "help";
 242 a.arora         1.142 
 243 kumpf           1.203 static const char LONG_VERSION[]     = "version";
 244 a.arora         1.142 
 245 kumpf           1.178 static const char OPTION_DEBUGOUTPUT = 'X';
 246 kumpf           1.48  
 247 mike            1.32  /** GetOptions function - This function defines the Options Table
 248 mike            1.35      and sets up the options from that table using the config manager.
 249 kumpf           1.198 
 250                           Some possible exceptions:  NoSuchFile, FileNotReadable, CannotRenameFile,
 251                           ConfigFileSyntaxError, UnrecognizedConfigProperty, InvalidPropertyValue,
 252                           CannotOpenFile.
 253 mike            1.32  */
 254                       void GetOptions(
 255 mike            1.35      ConfigManager* cm,
 256 mike            1.32      int& argc,
 257 mateus.baur     1.193     char** argv,
 258 kumpf           1.198     Boolean shutdownOption)
 259 mike            1.32  {
 260 kumpf           1.198     if (shutdownOption)
 261                           {
 262                               cm->loadConfigFiles();
 263                           }
 264                           else
 265 mike            1.32      {
 266 kumpf           1.198         cm->mergeConfigFiles();
 267                           }
 268 mateus.baur     1.193 
 269 kumpf           1.198     // Temporarily disable updates to the current configuration
 270                           // file if shutdownOption is true
 271                           cm->useConfigFiles = (shutdownOption==false);
 272 mike            1.33  
 273 kumpf           1.198     cm->mergeCommandLine(argc, argv);
 274 mateus.baur     1.193 
 275 kumpf           1.198     // Enable updates again
 276                           cm->useConfigFiles = true;
 277 mike            1.32  }
 278                       
 279                       /* PrintHelp - This is temporary until we expand the options manager to allow
 280                          options help to be defined with the OptionRow entries and presented from
 281                          those entries.
 282                       */
 283                       void PrintHelp(const char* arg0)
 284                       {
 285 mike            1.35      String usage = String (USAGE);
 286 kumpf           1.202     usage.append(COMMAND_NAME);
 287                           usage.append(" [ [ options ] | [ configProperty=value, ... ] ]\n");
 288                           usage.append("  options\n");
 289                           usage.append("    -v, --version   - displays CIM Server version number\n");
 290 denise.eckstein 1.229     usage.append("    --status        - displays the running status of"
 291                               " the CIM Server\n");
 292 kumpf           1.202     usage.append("    -h, --help      - prints this help message\n");
 293                           usage.append("    -s              - shuts down CIM Server\n");
 294 kumpf           1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 295 kumpf           1.202     usage.append("    -D [home]       - sets pegasus home directory\n");
 296 humberto        1.97  #endif
 297                       #if defined(PEGASUS_OS_TYPE_WINDOWS)
 298 kumpf           1.202     usage.append("    -install [name] - installs pegasus as a Windows "
 299                               "Service\n");
 300                           usage.append("                      [name] is optional and overrides "
 301                               "the\n");
 302                           usage.append("                      default CIM Server Service Name\n");
 303                           usage.append("                      by appending [name]\n");
 304                           usage.append("    -remove [name]  - removes pegasus as a Windows "
 305                               "Service\n");
 306                           usage.append("                      [name] is optional and overrides "
 307                               "the\n");
 308                           usage.append("                      default CIM Server Service Name\n");
 309                           usage.append("                      by appending [name]\n");
 310                           usage.append("    -start [name]   - starts pegasus as a Windows Service\n");
 311                           usage.append("                      [name] is optional and overrides "
 312                               "the\n");
 313                           usage.append("                      default CIM Server Service Name\n");
 314                           usage.append("                      by appending [name]\n");
 315                           usage.append("    -stop [name]    - stops pegasus as a Windows Service\n");
 316                           usage.append("                      [name] is optional and overrides "
 317                               "the\n");
 318                           usage.append("                      default CIM Server Service Name\n");
 319 kumpf           1.202     usage.append("                      by appending [name]\n\n");
 320                       #endif
 321                           usage.append("  configProperty=value\n");
 322                           usage.append("                    - sets CIM Server configuration "
 323                               "property\n");
 324 humberto        1.97  
 325                           cout << endl;
 326 kumpf           1.202     cout << _cimServerProcess->getProductName() << " " <<
 327                               _cimServerProcess->getCompleteVersion() << endl;
 328 humberto        1.97      cout << endl;
 329 david.dillard   1.165 
 330 humberto        1.97  #if defined(PEGASUS_OS_TYPE_WINDOWS)
 331 humberto        1.104     MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
 332 kumpf           1.152 #elif defined(PEGASUS_USE_RELEASE_DIRS)
 333 kumpf           1.202     MessageLoaderParms parms(
 334                               "src.Server.cimserver.MENU.HPUXLINUXIA64GNU",
 335                               usage);
 336 humberto        1.97  #else
 337 kumpf           1.138     MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
 338 humberto        1.97  #endif
 339                           cout << MessageLoader::getMessage(parms) << endl;
 340 mike            1.35  }
 341                       
 342 kumpf           1.202 // This needs to be called at various points in the code depending on the
 343                       // platform and error conditions.
 344                       // We need to delete the _cimServer reference on exit in order for the
 345                       // destructors to get called.
 346 h.sterling      1.156 void deleteCIMServer()
 347                       {
 348 kumpf           1.203     delete _cimServer;
 349                           _cimServer = 0;
 350 kumpf           1.202 
 351                           if (dummyInitialThread)
 352                           {
 353 kumpf           1.199         Thread::clearLanguages();
 354                               delete dummyInitialThread;
 355 kumpf           1.202     }
 356 venkat.puvvada  1.238     _serverRunStatus.setServerNotRunning();
 357 h.sterling      1.156 }
 358                       
 359 chuck           1.96  //
 360                       // Dummy function for the Thread object associated with the initial thread.
 361                       // Since the initial thread is used to process CIM requests, this is
 362                       // needed to localize the exceptions thrown during CIM request processing.
 363 david.dillard   1.165 // Note: This function should never be called!
 364                       //
 365 kumpf           1.202 ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void* parm)
 366 chuck           1.96  {
 367 kumpf           1.202     return (ThreadReturnType)0;
 368 chuck           1.96  }
 369                       
 370 kumpf           1.199 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 371                       
 372                       static int _extractExecutorSockOpt(int& argc, char**& argv)
 373                       {
 374                           // Extract the "--executor-socket <sock>" option if any. This indicates
 375                           // that the e[x]ecutor is running. The option argument is the socket used
 376                           // to communicate with the executor. Remove the option from the
 377                           // argv list and decrease argc by two.
 378                       
 379                           int sock = -1;
 380                           const char OPT[] = "--executor-socket";
 381                       
 382                           for (int i = 1; i < argc; i++)
 383                           {
 384                               if (strcmp(argv[i], OPT) == 0)
 385                               {
 386                                   // Check for missing option argument.
 387                       
 388                                   if (i + 1 == argc)
 389                                   {
 390                                       MessageLoaderParms parms(
 391 kumpf           1.199                     "src.Server.cimserver.MISSING_OPTION_ARGUMENT",
 392                                           "Missing argument for $0 option.",
 393                                           OPT);
 394                                       cerr << argv[0] << ": " << MessageLoader::getMessage(parms) <<
 395                                           endl;
 396                                       exit(1);
 397                                   }
 398                       
 399                                   // Convert argument to positive integer.
 400                       
 401                                   char* end;
 402                                   unsigned long x = strtoul(argv[i+1], &end, 10);
 403                       
 404                                   // Check whether option argument will fit in a signed integer.
 405                       
 406                                   if (*end != '\0' || x > 2147483647)
 407                                   {
 408                                       MessageLoaderParms parms(
 409                                           "src.Server.cimserver.BAD_OPTION_ARGUMENT",
 410                                           "Bad $0 option argument: $1.",
 411                                           OPT,
 412 kumpf           1.199                     argv[i+1]);
 413                                       cerr << argv[0] << ": " << MessageLoader::getMessage(parms) <<
 414                                           endl;
 415                                       exit(1);
 416                                   }
 417                       
 418                                   sock = int(x);
 419                       
 420                                   // Remove "-x <sock>" from argv-argc.
 421                       
 422                                   memmove(argv + i, argv + i + 2, sizeof(char*) * (argc - i - 1));
 423                                   argc -= 2;
 424                                   break;
 425                               }
 426                           }
 427                       
 428                           if (sock == -1)
 429                           {
 430                               MessageLoaderParms parms(
 431                                   "src.Server.cimserver.MISSING_OPTION",
 432                                   "Missing $0 option.",
 433 kumpf           1.199             OPT);
 434                               cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << endl;
 435                               exit(1);
 436                           }
 437                       
 438                           return sock;
 439                       }
 440                       
 441                       #endif /* PEGASUS_ENABLE_PRIVILEGE_SEPARATION */
 442 mike            1.35  
 443 venkat.puvvada  1.231 static void _initConfigProperty(const String &propName, Uint32 value)
 444                       {
 445                           char strValue[22];
 446                           Uint32 n;
 447                           const char *startP = Uint32ToString(
 448                               strValue,
 449                               value,
 450                               n);
 451                           ConfigManager::getInstance()->initCurrentValue(propName, String(startP, n));
 452                       }
 453 dev.meetei      1.241 static void _restrictListening(
 454                           ConfigManager* configManager,
 455                           const String &listenOn,
 456                           const Uint32 &portNumberHttp,
 457                           const Boolean useSSL)
 458                       {
 459                           static Array<HostAddress> laddr = configManager ->getListenAddress( 
 460                                                                 listenOn);
 461                           for(Uint32 i = 0, n = laddr.size(); i < n; ++i)
 462                           {
 463                               if(laddr[i].getAddressType() == HostAddress::AT_IPV6)
 464                               {
 465                       #ifdef PEGASUS_ENABLE_IPV6
 466                                   _cimServer->addAcceptor(HTTPAcceptor::IPV6_CONNECTION,
 467                                           portNumberHttp, useSSL, 
 468                                           &laddr[i]);
 469                       #endif
 470                               }
 471                               else if(laddr[i].getAddressType() == HostAddress::AT_IPV4)
 472                               {
 473                                   _cimServer->addAcceptor(HTTPAcceptor::IPV4_CONNECTION,
 474 dev.meetei      1.241                     portNumberHttp, useSSL, 
 475                                           &laddr[i]);
 476                               }
 477                           }
 478                       }
 479 venkat.puvvada  1.231 
 480 mike            1.33  /////////////////////////////////////////////////////////////////////////
 481 mike            1.32  //  MAIN
 482                       //////////////////////////////////////////////////////////////////////////
 483 kumpf           1.199 
 484 mike            1.32  int main(int argc, char** argv)
 485                       {
 486 kumpf           1.196     String pegasusHome;
 487 mike            1.35      Boolean shutdownOption = false;
 488 kumpf           1.178     Boolean debugOutputOption = false;
 489 mday            1.47  
 490 kumpf           1.202     // Set Message loading to process locale
 491                           MessageLoader::_useProcessLocale = true;
 492 humberto        1.97  
 493 thilo.boehm     1.211 #ifdef PEGASUS_OS_ZOS
 494                           // Direct standard input to /dev/null,
 495                           close(STDIN_FILENO);
 496                           open("/dev/null", O_RDONLY);
 497                       
 498                           if ( setEBCDICEncoding(STDOUT_FILENO)==-1 ||
 499                                setEBCDICEncoding(STDERR_FILENO)==-1 )
 500                           {
 501 marek           1.220        PEG_TRACE_CSTRING(TRC_SERVER,Tracer::LEVEL1,
 502 thilo.boehm     1.211            "Coud not set stdout or stderr to EBCDIC encoding.");
 503                           }
 504                           // Need to initialize timezone information in the
 505                           // initial processing thread (IPT)
 506 marek           1.236     initialize_zOS_timezone();
 507 thilo.boehm     1.211 #endif
 508                       
 509 kv.le           1.140 #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
 510 kumpf           1.202     setlocale(LC_ALL, "");
 511 kv.le           1.140 #endif
 512                       
 513 tony            1.82  #ifndef PEGASUS_OS_TYPE_WINDOWS
 514 kumpf           1.38      //
 515                           // Get environment variables:
 516                           //
 517 kumpf           1.202 # if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
 518 kv.le           1.134     pegasusHome = AIX_RELEASE_PEGASUS_HOME;
 519 ouyang.jian     1.210 # elif defined(PEGASUS_OS_PASE)
 520                           const char *tmp = getenv("PEGASUS_HOME");
 521                           pegasusHome = (tmp == 0) ? PASE_DEFAULT_PEGASUS_HOME : tmp;
 522 kumpf           1.202 # elif !defined(PEGASUS_USE_RELEASE_DIRS) || \
 523 r.kieninger     1.223     defined(PEGASUS_OS_ZOS)
 524 kumpf           1.38      const char* tmp = getenv("PEGASUS_HOME");
 525                       
 526                           if (tmp)
 527                           {
 528                               pegasusHome = tmp;
 529                           }
 530 kumpf           1.202 # endif
 531 kumpf           1.38  
 532                           FileSystem::translateSlashes(pegasusHome);
 533 tony            1.82  #else
 534 kumpf           1.38  
 535 kumpf           1.202     // windows only
 536                           //setHome(pegasusHome);
 537                           pegasusHome = _cimServerProcess->getHome();
 538 tony            1.82  #endif
 539 mike            1.32  
 540 kumpf           1.199 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 541                       
 542                           // If invoked with "--executor-socket <socket>" option, then use executor.
 543                       
 544                           Executor::setSock(_extractExecutorSockOpt(argc, argv));
 545                       
 546                           // Ping executor to verify the specified socket is valid.
 547                       
 548                           if (Executor::ping() != 0)
 549                           {
 550                               MessageLoaderParms parms("src.Server.cimserver.EXECUTOR_PING_FAILED",
 551                                   "Failed to ping the executor on the specified socket.");
 552                               cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << endl;
 553                               exit(1);
 554                           }
 555                       
 556                       #endif /* !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) */
 557                       
 558 denise.eckstein 1.229         // Get help, version, status and shutdown options
 559 mike            1.35  
 560                               for (int i = 1; i < argc; )
 561                               {
 562                                   const char* arg = argv[i];
 563 kumpf           1.216             if (strcmp(arg, "--help") == 0)
 564 a.arora         1.142             {
 565 kumpf           1.216                 PrintHelp(argv[0]);
 566                                       Executor::daemonizeExecutor();
 567                                       exit(0);
 568 a.arora         1.142             }
 569 denise.eckstein 1.229             if (strcmp(arg, "--status") == 0)
 570                                   {
 571                                       int retValue = 0;
 572                                       if (_serverRunStatus.isServerRunning())
 573                                       {
 574                                           MessageLoaderParms parms(
 575                                               "src.Server.cimserver.CIMSERVER_RUNNING",
 576                                               "The CIM Server is running.");
 577                                           cout << MessageLoader::getMessage(parms) << endl;
 578                                       }
 579                                       else
 580                                       {
 581                                           MessageLoaderParms parms(
 582                                               "src.Server.cimserver.CIMSERVER_NOT_RUNNING",
 583                                               "The CIM Server is not running.");
 584                                           cout << MessageLoader::getMessage(parms) << endl;
 585                                           retValue = 2;
 586                                       }
 587                                       Executor::daemonizeExecutor();
 588                                       exit(retValue);
 589                                   }
 590 kumpf           1.216             else if (strcmp(arg, "--version") == 0)
 591 a.arora         1.142             {
 592 jim.wunderlich  1.180                 cout << _cimServerProcess->getCompleteVersion() << endl;
 593 kumpf           1.216                 Executor::daemonizeExecutor();
 594 a.arora         1.142                 exit(0);
 595                                   }
 596 mike            1.35              // Check for -option
 597 a.arora         1.142             else if (*arg == '-')
 598 mike            1.35              {
 599                                       // Get the option
 600                                       const char* option = arg + 1;
 601                       
 602                                       //
 603                                       // Check to see if user asked for the version (-v option):
 604                                       //
 605 tony            1.83                  if (*option == OPTION_VERSION &&
 606                                           strlen(option) == 1)
 607 mike            1.35                  {
 608 jim.wunderlich  1.180                     cout << _cimServerProcess->getCompleteVersion() << endl;
 609 kumpf           1.216                     Executor::daemonizeExecutor();
 610 mike            1.35                      exit(0);
 611                                       }
 612                                       //
 613                                       // Check to see if user asked for help (-h option):
 614                                       //
 615 tony            1.83                  else if (*option == OPTION_HELP &&
 616                                               (strlen(option) == 1))
 617 mike            1.35                  {
 618                                           PrintHelp(argv[0]);
 619 kumpf           1.216                     Executor::daemonizeExecutor();
 620 mike            1.35                      exit(0);
 621                                       }
 622 kumpf           1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 623 tony            1.83                  else if (*option == OPTION_HOME &&
 624                                               (strlen(option) == 1))
 625 mike            1.35                  {
 626 kumpf           1.60                      if (i + 1 < argc)
 627 mike            1.35                      {
 628                                               pegasusHome.assign(argv[i + 1]);
 629                                           }
 630                                           else
 631                                           {
 632 humberto        1.99                          String opt(option);
 633 kumpf           1.202                         MessageLoaderParms parms(
 634                                                   "src.Server.cimserver.MISSING_ARGUMENT",
 635                                                   "Missing argument for option -$0",
 636                                                   opt);
 637 h.sterling      1.153                         cout << MessageLoader::getMessage(parms) << endl;
 638 kumpf           1.216                         exit(1);
 639 mike            1.35                      }
 640                       
 641                                           memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 642                                           argc -= 2;
 643                                       }
 644 kumpf           1.63  #endif
 645 kumpf           1.48                  //
 646 kumpf           1.178                 // Check to see if user asked for debug output (-X option):
 647 kumpf           1.48                  //
 648 kumpf           1.178                 else if (*option == OPTION_DEBUGOUTPUT &&
 649 tony            1.83                          (strlen(option) == 1))
 650 kumpf           1.48                  {
 651 kumpf           1.178                     MessageLoaderParms parms(
 652                                               "src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 653                                               "Unsupported debug output option is enabled.");
 654 h.sterling      1.153                     cout << MessageLoader::getMessage(parms) << endl;
 655 kumpf           1.178 
 656                                           debugOutputOption = true;
 657                       
 658                       #if defined(PEGASUS_OS_HPUX)
 659                                           System::bindVerbose = true;
 660                       #endif
 661                       
 662 kumpf           1.48                      // remove the option from the command line
 663                                           memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 664 david.dillard   1.165                     argc--;
 665 kumpf           1.48                  }
 666 mike            1.35                  //
 667                                       // Check to see if user asked for shutdown (-s option):
 668                                       //
 669 tony            1.82                  else if (*option == OPTION_SHUTDOWN &&
 670                                               (strlen(option) == 1))
 671 mike            1.35                  {
 672                                           //
 673 kumpf           1.52                      // Check to see if shutdown has already been specified:
 674 mike            1.35                      //
 675 kumpf           1.52                      if (shutdownOption)
 676 mike            1.35                      {
 677 kumpf           1.202                         MessageLoaderParms parms(
 678                                                   "src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 679                                                   "Duplicate shutdown option specified.");
 680 david.dillard   1.165 
 681 humberto        1.97                          cout << MessageLoader::getMessage(parms) << endl;
 682 kumpf           1.216                         exit(1);
 683 mike            1.35                      }
 684                       
 685 kumpf           1.52                      shutdownOption = true;
 686 david.dillard   1.165 
 687 mike            1.35                      // remove the option from the command line
 688                                           memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 689 david.dillard   1.165                     argc--;
 690 mike            1.35                  }
 691                                       else
 692                                           i++;
 693                                   }
 694                                   else
 695                                       i++;
 696 mike            1.32          }
 697 mike            1.35  
 698 kumpf           1.38      //
 699                           // Set the value for pegasusHome property
 700                           //
 701                           ConfigManager::setPegasusHome(pegasusHome);
 702 mike            1.32  
 703 mike            1.35      //
 704 carolann.graves 1.171     // Do the platform specific run
 705 s.hills         1.117     //
 706                       
 707 kumpf           1.178     return _cimServerProcess->platform_run(
 708                               argc, argv, shutdownOption, debugOutputOption);
 709 s.hills         1.117 }
 710                       
 711 h.sterling      1.153 void CIMServerProcess::cimserver_stop()
 712                       {
 713                           _cimServer->shutdownSignal();
 714                       }
 715 s.hills         1.117 
 716                       //
 717                       // The main, common, running code
 718                       //
 719 david.dillard   1.165 // NOTE: Do NOT call exit().  Use return(), otherwise some platforms
 720 s.hills         1.117 // will fail to shutdown properly/cleanly.
 721                       //
 722 david.dillard   1.165 // TODO: Current change minimal for platform "service" shutdown bug fixes.
 723 carolann.graves 1.171 // Perhaps further extract out common stuff and put into main(), put
 724 david.dillard   1.165 // daemon stuff into platform specific platform_run(), etc.
 725                       // Note: make sure to not put error handling stuff that platform
 726 carolann.graves 1.171 // specific runs may need to deal with better (instead of exit(), etc).
 727 s.hills         1.117 //
 728                       
 729 kumpf           1.178 int CIMServerProcess::cimserver_run(
 730                           int argc,
 731                           char** argv,
 732                           Boolean shutdownOption,
 733                           Boolean debugOutputOption)
 734 s.hills         1.117 {
 735                           Boolean daemonOption = false;
 736                       
 737 ouyang.jian     1.206 #if defined (PEGASUS_OS_PASE) && !defined (PEGASUS_DEBUG)
 738                           // PASE have itself regular for checking privileged user
 739                           if (!System::isPrivilegedUser("*CURRENT  "))
 740                           {
 741                               MessageLoaderParms parms(
 742                                       "src.Server.cimserver.NO_AUTHORITY.PEGASUS_OS_PASE",
 743                                       "The caller should be a privileged user,"
 744                                       " or the server will not run.");
 745                               cerr << MessageLoader::getMessage(parms) << endl;
 746                               exit (1);
 747                           }
 748                           char jobName[11];
 749                           // this function only can be found in PASE environment
 750                           umeGetJobName(jobName, false);
 751                           if (strncmp("QUMECIMOM ", jobName, 10) != 0
 752                                   && strncmp("QUMEENDCIM", jobName, 10) != 0)
 753                           {
 754                               MessageLoaderParms parms(
 755                                       "src.Server.cimserver.NOT_OFFICIAL_START.PEGASUS_OS_PASE",
 756                                       "cimserver can not be started by user.\nServer will not run.");
 757                               cerr << MessageLoader::getMessage(parms) << endl;
 758 ouyang.jian     1.206         exit (1);
 759                           }
 760                       
 761 kumpf           1.228     // Direct standard input, output, and error to /dev/null,
 762 ouyang.jian     1.206     // PASE run this job in background, any output in not allowed
 763                           freopen("/dev/null", "r", stdin);
 764                           freopen("/dev/null", "w", stdout);
 765                           freopen("/dev/null", "w", stderr);
 766                       #endif
 767                       
 768 s.hills         1.117     //
 769 mike            1.35      // Get an instance of the Config Manager.
 770                           //
 771 kumpf           1.203     ConfigManager* configManager = ConfigManager::getInstance();
 772 kumpf           1.136     configManager->useConfigFiles = true;
 773 mike            1.35  
 774 mike            1.32      try
 775                           {
 776 kumpf           1.203         //
 777                               // Get options (from command line and from configuration file); this
 778                               // removes corresponding options and their arguments from the command
 779                               // line.  NOTE: If shutdownOption=true, the contents of current config
 780                               // file are not overwritten by the planned config file.
 781                               //
 782 mateus.baur     1.193         GetOptions(configManager, argc, argv, shutdownOption);
 783 kumpf           1.127 
 784 kumpf           1.203         //
 785                               // Initialize the message home directory in the MessageLoader.
 786                               // This is the default directory where the resource bundles are found.
 787                               //
 788                               MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
 789                                   ConfigManager::getInstance()->getCurrentValue("messageDir")));
 790 kumpf           1.86  
 791 ouyang.jian     1.224 #if !defined(PEGASUS_USE_SYSLOGS)
 792                               String logsDirectory = ConfigManager::getHomedPath(
 793                                   configManager->getCurrentValue("logdir"));
 794                       
 795                               // Set up the Logger.  This does not open the logs.
 796                               // Might be more logical to clean before set.
 797                               Logger::setHomeDirectory(logsDirectory);
 798                       #endif
 799                       
 800                       
 801 ouyang.jian     1.206 #ifdef PEGASUS_OS_PASE
 802 ouyang.jian     1.224         /* write job log to tell where pegasus log is.*/
 803                               if(logsDirectory.size() > 0)
 804                                   // this function only can be found in PASE environment
 805                                   logPegasusDir2joblog(logsDirectory.getCString());
 806                               else
 807                                   logPegasusDir2joblog(".");
 808                       
 809                               // set ccsid to unicode for entire job
 810                               // ccsid is globolization mechanism in PASE environment
 811                               if (_SETCCSID(1208) == -1)
 812                               {
 813                                   MessageLoaderParms parms(
 814                                           "src.Server.cimserver.SET_CCSID_ERROR.PEGASUS_OS_PASE",
 815                                           "Failed to set CCSID, server will stop.");
 816                                   cerr << MessageLoader::getMessage(parms) << endl;
 817                                   Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::FATAL,
 818                                           parms);
 819                                   exit (1);
 820                               }
 821 ouyang.jian     1.206 
 822 ouyang.jian     1.224         char fullJobName[29];
 823                               umeGetJobName(fullJobName, true);
 824                               Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
 825                                       Logger::INFORMATION,
 826                                       MessageLoaderParms(
 827                                           "src.Server.cimserver.SERVER_JOB_NAME.PEGASUS_OS_PASE",
 828                                           "CIM Server's Job Name is: $0", fullJobName));
 829 ouyang.jian     1.206 #endif
 830                       
 831 kumpf           1.221 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
 832                               // Make sure at least one connection is enabled
 833 ouyang.jian     1.206 
 834 kumpf           1.221         Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
 835                                   configManager->getCurrentValue("enableHttpConnection"));
 836                               Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
 837                                   configManager->getCurrentValue("enableHttpsConnection"));
 838                       
 839                               if (!enableHttpConnection && !enableHttpsConnection)
 840                               {
 841                                   MessageLoaderParms parms(
 842 ouyang.jian     1.206                 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 843                                       "Neither HTTP nor HTTPS connection is enabled."
 844 kumpf           1.221                     "  CIMServer will not be started.");
 845 kumpf           1.222             Logger::put_l(
 846                                       Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 847                                       parms);
 848 kumpf           1.221             cerr << MessageLoader::getMessage(parms) << endl;
 849                                   return 1;
 850                               }
 851 ouyang.jian     1.206 #endif
 852 kumpf           1.221 
 853 mike            1.35          //
 854 kumpf           1.187         // Check to see if we should start Pegasus as a daemon
 855 mike            1.35          //
 856 kumpf           1.187         daemonOption = ConfigManager::parseBooleanValue(
 857                                   configManager->getCurrentValue("daemon"));
 858 david.dillard   1.165 
 859 kumpf           1.215         if ((Executor::detectExecutor() == 0) && (daemonOption == false))
 860                               {
 861                                   MessageLoaderParms parms(
 862                                       "src.Server.cimserver.PRIVSEP_REQUIRES_DAEMON",
 863                                       "Warning: The configuration setting daemon=false is ignored "
 864                                           "with privilege separation enabled.");
 865                                   cerr << MessageLoader::getMessage(parms) << endl;
 866                                   daemonOption = true;
 867                               }
 868                       
 869 kumpf           1.36          //
 870 david.dillard   1.165         // Check to see if we need to shutdown CIMOM
 871 mike            1.35          //
 872                               if (shutdownOption)
 873                               {
 874 r.kieninger     1.240 #if defined(PEGASUS_OS_ZOS) && defined(PEGASUS_ZOS_SECURITY)
 875                                   // This checks whether user is authorized to stop the
 876                                   // CIM Server. When unauthorized a message is logged to
 877                                   // to the user and program exits.
 878                                   shutdownCheckProfileCIMSERVclassWBEM();
 879                                   // Depending on the success of the previous check we may not
 880                                   // reach this code!!!
 881                       #endif
 882 david.dillard   1.165             String configTimeout =
 883 kumpf           1.60                  configManager->getCurrentValue("shutdownTimeout");
 884 kumpf           1.202             Uint32 timeoutValue =
 885                                       strtol(configTimeout.getCString(), (char **)0, 10);
 886 david.dillard   1.165 
 887 kumpf           1.198             ServerShutdownClient serverShutdownClient(&_serverRunStatus);
 888                                   serverShutdownClient.shutdown(timeoutValue);
 889 kumpf           1.45  
 890 kumpf           1.198             MessageLoaderParms parms(
 891                                       "src.Server.cimserver.SERVER_STOPPED",
 892                                       "CIM Server stopped.");
 893 humberto        1.106 
 894 humberto        1.97              cout << MessageLoader::getMessage(parms) << endl;
 895 kumpf           1.202             return 0;
 896 mike            1.35          }
 897 mike            1.32  
 898 kumpf           1.198 #if defined(PEGASUS_DEBUG) && !defined(PEGASUS_USE_SYSLOGS)
 899 kumpf           1.36          // Leave this in until people get familiar with the logs.
 900 humberto        1.97          MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
 901 h.sterling      1.153                                  "Logs Directory = ");
 902 humberto        1.97          cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
 903 kumpf           1.57  #endif
 904 mike            1.32      }
 905 kumpf           1.203     catch (Exception& e)
 906 mike            1.32      {
 907 kumpf           1.203         MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 908                                   "cimserver not started: $0", e.getMessage());
 909 kumpf           1.222         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 910                                   parms);
 911 kumpf           1.203         cerr << MessageLoader::getMessage(parms) << endl;
 912                       
 913                               return 1;
 914 marek           1.186     }
 915 david           1.85  
 916 thilo.boehm     1.237 #if defined(PEGASUS_OS_ZOS) 
 917                       #  if defined(PEGASUS_ZOS_SECURITY)
 918 marek           1.186     startupCheckBPXServer(true);
 919                           startupCheckProfileCIMSERVclassWBEM();
 920                           startupEnableMSC();
 921 thilo.boehm     1.237 #  endif
 922                           startupWaitForTCPIP();
 923 david           1.85  #endif
 924 mike            1.32  
 925 kumpf           1.139 #if defined(PEGASUS_DEBUG)
 926 mike            1.32      // Put out startup up message.
 927 kumpf           1.202     cout << _cimServerProcess->getProductName() << " " <<
 928                               _cimServerProcess->getCompleteVersion() << endl;
 929 humberto        1.97  #endif
 930                       
 931 marek           1.242     // Force initialization of hostname and fullyQualifiedHostName through
 932                           // retrieving current value from Configuration Manager
 933                           // - this will run getCurrentValue() in DefaultPropertyOwner.cpp
 934                           configManager->getCurrentValue("hostname");
 935                           configManager->getCurrentValue("fullyQualifiedHostName");
 936                       
 937 kumpf           1.202     // reset message loading to NON-process locale
 938                           MessageLoader::_useProcessLocale = false;
 939 mike            1.32  
 940 kumpf           1.137     // Get the parent's PID before forking
 941 kumpf           1.198     _serverRunStatus.setParentPid(System::getPID());
 942 david.dillard   1.165 
 943 kumpf           1.202     // Do not fork when using privilege separation (executor will daemonize
 944                           // itself later).
 945 kumpf           1.63      if (daemonOption)
 946                           {
 947 kumpf           1.202         if (-1 == _cimServerProcess->cimserver_fork())
 948                                   return -1;
 949 kumpf           1.63      }
 950 chuck           1.66  
 951 chuck           1.96      // Now we are after the fork...
 952                           // Create a dummy Thread object that can be used to store the
 953 kumpf           1.176     // AcceptLanguageList object for CIM requests that are serviced
 954 chuck           1.96      // by this thread (initial thread of server).  Need to do this
 955                           // because this thread is not in a ThreadPool, but is used
 956                           // to service CIM requests.
 957                           // The run function for the dummy Thread should never be called,
 958 konrad.r        1.166     dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
 959 david.dillard   1.165     Thread::setCurrent(dummyInitialThread);
 960 kumpf           1.202     try
 961                           {
 962 kumpf           1.214         Thread::setLanguages(LanguageParser::getDefaultAcceptLanguages());
 963 kumpf           1.202     }
 964                           catch (InvalidAcceptLanguageHeader& e)
 965                           {
 966 kumpf           1.203         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 967 kumpf           1.222             MessageLoaderParms(
 968                                       "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
 969                                       "Could not convert the system process locale into a valid "
 970                                           "AcceptLanguage format."));
 971 kumpf           1.203         Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 972                                   e.getMessage());
 973 humberto        1.108     }
 974 david.dillard   1.165 
 975 kumpf           1.167 #ifndef PEGASUS_OS_TYPE_WINDOWS
 976                           umask(S_IRWXG|S_IRWXO);
 977                       #endif
 978 mday            1.62  
 979 kumpf           1.203     // Start up the CIM Server
 980 mateus.baur     1.175 
 981 kumpf           1.203     try
 982                           {
 983 mateus.baur     1.175 #if defined(PEGASUS_OS_TYPE_UNIX)
 984 kumpf           1.203         //
 985                               // Lock the CIMSERVER_LOCK_FILE during CIM Server start-up to prevent
 986                               // concurrent writes to this file by multiple cimserver processes
 987                               // starting at the same time.
 988                               //
 989                               CString startupLockFileName = ConfigManager::getHomedPath(
 990 kumpf           1.204             PEGASUS_CIMSERVER_START_LOCK_FILE).getCString();
 991 kumpf           1.203 
 992                               // Make sure the start-up lock file exists
 993                               FILE* startupLockFile;
 994                               if ((startupLockFile = fopen(startupLockFileName, "w")) != 0)
 995                               {
 996                                   fclose(startupLockFile);
 997                               }
 998 kumpf           1.202 
 999 kumpf           1.203         AutoFileLock fileLock(startupLockFileName);
1000                       #endif
1001 kumpf           1.202 
1002 kumpf           1.203 #if defined(PEGASUS_OS_TYPE_UNIX) || defined(PEGASUS_OS_VMS)
1003                               //
1004                               // Check if a CIM Server is already running.  If so, print an error
1005                               // message and notify the parent process (if there is one) to terminate
1006                               //
1007                               if (_serverRunStatus.isServerRunning())
1008                               {
1009                                   MessageLoaderParms parms(
1010                                       "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1011                                       "Unable to start CIMServer. CIMServer is already running.");
1012 kumpf           1.222             Logger::put_l(
1013 kumpf           1.203                 Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
1014 kumpf           1.222                 parms);
1015 kumpf           1.203             cerr << MessageLoader::getMessage(parms) << endl;
1016 mateus.baur     1.175 
1017 kumpf           1.203             if (daemonOption)
1018                                   {
1019                                       _cimServerProcess->notify_parent(1);
1020                                   }
1021 kumpf           1.79  
1022 kumpf           1.203             return 1;
1023                               }
1024 kumpf           1.79  
1025 kumpf           1.198         //
1026 kumpf           1.203         // Declare ourselves as the running CIM Server process, and write our
1027                               // PID to the PID file.
1028 kumpf           1.79          //
1029 kumpf           1.203         _serverRunStatus.setServerRunning();
1030                       #endif
1031                       
1032                               // Create and initialize the CIMServer object
1033                       
1034                               _cimServer = new CIMServer();
1035                       
1036                               Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
1037                                   configManager->getCurrentValue("enableHttpConnection"));
1038                               Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
1039                                   configManager->getCurrentValue("enableHttpsConnection"));
1040                       
1041                       #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1042                               // Make sure at least one connection is enabled
1043                               if (!enableHttpConnection && !enableHttpsConnection)
1044 kumpf           1.198         {
1045 kumpf           1.203             MessageLoaderParms parms(
1046                                       "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
1047                                       "Neither HTTP nor HTTPS connection is enabled.");
1048                                   throw Exception(parms);
1049 kumpf           1.198         }
1050 kumpf           1.63  #endif
1051 kumpf           1.51  
1052 venkat.puvvada  1.208         Boolean addIP6Acceptor = false;
1053                               Boolean addIP4Acceptor = false;
1054                       
1055                       #ifdef PEGASUS_OS_TYPE_WINDOWS
1056                               addIP4Acceptor = true;
1057                       #endif
1058                       
1059                       #ifdef PEGASUS_ENABLE_IPV6
1060                               // If IPv6 stack is disabled swicth to IPv4 stack.
1061                               if (System::isIPv6StackActive())
1062                               {
1063                                   addIP6Acceptor = true;
1064                               }
1065                               else
1066                               {
1067 marek           1.233             PEG_TRACE_CSTRING(TRC_SERVER,Tracer::LEVEL4,
1068 venkat.puvvada  1.208                 "IPv6 stack is not active, using IPv4 socket.");
1069                               }
1070                       #endif
1071                               if (!addIP6Acceptor)
1072                               {
1073                                   addIP4Acceptor = true;
1074                               }
1075                       
1076 kumpf           1.203         // The server HTTP and HTTPS ports are determined via this algorithm:
1077                               // 1) If the user explicitly specified a port, use it.
1078                               // 2) If the user did not specify a port, get the port from the
1079                               //    services file.
1080                               // 3) If no value is specified in the services file, use the IANA WBEM
1081                               //    default port.
1082                               // Note that 2 and 3 are done within the System::lookupPort method
1083                               // An empty string from the ConfigManager implies that the user did not
1084                               // specify a port.
1085 kumpf           1.41  
1086 kumpf           1.86          if (enableHttpConnection)
1087                               {
1088 kumpf           1.203             Uint32 portNumberHttp = 0;
1089                                   String httpPort = configManager->getCurrentValue("httpPort");
1090                                   if (httpPort == String::EMPTY)
1091                                   {
1092                                       //
1093                                       // Look up the WBEM-HTTP port number
1094                                       //
1095                                       portNumberHttp = System::lookupPort(
1096                                           WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1097 venkat.puvvada  1.231                 _initConfigProperty("httpPort", portNumberHttp);
1098 kumpf           1.203             }
1099                                   else
1100                                   {
1101                                       //
1102                                       // user-specified
1103                                       //
1104                                       CString portString = httpPort.getCString();
1105                                       char* end = 0;
1106                                       portNumberHttp = strtol(portString, &end, 10);
1107                                       if (!(end != 0 && *end == '\0'))
1108                                       {
1109                                           throw InvalidPropertyValue("httpPort", httpPort);
1110                                       }
1111                                   }
1112                       
1113 dev.meetei      1.241             String listenOn = configManager->getCurrentValue("listenAddress");
1114                                   if(String::equalNoCase(listenOn, "All"))
1115 venkat.puvvada  1.208             {
1116 dev.meetei      1.241                 if (addIP6Acceptor)
1117                                       {
1118                                           _cimServer->addAcceptor(HTTPAcceptor::IPV6_CONNECTION,
1119                                               portNumberHttp, false);
1120                                       }
1121                                       if (addIP4Acceptor)
1122                                       {
1123                                           _cimServer->addAcceptor(HTTPAcceptor::IPV4_CONNECTION,
1124                                               portNumberHttp, false);
1125                                       }
1126 venkat.puvvada  1.208             }
1127 dev.meetei      1.241             else // Restricted listening
1128 venkat.puvvada  1.208             {
1129 dev.meetei      1.241                 _restrictListening(
1130                                           configManager, listenOn, portNumberHttp, false);
1131 venkat.puvvada  1.208             }
1132 dev.meetei      1.241 
1133 denise.eckstein 1.225             // The port number is converted to a string to avoid the
1134                                   //  addition of localized characters (e.g., "5,988").
1135 denise.eckstein 1.218             char scratchBuffer[22];
1136                                   Uint32 n;
1137                                   const char * portNumberHttpStr = Uint32ToString(
1138 kumpf           1.228                 scratchBuffer, portNumberHttp, n);
1139 kumpf           1.203             MessageLoaderParms parms(
1140 kumpf           1.198                 "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1141 denise.eckstein 1.218                 "Listening on HTTP port $0.", portNumberHttpStr);
1142 kumpf           1.222             Logger::put_l(
1143 kumpf           1.203                 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1144 kumpf           1.222                 parms);
1145 kumpf           1.203 #if defined(PEGASUS_DEBUG)
1146                                   cout << MessageLoader::getMessage(parms) << endl;
1147                       #endif
1148 kumpf           1.86          }
1149 kumpf           1.198 
1150 kumpf           1.86          if (enableHttpsConnection)
1151                               {
1152 kumpf           1.203             Uint32 portNumberHttps = 0;
1153                                   String httpsPort = configManager->getCurrentValue("httpsPort");
1154                                   if (httpsPort == String::EMPTY)
1155                                   {
1156                                       //
1157                                       // Look up the WBEM-HTTPS port number
1158                                       //
1159                                       portNumberHttps = System::lookupPort(
1160                                           WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1161 venkat.puvvada  1.231                 _initConfigProperty("httpsPort", portNumberHttps);
1162 kumpf           1.203             }
1163                                   else
1164                                   {
1165                                       //
1166                                       // user-specified
1167                                       //
1168                                       CString portString = httpsPort.getCString();
1169                                       char* end = 0;
1170                                       portNumberHttps = strtol(portString, &end, 10);
1171                                       if (!(end != 0 && *end == '\0'))
1172                                       {
1173                                           throw InvalidPropertyValue("httpsPort", httpsPort);
1174                                       }
1175                                   }
1176 dev.meetei      1.241             String listenOn = configManager->getCurrentValue("listenAddress");
1177                                   if(String::equalNoCase(listenOn, "All"))
1178 kumpf           1.228             {
1179 dev.meetei      1.241                 if (addIP6Acceptor)
1180                                       {
1181                                           _cimServer->addAcceptor(HTTPAcceptor::IPV6_CONNECTION,
1182                                               portNumberHttps, true);
1183                                       }
1184                                       if (addIP4Acceptor)
1185                                       {
1186                                           _cimServer->addAcceptor(HTTPAcceptor::IPV4_CONNECTION,
1187                                               portNumberHttps, true);
1188                                       }
1189 venkat.puvvada  1.208             }
1190 dev.meetei      1.241             else //Restricted
1191 venkat.puvvada  1.208             {
1192 dev.meetei      1.241                 _restrictListening(
1193                                           configManager, listenOn, portNumberHttps, true);
1194 venkat.puvvada  1.208             }
1195 dev.meetei      1.241 
1196 denise.eckstein 1.225             // The port number is converted to a string to avoid the
1197                                   //  addition of localized characters (e.g., "5,989").
1198 denise.eckstein 1.218             char scratchBuffer[22];
1199                                   Uint32 n;
1200                                   const char * portNumberHttpsStr = Uint32ToString(
1201 kumpf           1.228                 scratchBuffer, portNumberHttps, n);
1202 kumpf           1.203             MessageLoaderParms parms(
1203 kumpf           1.198                 "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1204 denise.eckstein 1.218                 "Listening on HTTPS port $0.", portNumberHttpsStr);
1205 kumpf           1.222             Logger::put_l(
1206 kumpf           1.203                 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1207 kumpf           1.222                 parms);
1208 kumpf           1.203 #if defined(PEGASUS_DEBUG)
1209                                   cout << MessageLoader::getMessage(parms) << endl;
1210                       #endif
1211 kumpf           1.86          }
1212 kumpf           1.135 
1213 h.sterling      1.159 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1214 kumpf           1.203         {
1215 dave.sudlik     1.205             _cimServer->addAcceptor(HTTPAcceptor::LOCAL_CONNECTION, 0, false);
1216 kumpf           1.86  
1217 kumpf           1.198             MessageLoaderParms parms(
1218 kumpf           1.203                 "src.Server.cimserver.LISTENING_ON_LOCAL",
1219                                       "Listening on local connection socket.");
1220 kumpf           1.222             Logger::put_l(
1221 kumpf           1.203                 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1222 kumpf           1.222                 parms);
1223 kumpf           1.203 # if defined(PEGASUS_DEBUG)
1224 h.sterling      1.153             cout << MessageLoader::getMessage(parms) << endl;
1225 kumpf           1.203 # endif
1226 kumpf           1.86          }
1227 david           1.85  #endif
1228 mike            1.35  
1229 kumpf           1.198         _cimServer->bind();
1230 kumpf           1.199 
1231 kumpf           1.198         // notify parent process (if there is a parent process) to terminate
1232 konrad.r        1.95          // so user knows that there is cimserver ready to serve CIM requests.
1233 kumpf           1.198         if (daemonOption)
1234                               {
1235                                   _cimServerProcess->notify_parent(0);
1236                               }
1237 mike            1.35  
1238 kumpf           1.139 #if defined(PEGASUS_DEBUG)
1239 kumpf           1.202         cout << "Started. " << endl;
1240 kumpf           1.63  #endif
1241 david.dillard   1.165 
1242 kumpf           1.54          // Put server started message to the logger
1243 kumpf           1.143         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1244                                   Logger::INFORMATION,
1245 kumpf           1.222             MessageLoaderParms(
1246                                       "src.Server.cimserver.STARTED_VERSION",
1247                                       "Started $0 version $1.",
1248                                       _cimServerProcess->getProductName(),
1249                                       _cimServerProcess->getCompleteVersion()));
1250 kumpf           1.45  
1251 marek           1.190 #if defined(PEGASUS_OS_TYPE_UNIX) && !defined(PEGASUS_OS_ZOS)
1252 kumpf           1.178         if (daemonOption && !debugOutputOption)
1253 kumpf           1.202         {
1254 kumpf           1.178             // Direct standard input, output, and error to /dev/null,
1255                                   // since we are running as a daemon.
1256 thilo.boehm     1.211             close(STDIN_FILENO);
1257 kumpf           1.178             open("/dev/null", O_RDONLY);
1258 thilo.boehm     1.211             close(STDOUT_FILENO);
1259 kumpf           1.178             open("/dev/null", O_RDWR);
1260 thilo.boehm     1.211             close(STDERR_FILENO);
1261 kumpf           1.178             open("/dev/null", O_RDWR);
1262                               }
1263                       #endif
1264 kumpf           1.203     }
1265                           catch (Exception& e)
1266                           {
1267                               MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
1268                                   "cimserver not started: $0", e.getMessage());
1269 kumpf           1.222         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1270                                   parms);
1271 kumpf           1.203         cerr << MessageLoader::getMessage(parms) << endl;
1272 kumpf           1.178 
1273 s.kodali        1.234         deleteCIMServer();
1274                       
1275 kumpf           1.203         //
1276                               // notify parent process (if there is a parent process) to terminate
1277                               //
1278                               if (daemonOption)
1279                                   _cimServerProcess->notify_parent(1);
1280                       
1281                               return 1;
1282                           }
1283                       
1284                           // Run the main CIM Server loop
1285                       
1286                           try
1287                           {
1288 r.kieninger     1.223 #if defined(PEGASUS_OS_ZOS)
1289 thilo.boehm     1.185 
1290 kumpf           1.202         // ARM is a z/OS internal restart facility.
1291                               // This is a z/OS specific change.
1292 thilo.boehm     1.185 
1293                               // Instatiating the automatic restart manager for zOS
1294                               ARM_zOS automaticRestartManager;
1295                       
1296                               // register to zOS ARM
1297                               automaticRestartManager.Register();
1298                       
1299                       #endif
1300                       
1301 marek           1.217 #ifdef PEGASUS_ENABLE_SLP
1302                               _cimServer->startSLPProvider();
1303 kumpf           1.228 #endif
1304 venkat.puvvada  1.232         _cimServer->initComplete();
1305                       
1306 mike            1.35          //
1307                               // Loop to call CIMServer's runForever() method until CIMServer
1308                               // has been shutdown
1309                               //
1310 kumpf           1.202         while (!_cimServer->terminated())
1311                               {
1312                                   _cimServer->runForever();
1313                               }
1314 carson.hovey    1.157 
1315 kumpf           1.45          //
1316                               // normal termination
1317 carson.hovey    1.157         //
1318 kumpf           1.203 
1319 r.kieninger     1.223 #if defined(PEGASUS_OS_ZOS)
1320 thilo.boehm     1.185 
1321 kumpf           1.202         // ARM is a z/OS internal restart facility.
1322                               // This is a z/OS specific change.
1323 thilo.boehm     1.185 
1324                               // register to zOS ARM
1325                               automaticRestartManager.DeRegister();
1326                       
1327                       #endif
1328 kumpf           1.143 
1329 kumpf           1.54          // Put server shutdown message to the logger
1330 kumpf           1.222         Logger::put_l(
1331                                   Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1332                                   MessageLoaderParms(
1333                                       "src.Server.cimserver.STOPPED",
1334                                       "$0 stopped.", _cimServerProcess->getProductName()));
1335 mike            1.32      }
1336 kumpf           1.202     catch (Exception& e)
1337 marek           1.195     {
1338 kumpf           1.202         MessageLoaderParms parms(
1339 marek           1.195             "src.Server.cimserver.ERROR",
1340 kumpf           1.202             "Error: $0",
1341                                   e.getMessage());
1342 kumpf           1.222         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1343                                   parms);
1344 kumpf           1.203         cerr << MessageLoader::getMessage(parms) << endl;
1345 marek           1.195 
1346                               deleteCIMServer();
1347                               return 1;
1348                           }
1349 mike            1.32  
1350 h.sterling      1.156     deleteCIMServer();
1351 mike            1.32      return 0;
1352                       }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2