(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 karl            1.237.2.2 #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 karl            1.237.2.2 #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 karl            1.237.2.1     _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                           
 454 mike            1.33      /////////////////////////////////////////////////////////////////////////
 455 mike            1.32      //  MAIN
 456                           //////////////////////////////////////////////////////////////////////////
 457 kumpf           1.199     
 458 mike            1.32      int main(int argc, char** argv)
 459                           {
 460 kumpf           1.196         String pegasusHome;
 461 mike            1.35          Boolean shutdownOption = false;
 462 kumpf           1.178         Boolean debugOutputOption = false;
 463 mday            1.47      
 464 kumpf           1.202         // Set Message loading to process locale
 465                               MessageLoader::_useProcessLocale = true;
 466 humberto        1.97      
 467 thilo.boehm     1.211     #ifdef PEGASUS_OS_ZOS
 468                               // Direct standard input to /dev/null,
 469                               close(STDIN_FILENO);
 470                               open("/dev/null", O_RDONLY);
 471                           
 472                               if ( setEBCDICEncoding(STDOUT_FILENO)==-1 ||
 473                                    setEBCDICEncoding(STDERR_FILENO)==-1 )
 474                               {
 475 marek           1.220            PEG_TRACE_CSTRING(TRC_SERVER,Tracer::LEVEL1,
 476 thilo.boehm     1.211                "Coud not set stdout or stderr to EBCDIC encoding.");
 477                               }
 478                               // Need to initialize timezone information in the
 479                               // initial processing thread (IPT)
 480 marek           1.236         initialize_zOS_timezone();
 481 thilo.boehm     1.211     #endif
 482                           
 483 kv.le           1.140     #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
 484 kumpf           1.202         setlocale(LC_ALL, "");
 485 kv.le           1.140     #endif
 486                           
 487 tony            1.82      #ifndef PEGASUS_OS_TYPE_WINDOWS
 488 kumpf           1.38          //
 489                               // Get environment variables:
 490                               //
 491 kumpf           1.202     # if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
 492 kv.le           1.134         pegasusHome = AIX_RELEASE_PEGASUS_HOME;
 493 ouyang.jian     1.210     # elif defined(PEGASUS_OS_PASE)
 494                               const char *tmp = getenv("PEGASUS_HOME");
 495                               pegasusHome = (tmp == 0) ? PASE_DEFAULT_PEGASUS_HOME : tmp;
 496 kumpf           1.202     # elif !defined(PEGASUS_USE_RELEASE_DIRS) || \
 497 r.kieninger     1.223         defined(PEGASUS_OS_ZOS)
 498 kumpf           1.38          const char* tmp = getenv("PEGASUS_HOME");
 499                           
 500                               if (tmp)
 501                               {
 502                                   pegasusHome = tmp;
 503                               }
 504 kumpf           1.202     # endif
 505 kumpf           1.38      
 506                               FileSystem::translateSlashes(pegasusHome);
 507 tony            1.82      #else
 508 kumpf           1.38      
 509 kumpf           1.202         // windows only
 510                               //setHome(pegasusHome);
 511                               pegasusHome = _cimServerProcess->getHome();
 512 tony            1.82      #endif
 513 mike            1.32      
 514 kumpf           1.199     #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 515                           
 516                               // If invoked with "--executor-socket <socket>" option, then use executor.
 517                           
 518                               Executor::setSock(_extractExecutorSockOpt(argc, argv));
 519                           
 520                               // Ping executor to verify the specified socket is valid.
 521                           
 522                               if (Executor::ping() != 0)
 523                               {
 524                                   MessageLoaderParms parms("src.Server.cimserver.EXECUTOR_PING_FAILED",
 525                                       "Failed to ping the executor on the specified socket.");
 526                                   cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << endl;
 527                                   exit(1);
 528                               }
 529                           
 530                           #endif /* !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) */
 531                           
 532 denise.eckstein 1.229             // Get help, version, status and shutdown options
 533 mike            1.35      
 534                                   for (int i = 1; i < argc; )
 535                                   {
 536                                       const char* arg = argv[i];
 537 kumpf           1.216                 if (strcmp(arg, "--help") == 0)
 538 a.arora         1.142                 {
 539 kumpf           1.216                     PrintHelp(argv[0]);
 540                                           Executor::daemonizeExecutor();
 541                                           exit(0);
 542 a.arora         1.142                 }
 543 denise.eckstein 1.229                 if (strcmp(arg, "--status") == 0)
 544                                       {
 545                                           int retValue = 0;
 546                                           if (_serverRunStatus.isServerRunning())
 547                                           {
 548                                               MessageLoaderParms parms(
 549                                                   "src.Server.cimserver.CIMSERVER_RUNNING",
 550                                                   "The CIM Server is running.");
 551                                               cout << MessageLoader::getMessage(parms) << endl;
 552                                           }
 553                                           else
 554                                           {
 555                                               MessageLoaderParms parms(
 556                                                   "src.Server.cimserver.CIMSERVER_NOT_RUNNING",
 557                                                   "The CIM Server is not running.");
 558                                               cout << MessageLoader::getMessage(parms) << endl;
 559                                               retValue = 2;
 560                                           }
 561                                           Executor::daemonizeExecutor();
 562                                           exit(retValue);
 563                                       }
 564 kumpf           1.216                 else if (strcmp(arg, "--version") == 0)
 565 a.arora         1.142                 {
 566 jim.wunderlich  1.180                     cout << _cimServerProcess->getCompleteVersion() << endl;
 567 kumpf           1.216                     Executor::daemonizeExecutor();
 568 a.arora         1.142                     exit(0);
 569                                       }
 570 mike            1.35                  // Check for -option
 571 a.arora         1.142                 else if (*arg == '-')
 572 mike            1.35                  {
 573                                           // Get the option
 574                                           const char* option = arg + 1;
 575                           
 576                                           //
 577                                           // Check to see if user asked for the version (-v option):
 578                                           //
 579 tony            1.83                      if (*option == OPTION_VERSION &&
 580                                               strlen(option) == 1)
 581 mike            1.35                      {
 582 jim.wunderlich  1.180                         cout << _cimServerProcess->getCompleteVersion() << endl;
 583 kumpf           1.216                         Executor::daemonizeExecutor();
 584 mike            1.35                          exit(0);
 585                                           }
 586                                           //
 587                                           // Check to see if user asked for help (-h option):
 588                                           //
 589 tony            1.83                      else if (*option == OPTION_HELP &&
 590                                                   (strlen(option) == 1))
 591 mike            1.35                      {
 592                                               PrintHelp(argv[0]);
 593 kumpf           1.216                         Executor::daemonizeExecutor();
 594 mike            1.35                          exit(0);
 595                                           }
 596 kumpf           1.138     #if !defined(PEGASUS_USE_RELEASE_DIRS)
 597 tony            1.83                      else if (*option == OPTION_HOME &&
 598                                                   (strlen(option) == 1))
 599 mike            1.35                      {
 600 kumpf           1.60                          if (i + 1 < argc)
 601 mike            1.35                          {
 602                                                   pegasusHome.assign(argv[i + 1]);
 603                                               }
 604                                               else
 605                                               {
 606 humberto        1.99                              String opt(option);
 607 kumpf           1.202                             MessageLoaderParms parms(
 608                                                       "src.Server.cimserver.MISSING_ARGUMENT",
 609                                                       "Missing argument for option -$0",
 610                                                       opt);
 611 h.sterling      1.153                             cout << MessageLoader::getMessage(parms) << endl;
 612 kumpf           1.216                             exit(1);
 613 mike            1.35                          }
 614                           
 615                                               memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 616                                               argc -= 2;
 617                                           }
 618 kumpf           1.63      #endif
 619 kumpf           1.48                      //
 620 kumpf           1.178                     // Check to see if user asked for debug output (-X option):
 621 kumpf           1.48                      //
 622 kumpf           1.178                     else if (*option == OPTION_DEBUGOUTPUT &&
 623 tony            1.83                              (strlen(option) == 1))
 624 kumpf           1.48                      {
 625 kumpf           1.178                         MessageLoaderParms parms(
 626                                                   "src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 627                                                   "Unsupported debug output option is enabled.");
 628 h.sterling      1.153                         cout << MessageLoader::getMessage(parms) << endl;
 629 kumpf           1.178     
 630                                               debugOutputOption = true;
 631                           
 632                           #if defined(PEGASUS_OS_HPUX)
 633                                               System::bindVerbose = true;
 634                           #endif
 635                           
 636 kumpf           1.48                          // remove the option from the command line
 637                                               memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 638 david.dillard   1.165                         argc--;
 639 kumpf           1.48                      }
 640 mike            1.35                      //
 641                                           // Check to see if user asked for shutdown (-s option):
 642                                           //
 643 tony            1.82                      else if (*option == OPTION_SHUTDOWN &&
 644                                                   (strlen(option) == 1))
 645 mike            1.35                      {
 646                                               //
 647 kumpf           1.52                          // Check to see if shutdown has already been specified:
 648 mike            1.35                          //
 649 kumpf           1.52                          if (shutdownOption)
 650 mike            1.35                          {
 651 kumpf           1.202                             MessageLoaderParms parms(
 652                                                       "src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 653                                                       "Duplicate shutdown option specified.");
 654 david.dillard   1.165     
 655 humberto        1.97                              cout << MessageLoader::getMessage(parms) << endl;
 656 kumpf           1.216                             exit(1);
 657 mike            1.35                          }
 658                           
 659 kumpf           1.52                          shutdownOption = true;
 660 david.dillard   1.165     
 661 mike            1.35                          // remove the option from the command line
 662                                               memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 663 david.dillard   1.165                         argc--;
 664 mike            1.35                      }
 665                                           else
 666                                               i++;
 667                                       }
 668                                       else
 669                                           i++;
 670 mike            1.32              }
 671 mike            1.35      
 672 kumpf           1.38          //
 673                               // Set the value for pegasusHome property
 674                               //
 675                               ConfigManager::setPegasusHome(pegasusHome);
 676 mike            1.32      
 677 mike            1.35          //
 678 carolann.graves 1.171         // Do the platform specific run
 679 s.hills         1.117         //
 680                           
 681 kumpf           1.178         return _cimServerProcess->platform_run(
 682                                   argc, argv, shutdownOption, debugOutputOption);
 683 s.hills         1.117     }
 684                           
 685 h.sterling      1.153     void CIMServerProcess::cimserver_stop()
 686                           {
 687                               _cimServer->shutdownSignal();
 688                           }
 689 s.hills         1.117     
 690                           //
 691                           // The main, common, running code
 692                           //
 693 david.dillard   1.165     // NOTE: Do NOT call exit().  Use return(), otherwise some platforms
 694 s.hills         1.117     // will fail to shutdown properly/cleanly.
 695                           //
 696 david.dillard   1.165     // TODO: Current change minimal for platform "service" shutdown bug fixes.
 697 carolann.graves 1.171     // Perhaps further extract out common stuff and put into main(), put
 698 david.dillard   1.165     // daemon stuff into platform specific platform_run(), etc.
 699                           // Note: make sure to not put error handling stuff that platform
 700 carolann.graves 1.171     // specific runs may need to deal with better (instead of exit(), etc).
 701 s.hills         1.117     //
 702                           
 703 kumpf           1.178     int CIMServerProcess::cimserver_run(
 704                               int argc,
 705                               char** argv,
 706                               Boolean shutdownOption,
 707                               Boolean debugOutputOption)
 708 s.hills         1.117     {
 709                               Boolean daemonOption = false;
 710                           
 711 ouyang.jian     1.206     #if defined (PEGASUS_OS_PASE) && !defined (PEGASUS_DEBUG)
 712                               // PASE have itself regular for checking privileged user
 713                               if (!System::isPrivilegedUser("*CURRENT  "))
 714                               {
 715                                   MessageLoaderParms parms(
 716                                           "src.Server.cimserver.NO_AUTHORITY.PEGASUS_OS_PASE",
 717                                           "The caller should be a privileged user,"
 718                                           " or the server will not run.");
 719                                   cerr << MessageLoader::getMessage(parms) << endl;
 720                                   exit (1);
 721                               }
 722                               char jobName[11];
 723                               // this function only can be found in PASE environment
 724                               umeGetJobName(jobName, false);
 725                               if (strncmp("QUMECIMOM ", jobName, 10) != 0
 726                                       && strncmp("QUMEENDCIM", jobName, 10) != 0)
 727                               {
 728                                   MessageLoaderParms parms(
 729                                           "src.Server.cimserver.NOT_OFFICIAL_START.PEGASUS_OS_PASE",
 730                                           "cimserver can not be started by user.\nServer will not run.");
 731                                   cerr << MessageLoader::getMessage(parms) << endl;
 732 ouyang.jian     1.206             exit (1);
 733                               }
 734                           
 735 kumpf           1.228         // Direct standard input, output, and error to /dev/null,
 736 ouyang.jian     1.206         // PASE run this job in background, any output in not allowed
 737                               freopen("/dev/null", "r", stdin);
 738                               freopen("/dev/null", "w", stdout);
 739                               freopen("/dev/null", "w", stderr);
 740                           #endif
 741                           
 742 s.hills         1.117         //
 743 mike            1.35          // Get an instance of the Config Manager.
 744                               //
 745 kumpf           1.203         ConfigManager* configManager = ConfigManager::getInstance();
 746 kumpf           1.136         configManager->useConfigFiles = true;
 747 mike            1.35      
 748 mike            1.32          try
 749                               {
 750 kumpf           1.203             //
 751                                   // Get options (from command line and from configuration file); this
 752                                   // removes corresponding options and their arguments from the command
 753                                   // line.  NOTE: If shutdownOption=true, the contents of current config
 754                                   // file are not overwritten by the planned config file.
 755                                   //
 756 mateus.baur     1.193             GetOptions(configManager, argc, argv, shutdownOption);
 757 kumpf           1.127     
 758 kumpf           1.203             //
 759                                   // Initialize the message home directory in the MessageLoader.
 760                                   // This is the default directory where the resource bundles are found.
 761                                   //
 762                                   MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
 763                                       ConfigManager::getInstance()->getCurrentValue("messageDir")));
 764 kumpf           1.86      
 765 ouyang.jian     1.224     #if !defined(PEGASUS_USE_SYSLOGS)
 766                                   String logsDirectory = ConfigManager::getHomedPath(
 767                                       configManager->getCurrentValue("logdir"));
 768                           
 769                                   // Set up the Logger.  This does not open the logs.
 770                                   // Might be more logical to clean before set.
 771                                   Logger::setHomeDirectory(logsDirectory);
 772                           #endif
 773                           
 774                           
 775 ouyang.jian     1.206     #ifdef PEGASUS_OS_PASE
 776 ouyang.jian     1.224             /* write job log to tell where pegasus log is.*/
 777                                   if(logsDirectory.size() > 0)
 778                                       // this function only can be found in PASE environment
 779                                       logPegasusDir2joblog(logsDirectory.getCString());
 780                                   else
 781                                       logPegasusDir2joblog(".");
 782                           
 783                                   // set ccsid to unicode for entire job
 784                                   // ccsid is globolization mechanism in PASE environment
 785                                   if (_SETCCSID(1208) == -1)
 786                                   {
 787                                       MessageLoaderParms parms(
 788                                               "src.Server.cimserver.SET_CCSID_ERROR.PEGASUS_OS_PASE",
 789                                               "Failed to set CCSID, server will stop.");
 790                                       cerr << MessageLoader::getMessage(parms) << endl;
 791                                       Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::FATAL,
 792                                               parms);
 793                                       exit (1);
 794                                   }
 795 ouyang.jian     1.206     
 796 ouyang.jian     1.224             char fullJobName[29];
 797                                   umeGetJobName(fullJobName, true);
 798                                   Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
 799                                           Logger::INFORMATION,
 800                                           MessageLoaderParms(
 801                                               "src.Server.cimserver.SERVER_JOB_NAME.PEGASUS_OS_PASE",
 802                                               "CIM Server's Job Name is: $0", fullJobName));
 803 ouyang.jian     1.206     #endif
 804                           
 805 kumpf           1.221     #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
 806                                   // Make sure at least one connection is enabled
 807 ouyang.jian     1.206     
 808 kumpf           1.221             Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
 809                                       configManager->getCurrentValue("enableHttpConnection"));
 810                                   Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
 811                                       configManager->getCurrentValue("enableHttpsConnection"));
 812                           
 813                                   if (!enableHttpConnection && !enableHttpsConnection)
 814                                   {
 815                                       MessageLoaderParms parms(
 816 ouyang.jian     1.206                     "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 817                                           "Neither HTTP nor HTTPS connection is enabled."
 818 kumpf           1.221                         "  CIMServer will not be started.");
 819 kumpf           1.222                 Logger::put_l(
 820                                           Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 821                                           parms);
 822 kumpf           1.221                 cerr << MessageLoader::getMessage(parms) << endl;
 823                                       return 1;
 824                                   }
 825 ouyang.jian     1.206     #endif
 826 kumpf           1.221     
 827 mike            1.35              //
 828 kumpf           1.187             // Check to see if we should start Pegasus as a daemon
 829 mike            1.35              //
 830 kumpf           1.187             daemonOption = ConfigManager::parseBooleanValue(
 831                                       configManager->getCurrentValue("daemon"));
 832 david.dillard   1.165     
 833 kumpf           1.215             if ((Executor::detectExecutor() == 0) && (daemonOption == false))
 834                                   {
 835                                       MessageLoaderParms parms(
 836                                           "src.Server.cimserver.PRIVSEP_REQUIRES_DAEMON",
 837                                           "Warning: The configuration setting daemon=false is ignored "
 838                                               "with privilege separation enabled.");
 839                                       cerr << MessageLoader::getMessage(parms) << endl;
 840                                       daemonOption = true;
 841                                   }
 842                           
 843 kumpf           1.36              //
 844 david.dillard   1.165             // Check to see if we need to shutdown CIMOM
 845 mike            1.35              //
 846                                   if (shutdownOption)
 847                                   {
 848 karl            1.237.2.2 #if defined(PEGASUS_OS_ZOS) && defined(PEGASUS_ZOS_SECURITY)
 849                                       // This checks whether user is authorized to stop the
 850                                       // CIM Server. When unauthorized a message is logged to
 851                                       // to the user and program exits.
 852                                       shutdownCheckProfileCIMSERVclassWBEM();
 853                                       // Depending on the success of the previous check we may not
 854                                       // reach this code!!!
 855                           #endif
 856 david.dillard   1.165                 String configTimeout =
 857 kumpf           1.60                      configManager->getCurrentValue("shutdownTimeout");
 858 kumpf           1.202                 Uint32 timeoutValue =
 859                                           strtol(configTimeout.getCString(), (char **)0, 10);
 860 david.dillard   1.165     
 861 kumpf           1.198                 ServerShutdownClient serverShutdownClient(&_serverRunStatus);
 862                                       serverShutdownClient.shutdown(timeoutValue);
 863 kumpf           1.45      
 864 kumpf           1.198                 MessageLoaderParms parms(
 865                                           "src.Server.cimserver.SERVER_STOPPED",
 866                                           "CIM Server stopped.");
 867 humberto        1.106     
 868 humberto        1.97                  cout << MessageLoader::getMessage(parms) << endl;
 869 kumpf           1.202                 return 0;
 870 mike            1.35              }
 871 mike            1.32      
 872 kumpf           1.198     #if defined(PEGASUS_DEBUG) && !defined(PEGASUS_USE_SYSLOGS)
 873 kumpf           1.36              // Leave this in until people get familiar with the logs.
 874 humberto        1.97              MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
 875 h.sterling      1.153                                      "Logs Directory = ");
 876 humberto        1.97              cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
 877 kumpf           1.57      #endif
 878 mike            1.32          }
 879 kumpf           1.203         catch (Exception& e)
 880 mike            1.32          {
 881 kumpf           1.203             MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 882                                       "cimserver not started: $0", e.getMessage());
 883 kumpf           1.222             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 884                                       parms);
 885 kumpf           1.203             cerr << MessageLoader::getMessage(parms) << endl;
 886                           
 887                                   return 1;
 888 marek           1.186         }
 889 david           1.85      
 890 thilo.boehm     1.237     #if defined(PEGASUS_OS_ZOS) 
 891                           #  if defined(PEGASUS_ZOS_SECURITY)
 892 marek           1.186         startupCheckBPXServer(true);
 893                               startupCheckProfileCIMSERVclassWBEM();
 894                               startupEnableMSC();
 895 thilo.boehm     1.237     #  endif
 896                               startupWaitForTCPIP();
 897 david           1.85      #endif
 898 mike            1.32      
 899 kumpf           1.139     #if defined(PEGASUS_DEBUG)
 900 mike            1.32          // Put out startup up message.
 901 kumpf           1.202         cout << _cimServerProcess->getProductName() << " " <<
 902                                   _cimServerProcess->getCompleteVersion() << endl;
 903 humberto        1.97      #endif
 904                           
 905 kumpf           1.202         // reset message loading to NON-process locale
 906                               MessageLoader::_useProcessLocale = false;
 907 mike            1.32      
 908 kumpf           1.137         // Get the parent's PID before forking
 909 kumpf           1.198         _serverRunStatus.setParentPid(System::getPID());
 910 david.dillard   1.165     
 911 kumpf           1.202         // Do not fork when using privilege separation (executor will daemonize
 912                               // itself later).
 913 kumpf           1.63          if (daemonOption)
 914                               {
 915 kumpf           1.202             if (-1 == _cimServerProcess->cimserver_fork())
 916                                       return -1;
 917 kumpf           1.63          }
 918 chuck           1.66      
 919 chuck           1.96          // Now we are after the fork...
 920                               // Create a dummy Thread object that can be used to store the
 921 kumpf           1.176         // AcceptLanguageList object for CIM requests that are serviced
 922 chuck           1.96          // by this thread (initial thread of server).  Need to do this
 923                               // because this thread is not in a ThreadPool, but is used
 924                               // to service CIM requests.
 925                               // The run function for the dummy Thread should never be called,
 926 konrad.r        1.166         dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
 927 david.dillard   1.165         Thread::setCurrent(dummyInitialThread);
 928 kumpf           1.202         try
 929                               {
 930 kumpf           1.214             Thread::setLanguages(LanguageParser::getDefaultAcceptLanguages());
 931 kumpf           1.202         }
 932                               catch (InvalidAcceptLanguageHeader& e)
 933                               {
 934 kumpf           1.203             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 935 kumpf           1.222                 MessageLoaderParms(
 936                                           "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
 937                                           "Could not convert the system process locale into a valid "
 938                                               "AcceptLanguage format."));
 939 kumpf           1.203             Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 940                                       e.getMessage());
 941 humberto        1.108         }
 942 david.dillard   1.165     
 943 kumpf           1.167     #ifndef PEGASUS_OS_TYPE_WINDOWS
 944                               umask(S_IRWXG|S_IRWXO);
 945                           #endif
 946 mday            1.62      
 947 kumpf           1.203         // Start up the CIM Server
 948 mateus.baur     1.175     
 949 kumpf           1.203         try
 950                               {
 951 mateus.baur     1.175     #if defined(PEGASUS_OS_TYPE_UNIX)
 952 kumpf           1.203             //
 953                                   // Lock the CIMSERVER_LOCK_FILE during CIM Server start-up to prevent
 954                                   // concurrent writes to this file by multiple cimserver processes
 955                                   // starting at the same time.
 956                                   //
 957                                   CString startupLockFileName = ConfigManager::getHomedPath(
 958 kumpf           1.204                 PEGASUS_CIMSERVER_START_LOCK_FILE).getCString();
 959 kumpf           1.203     
 960                                   // Make sure the start-up lock file exists
 961                                   FILE* startupLockFile;
 962                                   if ((startupLockFile = fopen(startupLockFileName, "w")) != 0)
 963                                   {
 964                                       fclose(startupLockFile);
 965                                   }
 966 kumpf           1.202     
 967 kumpf           1.203             AutoFileLock fileLock(startupLockFileName);
 968                           #endif
 969 kumpf           1.202     
 970 kumpf           1.203     #if defined(PEGASUS_OS_TYPE_UNIX) || defined(PEGASUS_OS_VMS)
 971                                   //
 972                                   // Check if a CIM Server is already running.  If so, print an error
 973                                   // message and notify the parent process (if there is one) to terminate
 974                                   //
 975                                   if (_serverRunStatus.isServerRunning())
 976                                   {
 977                                       MessageLoaderParms parms(
 978                                           "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
 979                                           "Unable to start CIMServer. CIMServer is already running.");
 980 kumpf           1.222                 Logger::put_l(
 981 kumpf           1.203                     Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 982 kumpf           1.222                     parms);
 983 kumpf           1.203                 cerr << MessageLoader::getMessage(parms) << endl;
 984 mateus.baur     1.175     
 985 kumpf           1.203                 if (daemonOption)
 986                                       {
 987                                           _cimServerProcess->notify_parent(1);
 988                                       }
 989 kumpf           1.79      
 990 kumpf           1.203                 return 1;
 991                                   }
 992 kumpf           1.79      
 993 kumpf           1.198             //
 994 kumpf           1.203             // Declare ourselves as the running CIM Server process, and write our
 995                                   // PID to the PID file.
 996 kumpf           1.79              //
 997 kumpf           1.203             _serverRunStatus.setServerRunning();
 998                           #endif
 999                           
1000                                   // Create and initialize the CIMServer object
1001                           
1002                                   _cimServer = new CIMServer();
1003                           
1004                                   Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
1005                                       configManager->getCurrentValue("enableHttpConnection"));
1006                                   Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
1007                                       configManager->getCurrentValue("enableHttpsConnection"));
1008                           
1009                           #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1010                                   // Make sure at least one connection is enabled
1011                                   if (!enableHttpConnection && !enableHttpsConnection)
1012 kumpf           1.198             {
1013 kumpf           1.203                 MessageLoaderParms parms(
1014                                           "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
1015                                           "Neither HTTP nor HTTPS connection is enabled.");
1016                                       throw Exception(parms);
1017 kumpf           1.198             }
1018 kumpf           1.63      #endif
1019 kumpf           1.51      
1020 venkat.puvvada  1.208             Boolean addIP6Acceptor = false;
1021                                   Boolean addIP4Acceptor = false;
1022                           
1023                           #ifdef PEGASUS_OS_TYPE_WINDOWS
1024                                   addIP4Acceptor = true;
1025                           #endif
1026                           
1027                           #ifdef PEGASUS_ENABLE_IPV6
1028                                   // If IPv6 stack is disabled swicth to IPv4 stack.
1029                                   if (System::isIPv6StackActive())
1030                                   {
1031                                       addIP6Acceptor = true;
1032                                   }
1033                                   else
1034                                   {
1035 marek           1.233                 PEG_TRACE_CSTRING(TRC_SERVER,Tracer::LEVEL4,
1036 venkat.puvvada  1.208                     "IPv6 stack is not active, using IPv4 socket.");
1037                                   }
1038                           #endif
1039                                   if (!addIP6Acceptor)
1040                                   {
1041                                       addIP4Acceptor = true;
1042                                   }
1043                           
1044 kumpf           1.203             // The server HTTP and HTTPS ports are determined via this algorithm:
1045                                   // 1) If the user explicitly specified a port, use it.
1046                                   // 2) If the user did not specify a port, get the port from the
1047                                   //    services file.
1048                                   // 3) If no value is specified in the services file, use the IANA WBEM
1049                                   //    default port.
1050                                   // Note that 2 and 3 are done within the System::lookupPort method
1051                                   // An empty string from the ConfigManager implies that the user did not
1052                                   // specify a port.
1053 kumpf           1.41      
1054 kumpf           1.86              if (enableHttpConnection)
1055                                   {
1056 kumpf           1.203                 Uint32 portNumberHttp = 0;
1057                                       String httpPort = configManager->getCurrentValue("httpPort");
1058                                       if (httpPort == String::EMPTY)
1059                                       {
1060                                           //
1061                                           // Look up the WBEM-HTTP port number
1062                                           //
1063                                           portNumberHttp = System::lookupPort(
1064                                               WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1065 venkat.puvvada  1.231                     _initConfigProperty("httpPort", portNumberHttp);
1066 kumpf           1.203                 }
1067                                       else
1068                                       {
1069                                           //
1070                                           // user-specified
1071                                           //
1072                                           CString portString = httpPort.getCString();
1073                                           char* end = 0;
1074                                           portNumberHttp = strtol(portString, &end, 10);
1075                                           if (!(end != 0 && *end == '\0'))
1076                                           {
1077                                               throw InvalidPropertyValue("httpPort", httpPort);
1078                                           }
1079                                       }
1080                           
1081 venkat.puvvada  1.208                 if (addIP6Acceptor)
1082                                       {
1083                                           _cimServer->addAcceptor(HTTPAcceptor::IPV6_CONNECTION,
1084                                               portNumberHttp, false);
1085                                       }
1086                                       if (addIP4Acceptor)
1087                                       {
1088                                           _cimServer->addAcceptor(HTTPAcceptor::IPV4_CONNECTION,
1089                                               portNumberHttp, false);
1090                                       }
1091 denise.eckstein 1.225                 // The port number is converted to a string to avoid the
1092                                       //  addition of localized characters (e.g., "5,988").
1093 denise.eckstein 1.218                 char scratchBuffer[22];
1094                                       Uint32 n;
1095                                       const char * portNumberHttpStr = Uint32ToString(
1096 kumpf           1.228                     scratchBuffer, portNumberHttp, n);
1097 kumpf           1.203                 MessageLoaderParms parms(
1098 kumpf           1.198                     "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1099 denise.eckstein 1.218                     "Listening on HTTP port $0.", portNumberHttpStr);
1100 kumpf           1.222                 Logger::put_l(
1101 kumpf           1.203                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1102 kumpf           1.222                     parms);
1103 kumpf           1.203     #if defined(PEGASUS_DEBUG)
1104                                       cout << MessageLoader::getMessage(parms) << endl;
1105                           #endif
1106 kumpf           1.86              }
1107 kumpf           1.198     
1108 kumpf           1.86              if (enableHttpsConnection)
1109                                   {
1110 kumpf           1.203                 Uint32 portNumberHttps = 0;
1111                                       String httpsPort = configManager->getCurrentValue("httpsPort");
1112                                       if (httpsPort == String::EMPTY)
1113                                       {
1114                                           //
1115                                           // Look up the WBEM-HTTPS port number
1116                                           //
1117                                           portNumberHttps = System::lookupPort(
1118                                               WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1119 venkat.puvvada  1.231                     _initConfigProperty("httpsPort", portNumberHttps);
1120 kumpf           1.203                 }
1121                                       else
1122                                       {
1123                                           //
1124                                           // user-specified
1125                                           //
1126                                           CString portString = httpsPort.getCString();
1127                                           char* end = 0;
1128                                           portNumberHttps = strtol(portString, &end, 10);
1129                                           if (!(end != 0 && *end == '\0'))
1130                                           {
1131                                               throw InvalidPropertyValue("httpsPort", httpsPort);
1132                                           }
1133                                       }
1134 venkat.puvvada  1.208                 if (addIP6Acceptor)
1135 kumpf           1.228                 {
1136 venkat.puvvada  1.208                     _cimServer->addAcceptor(HTTPAcceptor::IPV6_CONNECTION,
1137                                               portNumberHttps, true);
1138                                       }
1139                                       if (addIP4Acceptor)
1140                                       {
1141                                           _cimServer->addAcceptor(HTTPAcceptor::IPV4_CONNECTION,
1142                                               portNumberHttps, true);
1143                                       }
1144 denise.eckstein 1.225                 // The port number is converted to a string to avoid the
1145                                       //  addition of localized characters (e.g., "5,989").
1146 denise.eckstein 1.218                 char scratchBuffer[22];
1147                                       Uint32 n;
1148                                       const char * portNumberHttpsStr = Uint32ToString(
1149 kumpf           1.228                     scratchBuffer, portNumberHttps, n);
1150 kumpf           1.203                 MessageLoaderParms parms(
1151 kumpf           1.198                     "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1152 denise.eckstein 1.218                     "Listening on HTTPS port $0.", portNumberHttpsStr);
1153 kumpf           1.222                 Logger::put_l(
1154 kumpf           1.203                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1155 kumpf           1.222                     parms);
1156 kumpf           1.203     #if defined(PEGASUS_DEBUG)
1157                                       cout << MessageLoader::getMessage(parms) << endl;
1158                           #endif
1159 kumpf           1.86              }
1160 kumpf           1.135     
1161 h.sterling      1.159     #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1162 kumpf           1.203             {
1163 dave.sudlik     1.205                 _cimServer->addAcceptor(HTTPAcceptor::LOCAL_CONNECTION, 0, false);
1164 kumpf           1.86      
1165 kumpf           1.198                 MessageLoaderParms parms(
1166 kumpf           1.203                     "src.Server.cimserver.LISTENING_ON_LOCAL",
1167                                           "Listening on local connection socket.");
1168 kumpf           1.222                 Logger::put_l(
1169 kumpf           1.203                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1170 kumpf           1.222                     parms);
1171 kumpf           1.203     # if defined(PEGASUS_DEBUG)
1172 h.sterling      1.153                 cout << MessageLoader::getMessage(parms) << endl;
1173 kumpf           1.203     # endif
1174 kumpf           1.86              }
1175 david           1.85      #endif
1176 mike            1.35      
1177 kumpf           1.198             _cimServer->bind();
1178 kumpf           1.199     
1179 kumpf           1.198             // notify parent process (if there is a parent process) to terminate
1180 konrad.r        1.95              // so user knows that there is cimserver ready to serve CIM requests.
1181 kumpf           1.198             if (daemonOption)
1182                                   {
1183                                       _cimServerProcess->notify_parent(0);
1184                                   }
1185 mike            1.35      
1186 kumpf           1.139     #if defined(PEGASUS_DEBUG)
1187 kumpf           1.202             cout << "Started. " << endl;
1188 kumpf           1.63      #endif
1189 david.dillard   1.165     
1190 kumpf           1.54              // Put server started message to the logger
1191 kumpf           1.143             Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1192                                       Logger::INFORMATION,
1193 kumpf           1.222                 MessageLoaderParms(
1194                                           "src.Server.cimserver.STARTED_VERSION",
1195                                           "Started $0 version $1.",
1196                                           _cimServerProcess->getProductName(),
1197                                           _cimServerProcess->getCompleteVersion()));
1198 kumpf           1.45      
1199 marek           1.190     #if defined(PEGASUS_OS_TYPE_UNIX) && !defined(PEGASUS_OS_ZOS)
1200 kumpf           1.178             if (daemonOption && !debugOutputOption)
1201 kumpf           1.202             {
1202 kumpf           1.178                 // Direct standard input, output, and error to /dev/null,
1203                                       // since we are running as a daemon.
1204 thilo.boehm     1.211                 close(STDIN_FILENO);
1205 kumpf           1.178                 open("/dev/null", O_RDONLY);
1206 thilo.boehm     1.211                 close(STDOUT_FILENO);
1207 kumpf           1.178                 open("/dev/null", O_RDWR);
1208 thilo.boehm     1.211                 close(STDERR_FILENO);
1209 kumpf           1.178                 open("/dev/null", O_RDWR);
1210                                   }
1211                           #endif
1212 kumpf           1.203         }
1213                               catch (Exception& e)
1214                               {
1215                                   MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
1216                                       "cimserver not started: $0", e.getMessage());
1217 kumpf           1.222             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1218                                       parms);
1219 kumpf           1.203             cerr << MessageLoader::getMessage(parms) << endl;
1220 kumpf           1.178     
1221 s.kodali        1.234             deleteCIMServer();
1222                           
1223 kumpf           1.203             //
1224                                   // notify parent process (if there is a parent process) to terminate
1225                                   //
1226                                   if (daemonOption)
1227                                       _cimServerProcess->notify_parent(1);
1228                           
1229                                   return 1;
1230                               }
1231                           
1232                               // Run the main CIM Server loop
1233                           
1234                               try
1235                               {
1236 r.kieninger     1.223     #if defined(PEGASUS_OS_ZOS)
1237 thilo.boehm     1.185     
1238 kumpf           1.202             // ARM is a z/OS internal restart facility.
1239                                   // This is a z/OS specific change.
1240 thilo.boehm     1.185     
1241                                   // Instatiating the automatic restart manager for zOS
1242                                   ARM_zOS automaticRestartManager;
1243                           
1244                                   // register to zOS ARM
1245                                   automaticRestartManager.Register();
1246                           
1247                           #endif
1248                           
1249 marek           1.217     #ifdef PEGASUS_ENABLE_SLP
1250                                   _cimServer->startSLPProvider();
1251 kumpf           1.228     #endif
1252 venkat.puvvada  1.232             _cimServer->initComplete();
1253                           
1254 mike            1.35              //
1255                                   // Loop to call CIMServer's runForever() method until CIMServer
1256                                   // has been shutdown
1257                                   //
1258 kumpf           1.202             while (!_cimServer->terminated())
1259                                   {
1260                                       _cimServer->runForever();
1261                                   }
1262 carson.hovey    1.157     
1263 kumpf           1.45              //
1264                                   // normal termination
1265 carson.hovey    1.157             //
1266 kumpf           1.203     
1267 r.kieninger     1.223     #if defined(PEGASUS_OS_ZOS)
1268 thilo.boehm     1.185     
1269 kumpf           1.202             // ARM is a z/OS internal restart facility.
1270                                   // This is a z/OS specific change.
1271 thilo.boehm     1.185     
1272                                   // register to zOS ARM
1273                                   automaticRestartManager.DeRegister();
1274                           
1275                           #endif
1276 kumpf           1.143     
1277 kumpf           1.54              // Put server shutdown message to the logger
1278 kumpf           1.222             Logger::put_l(
1279                                       Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1280                                       MessageLoaderParms(
1281                                           "src.Server.cimserver.STOPPED",
1282                                           "$0 stopped.", _cimServerProcess->getProductName()));
1283 mike            1.32          }
1284 kumpf           1.202         catch (Exception& e)
1285 marek           1.195         {
1286 kumpf           1.202             MessageLoaderParms parms(
1287 marek           1.195                 "src.Server.cimserver.ERROR",
1288 kumpf           1.202                 "Error: $0",
1289                                       e.getMessage());
1290 kumpf           1.222             Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1291                                       parms);
1292 kumpf           1.203             cerr << MessageLoader::getMessage(parms) << endl;
1293 marek           1.195     
1294                                   deleteCIMServer();
1295                                   return 1;
1296                               }
1297 mike            1.32      
1298 h.sterling      1.156         deleteCIMServer();
1299 mike            1.32          return 0;
1300                           }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2