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

  1 mike  1.32 //%/////////////////////////////////////////////////////////////////////////////
  2            //
  3            // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
  4            //
  5            // Permission is hereby granted, free of charge, to any person obtaining a copy
  6            // of this software and associated documentation files (the "Software"), to 
  7            // deal in the Software without restriction, including without limitation the 
  8            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
  9            // sell copies of the Software, and to permit persons to whom the Software is
 10            // furnished to do so, subject to the following conditions:
 11            // 
 12            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 13            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 14            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 15            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 16            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 17            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 18            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 19            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 20            //
 21            //==============================================================================
 22 mike  1.32 //
 23            // Author: Mike Brasher (mbrasher@bmc.com)
 24            //
 25            // Modified By: Mike Day (mdday@us.ibm.com) 
 26 mike  1.33 //
 27 mike  1.32 // Modified By:	Karl Schopmeyer (k.schopmeyer@opengroup.org)
 28            //
 29 mike  1.35 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
 30            //
 31            // Modified By: Jenny Yu (jenny_yu@hp.com)
 32            //
 33 mike  1.32 //%/////////////////////////////////////////////////////////////////////////////
 34            
 35            
 36            //////////////////////////////////////////////////////////////////////
 37            //
 38            // Notes on deamon operation (Unix) and service operation (Win 32):
 39            //
 40            // To run pegasus as a daemon on Unix platforms, use the -d option:
 41            //
 42            // cimserver -d
 43            //
 44            // The -d option has no effect on windows operation. 
 45            //
 46 mike  1.35 // To shutdown pegasus, use the -s option:
 47            // 
 48            // cimserver -s [-f] [-T timeout_value]
 49            //
 50 mike  1.32 // To run pegasus as an NT service, there are FOUR  different possibilities:
 51            //
 52            // To INSTALL the Pegasus service, 
 53            //
 54            // cimserver -install
 55            //
 56            // To REMOVE the Pegasus service, 
 57            //
 58            // cimserver -remove
 59            //
 60            // To START the Pegasus service, 
 61            //
 62            // net start cimserver
 63            //
 64            // To STOP the Pegasus service, 
 65            //
 66            // net stop cimserver
 67            //
 68            // Alternatively, you can use the windows service manager. Pegasus shows up 
 69            // in the service database as "Pegasus CIM Object Manager"
 70            //
 71 mike  1.32 // Mike Day, mdday@us.ibm.com
 72            // 
 73            //////////////////////////////////////////////////////////////////////
 74            
 75            
 76 mike  1.35 #include <Pegasus/Common/Config.h>
 77 mike  1.32 #include <iostream>
 78 mike  1.35 #include <cassert>
 79 mike  1.32 #include <cstdlib>
 80            #include <Pegasus/Common/FileSystem.h>
 81 mike  1.35 #include <Pegasus/Common/Monitor.h>
 82 mike  1.32 #include <Pegasus/Server/CIMServer.h>
 83            #include <Pegasus/Common/PegasusVersion.h>
 84            #include <Pegasus/Protocol/Handler.h>
 85            #include <Pegasus/Common/Logger.h>
 86            #include <Pegasus/Common/System.h>
 87 mike  1.35 #include <Pegasus/Common/Tracer.h>
 88            #include <Pegasus/Config/ConfigManager.h>
 89            #include <Pegasus/Client/CIMClient.h>
 90            #include <Pegasus/Common/HTTPConnector.h>
 91            #include <Pegasus/Server/ShutdownService.h>
 92            #ifndef PEGASUS_OS_ZOS
 93 mike  1.32 #include <slp/slp.h>
 94 mike  1.35 #endif
 95 mike  1.32 
 96            
 97            #if defined(PEGASUS_OS_TYPE_WINDOWS)
 98            # include "cimserver_windows.cpp"
 99            #elif defined(PEGASUS_OS_TYPE_UNIX)
100            # include "cimserver_unix.cpp"
101            #else
102            # error "Unsupported platform"
103            #endif
104            
105            PEGASUS_USING_PEGASUS;
106            PEGASUS_USING_STD;
107            
108 mike  1.35 //
109            //  The command name.
110            //
111            static const char COMMAND_NAME []    = "cimserver";
112            
113            //
114            //  The constant defining usage string.
115            //
116            static const char USAGE []           = "Usage: ";
117            
118            /**
119            Constants representing the command line options.
120            */
121            static const char OPTION_VERSION     = 'v';
122            
123            static const char OPTION_HELP        = 'h';
124            
125            static const char OPTION_HOME        = 'D';
126            
127            static const char OPTION_SHUTDOWN    = 's';
128            
129 mike  1.35 static const char OPTION_FORCE       = 'f';
130            
131            static const char OPTION_TIMEOUT     = 'T';
132            
133            static const String NAMESPACE = "root/cimv2";
134            static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService";
135 kumpf 1.36 static const String PROPERTY_TIMEOUT = "operationTimeout";
136 mike  1.35 
137            ConfigManager*    configManager;
138            
139 mike  1.32 void GetEnvironmentVariables(
140                const char* arg0,
141                String& pegasusHome)
142            {
143                // Get environment variables:
144            
145                const char* tmp = getenv("PEGASUS_HOME");
146            
147                if (!tmp)
148                {
149            	cerr << arg0 << ": PEGASUS_HOME environment variable undefined" << endl;
150            	exit(1);
151                }
152            
153                pegasusHome = tmp;
154                FileSystem::translateSlashes(pegasusHome);
155            }
156            
157 mike  1.35 void SetEnvironmentVariables(
158                const char* arg0)
159            {
160                cout << "PEGASUS_HOME is now " << arg0 << endl;
161            
162                String str = "PEGASUS_HOME=";
163                str += arg0;
164                char* tmp = str.allocateCString();
165                putenv(tmp);
166            
167                // Note: don't delete tmp! putenv() uses it.
168            }
169            
170 mike  1.32 /** GetOptions function - This function defines the Options Table
171 mike  1.35     and sets up the options from that table using the config manager.
172 mike  1.32 */
173            void GetOptions(
174 mike  1.35     ConfigManager* cm,
175 mike  1.32     int& argc,
176                char** argv,
177                const String& pegasusHome)
178            {
179 mike  1.35     String currentFile = pegasusHome + "/" + CURRENT_CONFIG_FILE;
180                String plannedFile = pegasusHome + "/" + PLANNED_CONFIG_FILE;
181            
182                try
183 mike  1.32     {
184 mike  1.35         cm->mergeConfigFiles(currentFile, plannedFile);
185 mike  1.33 
186 mike  1.35         cm->mergeCommandLine(argc, argv);
187                }
188                catch (NoSuchFile nsf)
189                {
190                    throw nsf;
191                }
192                catch (FileNotReadable fnr)
193                {
194                    throw fnr;
195                }
196                catch (CannotRenameFile ftrf)
197                {
198                    throw ftrf;
199                }
200                catch (ConfigFileSyntaxError cfse)
201                {
202                    throw cfse;
203                }
204                catch(UnrecognizedConfigProperty ucp)
205                {
206                    throw ucp;
207 mike  1.35     }
208                catch(InvalidPropertyValue ipv)
209                {
210                    throw ipv;
211                }
212 mike  1.32 }
213            
214            /* PrintHelp - This is temporary until we expand the options manager to allow
215               options help to be defined with the OptionRow entries and presented from
216               those entries.
217            */
218            void PrintHelp(const char* arg0)
219            {
220 mike  1.35     /**
221                    Build the usage string for the config command.
222                */
223                String usage = String (USAGE);
224                usage.append (COMMAND_NAME);
225                usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
226                usage.append ("  options\n");
227                usage.append ("    -v          - displays pegasus version number\n");
228                usage.append ("    -h          - prints this help message\n");
229                usage.append ("    -D [home]   - sets pegasus home directory\n");
230                usage.append ("    -t          - turns tracing on\n");
231                usage.append ("    -t          - turns on trace of client IO to console\n");
232                usage.append ("    -l          - turns on trace of client IO to trace file\n");
233                usage.append ("    -d          - runs pegasus as a daemon\n");
234                usage.append ("    -s [-f] [-T timeout] \n");
235                usage.append ("                - shuts down pegasus\n");
236                usage.append ("    -cleanlogs  - clears the log files at startup\n");
237                usage.append ("    -install    - installs pegasus as a Windows NT Service\n");
238                usage.append ("    -remove     - removes pegasus as a Windows NT Service\n");
239                usage.append ("    -slp        - registers pegasus as a service with SLP\n\n");
240                usage.append ("    -SSL        - uses SSL\n\n");
241 mike  1.35 
242                usage.append ("  configProperty=value\n");
243                usage.append ("    port=nnnn            - sets port number to listen on\n");
244                usage.append ("    home=/pegasus/bin    - sets pegasus home directory\n");
245                usage.append ("    logdir=/pegasus/logs - directory for log files\n");
246            
247                cout << endl;
248 mike  1.32     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
249                cout << endl;
250 mike  1.35     cout << usage << endl;
251            }
252            
253 kumpf 1.36 void shutdownCIMOM(Boolean forceOption, Uint32 timeoutValue)
254 mike  1.35 {
255                //
256                // Create CIMClient object
257                //
258                Monitor* monitor = new Monitor;
259                HTTPConnector* httpConnector = new HTTPConnector(monitor);
260                CIMClient client(monitor, httpConnector);
261            
262                //
263                // Get the port number
264                //
265                String portNumberStr = configManager->getCurrentValue("port");
266            
267                String hostStr = System::getHostName();
268                hostStr.append(":");
269                hostStr.append(portNumberStr);
270            
271 kumpf 1.36     // Put server shutdown message to the logger
272                Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
273            	"Shutdown $0 on port $1.", PEGASUS_NAME, portNumberStr);
274            
275 mike  1.35     //
276                // open connection to CIMOM 
277                //
278                try
279                {
280                    client.connect(hostStr.allocateCString());
281                }
282                catch(Exception& e)
283                {
284 kumpf 1.36         Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
285                        "Failed to connect to $0 $1.", PEGASUS_NAME, e.getMessage());
286            
287 mike  1.35         PEGASUS_STD(cerr) << "Failed to connect to server: " << e.getMessage() << PEGASUS_STD(endl);
288                    exit(1);
289                }
290            
291                try
292                {
293                    //
294                    // construct CIMReference 
295                    //
296                    String referenceStr = "//";
297                    referenceStr.append(hostStr);
298                    referenceStr.append("/root/cimv2:PG_ShutdownService");
299                    CIMReference reference(referenceStr);
300            
301                    //
302                    // issue the invokeMethod request on the shutdown method
303                    //
304                    Array<CIMParamValue> inParams;
305                    Array<CIMParamValue> outParams;
306            
307                    if (forceOption)
308 mike  1.35         {
309                        inParams.append(CIMParamValue(
310                            CIMParameter("force", CIMType::STRING),
311                            CIMValue("TRUE")));
312                    }
313                    else
314                    {
315                        inParams.append(CIMParamValue(
316                            CIMParameter("force", CIMType::STRING),
317                            CIMValue("FALSE")));
318                    }
319            
320                    inParams.append(CIMParamValue(
321 kumpf 1.36             CIMParameter("timeout", CIMType::UINT32),
322                        CIMValue(timeoutValue)));
323 mike  1.35 
324                    CIMValue retValue = client.invokeMethod(
325                        NAMESPACE,
326                        reference,
327                        "shutdown",
328                        inParams,
329                        outParams);
330 kumpf 1.36 
331                    // Put server shutdown message to the logger
332                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
333            	    "$0 terminated on port $1.", PEGASUS_NAME, portNumberStr);
334            
335 mike  1.35     }
336                catch(Exception& e)
337                {
338                    PEGASUS_STD(cerr) << "Failed to shutdown server: " << e.getMessage() << PEGASUS_STD(endl);
339                    exit(1);
340                }
341            
342                return;
343 mike  1.32 }
344            
345 mike  1.35 
346 mike  1.33 /////////////////////////////////////////////////////////////////////////
347 mike  1.32 //  MAIN
348            //////////////////////////////////////////////////////////////////////////
349            int main(int argc, char** argv)
350            {
351 mike  1.35     String pegasusHome  = String::EMPTY;
352                Boolean pegasusIOTrace = false;
353                Boolean pegasusIOLog = false;
354                String portOption = String::EMPTY;
355                String logsDirectory = String::EMPTY;
356                Boolean useSLP = false;
357                Boolean useSSL = false;
358                Boolean daemonOption = false;
359                Boolean shutdownOption = false;
360                Boolean forceOption = false;
361                Boolean timeoutOption = false;
362                String  timeoutStr  = String::EMPTY;
363                long timeoutValue  = 0;
364            
365 mike  1.32     // on Windows NT if there are no command-line options, run as a service
366            
367                if (argc == 1 )
368 mike  1.35     {
369                  cim_server_service(argc, argv);
370                }
371                else
372                {
373                    // Get help, version and home options
374            
375                    for (int i = 1; i < argc; )
376                    {
377                        const char* arg = argv[i];
378            
379                        // Check for -option
380                        if (*arg == '-')
381                        {
382                            // Get the option
383                            const char* option = arg + 1;
384            
385                            //
386                            // Check to see if user asked for the version (-v option):
387                            //
388                            if (*option == OPTION_VERSION)
389 mike  1.35                 {
390                                cout << PEGASUS_VERSION << endl;
391                                exit(0);
392                            }
393                            //
394                            // Check to see if user asked for help (-h option):
395                            //
396                            else if (*option == OPTION_HELP)
397                            {
398                                PrintHelp(argv[0]);
399                                exit(0);
400                            }
401                            else if (*option == OPTION_HOME)
402                            {
403                                if (i + 1 < argc) 
404                                {
405                                    pegasusHome.assign(argv[i + 1]);
406                    	        SetEnvironmentVariables(argv[i + 1]);
407                                }
408                                else
409                                {
410 mike  1.35                         cout << "Missing argument for option -" << option << endl;
411                                    exit(0);
412                                }
413            
414                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
415                                argc -= 2;
416                            }
417                            //
418                            // Check to see if user asked for shutdown (-s option):
419                            //
420                            else if (*option == OPTION_SHUTDOWN)
421                            {
422                                //
423                                // Check to see if shutdown has already been specified:
424                                //
425                                if (shutdownOption)
426                                {
427                                    cout << "Duplicate shutdown option specified." << endl;
428                                    exit(0);
429                                }
430                                shutdownOption = true;
431 mike  1.35  
432                                // remove the option from the command line
433                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
434                                argc--;   
435                            }
436                            else if (*option == OPTION_FORCE)
437                            {
438                                //
439                                // Check to see if shutdown has been specified:
440                                //
441                                if (!shutdownOption)
442                                {
443                                    cout << "Invalid option -" << option << endl;
444                                    exit(0);
445                                }
446            
447                                //
448                                // Check to see if force has already been specified:
449                                //
450                                if (forceOption)
451                                {
452 mike  1.35                         cout << "Duplicate force option specified." << endl;
453                                    exit(0);
454                                }
455            
456                                forceOption = true;
457             
458                                // remove the option from the command line
459                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
460                                argc--;   
461                            }
462                            else if (*option == OPTION_TIMEOUT)
463                            {
464                                //
465                                // Check to see if shutdown has been specified:
466                                //
467                                if (!shutdownOption)
468                                {
469                                    cout << "Invalid option -" << option << endl;
470                                    exit(0);
471                                }
472            
473 mike  1.35                     if (timeoutOption)
474                                {
475                                    cout << "Duplicate timeout option specified." << endl;
476                                    exit(0);
477                                }
478            
479                                timeoutOption = true;
480            
481                                if (i + 1 < argc)
482                                {
483                                    // get timeout value
484                                    timeoutStr.assign(argv[i + 1]);
485            
486                                    // validate timeout value string
487                                    char* tmp = timeoutStr.allocateCString();
488                                    char* end = 0;
489                                    timeoutValue  = strtol(tmp, &end, 10);
490                                  
491                                    if (!end || *end != '\0')
492                                    {
493                                        cout << "invalid timeout value specified: ";
494 mike  1.35                             cout << timeoutStr << endl;
495                                        delete [] tmp;
496                                        exit(0);
497                                    }
498                                }
499                                else
500                                {
501                                    cout << "Missing argument for option -";
502                                    cout << option << endl;
503                                    exit(0);
504                                }
505            
506                                // remove the option from the command line
507                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
508                                argc -= 2;
509                            }
510                            else
511                                i++;
512                        }
513                        else
514                            i++;
515 mike  1.32         }
516                }
517 mike  1.35 
518 mike  1.32     if (pegasusHome.size() == 0)
519                    GetEnvironmentVariables(argv[0], pegasusHome);
520            
521 mike  1.35     //
522                // Get an instance of the Config Manager.
523                //
524                configManager = ConfigManager::getInstance();
525            
526                //
527 mike  1.32     // Get options (from command line and from configuration file); this
528 mike  1.35     // removes corresponding options and their arguments from the command
529 mike  1.32     // line.
530 mike  1.35     //
531 mike  1.32     try
532                {
533 mike  1.35         GetOptions(configManager, argc, argv, pegasusHome);
534 mike  1.32     }
535                catch (Exception& e)
536                {
537 mike  1.35         cerr << argv[0] << ": " << e.getMessage() << endl;
538                    exit(1);
539 mike  1.32     }
540            
541            
542 mike  1.35     try
543 mike  1.32     {
544 mike  1.35         //
545                    // Check to see if we should (can) install as a NT service
546                    //
547            
548                    if (String::equal(configManager->getCurrentValue("install"), "true"))
549                    {
550                        if( 0 != cimserver_install_nt_service( pegasusHome ))
551                        {
552                            cout << "\nPegasus installed as NT Service";
553                            exit(0);
554                        }
555                    }
556 mike  1.32 
557 mike  1.35         //
558                    // Check to see if we should (can) remove Pegasus as an NT service
559                    //
560            
561                    if (String::equal(configManager->getCurrentValue("remove"), "true"))
562                    {
563                        if( 0 != cimserver_remove_nt_service() )
564                        {
565                            cout << "\nPegasus removed as NT Service";
566                            exit(0);
567                        }
568                    }
569 mike  1.32 
570 mike  1.35         //
571                    // Check to see if we should Pegasus as a daemon
572                    //
573            
574                    if (String::equal(configManager->getCurrentValue("daemon"), "true"))
575                    {
576                        daemonOption = true;
577                    }
578 mike  1.32 
579 mike  1.35         //
580 kumpf 1.36         // Check the log trace options and set global variable
581                    //
582            
583                    if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
584                    {
585                        Handler::setMessageLogTrace(true);
586                        pegasusIOLog = true;
587                    }
588            
589                    // Get the log file directory definition.
590                    // We put String into Cstring because
591                    // Directory functions only handle Cstring.
592                    // ATTN-KS: create String based directory functions.
593            
594                    logsDirectory = configManager->getCurrentValue("logdir");
595            
596                    // Set up the Logger. This does not open the logs
597                    // Might be more logical to clean before set.
598                    // ATTN: Need tool to completely disable logging.
599            
600                    Logger::setHomeDirectory(logsDirectory);
601 kumpf 1.36 
602                    //
603 mike  1.35         // Check to see if we need to shutdown CIMOM 
604                    //
605                    if (shutdownOption)
606                    {
607                        //
608                        // if timeout was specified, validate the timeout value 
609                        //
610                        if (timeoutOption)
611                        {
612                            Boolean valid = configManager->validatePropertyValue(
613                                                         PROPERTY_TIMEOUT,
614                                                         timeoutStr);
615                            if (!valid)
616                            {
617                                cout << "Invalid timeout value specified: " << timeoutValue;
618                                cout << endl;
619                                exit(1);
620                            }
621                        }
622            
623 kumpf 1.36             shutdownCIMOM(forceOption, timeoutValue);
624 mike  1.35             cout << "Pegasus CIM Server terminated." << endl;
625                        exit(0);
626                    }
627 mike  1.32 
628 mike  1.35         //
629                    // Grab the port option:
630                    //
631            
632                    portOption = configManager->getCurrentValue("port");
633            
634                    //
635                    // Check the trace options and set global variable
636                    //
637            
638                    if (String::equal(configManager->getCurrentValue("trace"), "true"))
639                    {
640                        Handler::setMessageTrace(true);
641                        pegasusIOTrace = true;
642                        cout << "Trace Set" << endl;
643                    }
644            
645 kumpf 1.36         // Leave this in until people get familiar with the logs.
646                    cout << "Logs Directory = " << logsDirectory << endl;
647 mike  1.35 
648                    if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
649                    {
650                        Logger::clean(logsDirectory);;
651                    }
652 mike  1.32 
653 mike  1.35         if (String::equal(configManager->getCurrentValue("slp"), "true"))
654                    {
655                        useSLP =  true;
656                    }
657 mike  1.32 
658 mike  1.35         if (String::equal(configManager->getCurrentValue("SSL"), "true"))
659                    {
660                        useSSL =  true;
661                    }
662 mike  1.32     }
663 mike  1.35     catch (UnrecognizedConfigProperty e)
664 mike  1.32     {
665 mike  1.35         cout << "Error: " << e.getMessage() << endl;
666 mike  1.32     }
667            
668                char* address = portOption.allocateCString();
669            
670                // Put out startup up message.
671                cout << PEGASUS_NAME << PEGASUS_VERSION <<
672            	 " on port " << address << endl;
673                cout << "Built " << __DATE__ << " " << __TIME__ << endl;
674                cout <<"Started..."
675            	 << (pegasusIOTrace ? " Tracing to Display ": " ") 
676                     << (pegasusIOLog ? " Tracing to Log ": " ")
677            	 << (useSLP ? " SLP reg. " : " No SLP ")
678 mike  1.35          << (useSSL ? " Use SSL " : " No SSL ")
679 mike  1.32 	<< endl;
680            
681                // Put server start message to the logger
682                Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
683 mike  1.35 	"Start $0 $1 port $2 $3 $4 $5",
684 mike  1.32 		PEGASUS_NAME, 
685            		PEGASUS_VERSION,
686            		address,
687            		(pegasusIOTrace ? " Tracing": " "),
688 mike  1.35 		(useSLP ? " SLP on " : " SLP off "),
689                            (useSSL ? " Use SSL " : " No SSL "));
690 mike  1.32 
691 mike  1.35     // do we need to run as a daemon ?
692                if (daemonOption)
693                {
694                    if(-1 == cimserver_fork())
695                      exit(-1);
696                }
697 mike  1.32 
698                // try loop to bind the address, and run the server
699                try
700                {
701 mike  1.35 #ifndef PEGASUS_OS_ZOS
702 mike  1.32       	slp_client *discovery = new slp_client() ;;
703                    String serviceURL;
704            	serviceURL.assign("service:cim.pegasus://");
705            	String host_name = slp_get_host_name();
706            	serviceURL += host_name;
707            	serviceURL += ":";
708            	serviceURL += address;
709            	char *url = serviceURL.allocateCString();
710            	//	free(host_name);
711 mike  1.35 #endif
712 mike  1.32 
713 mike  1.35 	Monitor monitor;
714            	CIMServer server(&monitor, pegasusHome, useSSL);
715            		
716 mike  1.32 	// bind throws an exception of the bind fails
717 mike  1.33 	cout << "Binding to " << address << endl;
718 mike  1.35 
719            	char* end = 0;
720            	long portNumber = strtol(address, &end, 10);
721            	assert(end != 0 && *end == '\0');
722            	server.bind(portNumber);
723            
724 mike  1.32 	delete [] address;
725            
726            	time_t last = 0;
727 mike  1.35 
728                    //
729                    // Loop to call CIMServer's runForever() method until CIMServer
730                    // has been shutdown
731                    //
732            	while( !server.terminated() )
733 mike  1.32 	{
734 mike  1.35 #ifndef PEGASUS_OS_ZOS
735 mike  1.32 	  if(useSLP  ) 
736            	  {
737            	    if(  (time(NULL) - last ) > 60 ) 
738            	    {
739            	      if( discovery != NULL && url != NULL )
740            		discovery->srv_reg_all(url,  
741 mike  1.35 				       "(namespace=root/cimv2)",
742 mike  1.32 				       "service:cim.pegasus", 
743            				       "DEFAULT", 
744            				       70) ;
745            	      time(&last);
746            	    }
747            	  
748            	    discovery->service_listener();
749            	  }
750 mike  1.35 #endif
751 mike  1.32 	  server.runForever();
752            	}
753            
754 mike  1.34 	// This statement is unrechable!
755            	//
756            	// Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
757            	//   "Normal Termination");
758 mike  1.32     }
759                catch(Exception& e)
760                {
761            	Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
762            	    "Abnormal Termination $0", e.getMessage());
763            	
764            	PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
765                }
766            
767                return 0;
768            }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2