1 karl 1.38 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.7 //
|
3 karl 1.36 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.34 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.36 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.38 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.7 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.16 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.7 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
|
19 kumpf 1.16 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.7 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.7 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Day (mdday@us.ibm.com)
31 //
|
32 mary 1.11 // Modified By: Mary Hinton (m.hinton@verizon.net)
|
33 kumpf 1.12 // Sushma Fernandes (sushma_fernandes@hp.com)
|
34 tony 1.22 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
35 // Tony Fiorentino (fiorentino_tony@emc.com)
|
36 kumpf 1.23 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
37 s.hills 1.33 // Steve Hills (steve.hills@ncr.com)
|
38 joyce.j 1.37 // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2032
|
39 mike 1.7 //
40 //%/////////////////////////////////////////////////////////////////////////////
41
42 #include <windows.h>
43 #include <process.h> /* _beginthread, _endthread */
44 #include <tchar.h>
45 #include <direct.h>
|
46 humberto 1.30 #include <Pegasus/Common/MessageLoader.h> //l10n
|
47 chuck 1.31 #include <Pegasus/Common/Thread.h> // l10n
|
48 mike 1.7
|
49 tony 1.22 #include "service.cpp"
|
50 mike 1.7
51 PEGASUS_USING_PEGASUS;
52 PEGASUS_USING_STD;
53
|
54 tony 1.22 //-------------------------------------------------------------------------
55 // DEFINES
56 //-------------------------------------------------------------------------
57 #define PEGASUS_SERVICE_NAME "cimserver"
58 #define PEGASUS_DISPLAY_NAME "Pegasus CIM Object Manager"
59 #define PEGASUS_DESCRIPTION "Pegasus CIM Object Manager Service"
60
61 //-------------------------------------------------------------------------
62 // GLOBALS
63 //-------------------------------------------------------------------------
|
64 s.hills 1.33 static Mutex _cimserverLock;
65 static CIMServer* _cimserver = 0;
66 static bool _shutdown = false;
|
67 tony 1.22 static Service pegasus_service(PEGASUS_SERVICE_NAME);
|
68 s.hills 1.33 static HANDLE pegasus_service_event = NULL;
|
69 tony 1.26 static LPCSTR g_cimservice_key = TEXT("SYSTEM\\CurrentControlSet\\Services\\%s");
|
70 tony 1.22 static LPCSTR g_cimservice_home = TEXT("home");
|
71 a.dunfey 1.40 static int g_argc = 0;
72 static char **g_argv = 0;
|
73 tony 1.22
|
74 s.hills 1.33 // Constants representing the command line options.
75 static const char OPTION_INSTALL[] = "install";
76 static const char OPTION_REMOVE[] = "remove";
77 static const char OPTION_START[] = "start";
78 static const char OPTION_STOP[] = "stop";
79
|
80 tony 1.22 //-------------------------------------------------------------------------
81 // PROTOTYPES
82 //-------------------------------------------------------------------------
83 int cimserver_windows_main(int flag, int argc, char **argv);
84 static bool _getRegInfo(const char *lpchKeyword, char *lpchRetValue);
85 static bool _setRegInfo(const char *lpchKeyword, const char *lpchValue);
86 void setHome(String & home);
87
88 //-------------------------------------------------------------------------
89 // NO-OPs for windows platform
90 //-------------------------------------------------------------------------
91 int cimserver_fork(void) { return(0); }
92 int cimserver_kill(void) { return(0); }
|
93 s.hills 1.33 void notify_parent(int id) { return; }
|
94 tony 1.22
|
95 chuck 1.31 //-------------------------------------------------------------------------
|
96 s.hills 1.33 // Helper for platform specific handling
97 //-------------------------------------------------------------------------
98
99 void cimserver_set( CIMServer* s )
100 {
|
101 kumpf 1.35 AutoMutex am( _cimserverLock );
|
102 s.hills 1.33 _cimserver = s;
103 if( _cimserver && _shutdown )
104 _cimserver->shutdownSignal();
105 }
|
106 tony 1.22
|
107 s.hills 1.33 void signal_shutdown()
108 {
|
109 kumpf 1.35 AutoMutex am( _cimserverLock );
|
110 s.hills 1.33 _shutdown = true;
111 if( _cimserver )
112 _cimserver->shutdownSignal();
|
113 tony 1.22 }
|
114 mary 1.13
|
115 s.hills 1.33 //-------------------------------------------------------------------------
116 // Run main server asynchronously
117 //-------------------------------------------------------------------------
118 static unsigned __stdcall cimserver_windows_thread( void* parm )
119 {
|
120 a.dunfey 1.40 int rc = cimserver_run( g_argc, g_argv, false );
|
121 s.hills 1.33 SetEvent(pegasus_service_event);
122 _endthreadex( rc );
123 return rc;
124 }
|
125 mike 1.7
|
126 tony 1.22 //-------------------------------------------------------------------------
127 // Windows NT Service Control Code
128 //-------------------------------------------------------------------------
|
129 kumpf 1.14
|
130 tony 1.22 //-------------------------------------------------------------------------
|
131 s.hills 1.33 // START/STOP handler
|
132 tony 1.22 //-------------------------------------------------------------------------
|
133 s.hills 1.33 int cimserver_windows_main(int flag, int argc, char *argv[])
|
134 tony 1.22 {
|
135 s.hills 1.33 switch( flag )
136 {
137 case Service::STARTUP_FLAG:
138 {
139 //
140 // Start up main run in a separate thread and wait for it to finish.
141 //
142
143 unsigned threadid = 0;
|
144 a.dunfey 1.40 g_argc = argc;
145 g_argv = argv;
|
146 s.hills 1.33 HANDLE hThread = (HANDLE)_beginthreadex( NULL, 0, cimserver_windows_thread, NULL, 0, &threadid );
147 if( hThread == NULL )
148 return 1;
149
150 WaitForSingleObject( pegasus_service_event, INFINITE );
151
152 //
153 // Shutdown the cimserver.
154 //
155
156 signal_shutdown();
157
158 //
159 // Make sure we upate the SCM that our stop is pending.
160 // Wait for the main run thread to exit.
161 //
162
163 DWORD dwCheckPoint = 1; // service code should have already started at 0
|
164 mike 1.7
|
165 s.hills 1.33 while( WaitForSingleObject( hThread, 3000 ) == WAIT_TIMEOUT )
166 {
167 pegasus_service.report_status(
168 SERVICE_STOP_PENDING, NO_ERROR, dwCheckPoint++, 5000 );
169 }
|
170 mike 1.7
|
171 s.hills 1.33 CloseHandle( hThread );
|
172 mike 1.8
|
173 s.hills 1.33 break;
174 }
175 case Service::SHUTDOWN_FLAG:
176 SetEvent(pegasus_service_event);
177 break;
|
178 mike 1.8
|
179 s.hills 1.33 default:
180 break;
181 }
|
182 mike 1.7
|
183 s.hills 1.33 return 0;
|
184 mike 1.7 }
185
|
186 tony 1.22 //-------------------------------------------------------------------------
|
187 s.hills 1.33 // IS RUNNING?
|
188 tony 1.22 //-------------------------------------------------------------------------
|
189 s.hills 1.33
190 static const char* _ALREADY_RUNNING_NAME = "PegasusCIMServer";
191
192 class AlreadyRunning
|
193 tony 1.22 {
|
194 s.hills 1.33 public:
195 AlreadyRunning(): alreadyRunning( true ), event( NULL )
196 {
197 }
198 ~AlreadyRunning()
199 {
200 if( event != NULL )
201 CloseHandle( event );
202 }
203
204 void Init()
205 {
206 if( event == NULL )
207 {
208 event = CreateEvent( NULL, TRUE, TRUE, _ALREADY_RUNNING_NAME );
209 if( event != NULL && GetLastError() != ERROR_ALREADY_EXISTS )
210 alreadyRunning = false;
211 }
212 }
213
214 bool IsAlreadyRunning()
215 s.hills 1.33 {
216 return alreadyRunning;
217 }
218
219 bool alreadyRunning;
220 HANDLE event;
221 };
222
223 AlreadyRunning _alreadyRunning;
|
224 mike 1.7
225
|
226 tony 1.22 Boolean isCIMServerRunning(void)
227 {
|
228 s.hills 1.33 //Service::State state;
229 //pegasus_service.GetState(&state);
230 //return (state == Service::SERVICE_STATE_RUNNING) ? true : false;
231
232 // We do it this way so this will work when run as a
233 // console process and a Windows service.
234 AlreadyRunning ar;
235 ar.Init();
236 return ar.IsAlreadyRunning();
|
237 tony 1.22 }
|
238 mike 1.7
|
239 tony 1.22 //-------------------------------------------------------------------------
240 // INSTALL
241 //-------------------------------------------------------------------------
|
242 tony 1.26 bool cimserver_install_nt_service(char *service_name)
|
243 mike 1.7 {
|
244 tony 1.22 Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
|
245 tony 1.26 char filename[_MAX_PATH] = {0};
246 char displayname[_MAX_PATH] = {0};
247
248 // If service name is specified, override default
249 if (service_name == NULL)
250 {
251 strcpy(displayname, PEGASUS_DISPLAY_NAME);
252 }
253 else
254 {
255 pegasus_service.SetServiceName(service_name);
256 sprintf(displayname, "%s - %s", PEGASUS_DISPLAY_NAME, service_name);
257 }
|
258 tony 1.22
259 GetModuleFileName(NULL, filename, sizeof(filename));
|
260 tony 1.26 status = pegasus_service.Install(displayname, PEGASUS_DESCRIPTION, filename);
|
261 mike 1.7
|
262 tony 1.22 // Upon success, set home in registry
263 if (status == Service::SERVICE_RETURN_SUCCESS)
|
264 mike 1.7 {
|
265 tony 1.22 char pegasus_homepath[_MAX_PATH];
266 System::extract_file_path(filename, pegasus_homepath);
267 pegasus_homepath[strlen(pegasus_homepath)-1] = '\0';
268 strcpy(filename, pegasus_homepath);
269 System::extract_file_path(filename, pegasus_homepath);
270 pegasus_homepath[strlen(pegasus_homepath)-1] = '\0';
271 _setRegInfo(g_cimservice_home, pegasus_homepath);
|
272 mike 1.7 }
|
273 tony 1.22
274 return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false;
275 }
276
277 //-------------------------------------------------------------------------
278 // REMOVE
279 //-------------------------------------------------------------------------
|
280 tony 1.26 bool cimserver_remove_nt_service(char *service_name)
|
281 tony 1.22 {
282 Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
283
|
284 tony 1.26 // If service name is specified, override default
285 if (service_name != NULL)
286 {
287 pegasus_service.SetServiceName(service_name);
288 }
289
|
290 tony 1.22 status = pegasus_service.Remove();
291
292 return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false;
|
293 mike 1.7 }
294
|
295 tony 1.22 //-------------------------------------------------------------------------
296 // START
297 //-------------------------------------------------------------------------
|
298 a.dunfey 1.40 bool cimserver_start_nt_service(char *service_name, int num_args, char **service_args)
|
299 tony 1.22 {
300 Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
301
|
302 tony 1.26 // If service name is specified, override default
303 if (service_name != NULL)
304 {
305 pegasus_service.SetServiceName(service_name);
306 }
307
|
308 a.dunfey 1.40 if(num_args > 0 && service_args != NULL)
309 {
310 pegasus_service.SetServiceArgs(num_args, service_args);
311 }
312
|
313 tony 1.22 status = pegasus_service.Start(5);
314
315 return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false;
316 }
|
317 mike 1.7
|
318 tony 1.22 //-------------------------------------------------------------------------
319 // STOP
320 //-------------------------------------------------------------------------
|
321 tony 1.26 bool cimserver_stop_nt_service(char *service_name)
|
322 mike 1.7 {
|
323 tony 1.22 Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
|
324 mike 1.7
|
325 tony 1.26 // If service name is specified, override default
326 if (service_name != NULL)
327 {
328 pegasus_service.SetServiceName(service_name);
329 }
330
|
331 tony 1.22 status = pegasus_service.Stop(5);
332
333 return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false;
334 }
|
335 mike 1.7
|
336 tony 1.22 //-------------------------------------------------------------------------
337 // HELPER Utilities
338 //-------------------------------------------------------------------------
339 static bool _getRegInfo(const char *lpchKeyword, char *lpchRetValue)
340 {
341 HKEY hKey;
342 DWORD dw = _MAX_PATH;
|
343 tony 1.26 char subKey[_MAX_PATH] = {0};
344
345 sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName());
|
346 mike 1.7
|
347 tony 1.22 if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
348 tony 1.26 subKey,
|
349 tony 1.22 0,
350 KEY_READ,
351 &hKey)) != ERROR_SUCCESS)
|
352 mike 1.7 {
|
353 tony 1.22 return false;
|
354 mike 1.7 }
355
|
356 tony 1.22 if ((RegQueryValueEx(hKey,
357 lpchKeyword,
358 NULL,
359 NULL,
360 (LPBYTE)lpchRetValue,
361 &dw)) != ERROR_SUCCESS)
|
362 mike 1.7 {
|
363 tony 1.22 RegCloseKey(hKey);
364 return false;
|
365 mike 1.7 }
366
|
367 tony 1.22 RegCloseKey(hKey);
368
369 return true;
|
370 mike 1.7 }
371
|
372 tony 1.22 static bool _setRegInfo(const char *lpchKeyword, const char *lpchValue)
|
373 mike 1.7 {
|
374 tony 1.22 HKEY hKey;
375 DWORD dw = _MAX_PATH;
376 char home_key[_MAX_PATH] = {0};
|
377 tony 1.26 char subKey[_MAX_PATH] = {0};
|
378 tony 1.22
379 if (lpchKeyword == NULL || lpchValue == NULL)
380 return false;
381
|
382 tony 1.26 sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName());
383
384 if ((RegCreateKeyEx (HKEY_LOCAL_MACHINE,
385 subKey,
|
386 tony 1.22 0,
387 NULL,
388 0,
389 KEY_ALL_ACCESS,
390 NULL,
391 &hKey,
392 NULL) != ERROR_SUCCESS))
393 {
394 return false;
395 }
396
397 if ((RegSetValueEx(hKey,
398 lpchKeyword,
399 0,
400 REG_SZ,
401 (CONST BYTE *)lpchValue,
402 (DWORD)(strlen(lpchValue)+1))) != ERROR_SUCCESS)
403 {
404 RegCloseKey(hKey);
405 return false;
406 }
|
407 mike 1.7
|
408 tony 1.22 RegCloseKey(hKey);
409
410 return true;
|
411 mike 1.7 }
412
|
413 tony 1.22 void setHome(String & home)
|
414 mike 1.7 {
|
415 tony 1.22 // Determine the absolute path to the running program
|
416 tony 1.27 char exe_pathname[_MAX_PATH] = {0};
417 char home_pathname[_MAX_PATH] = {0};
|
418 tony 1.22 GetModuleFileName(NULL, exe_pathname, sizeof(exe_pathname));
419
420 // Pegasus home search rules:
421 // - look in registry (if set)
422 // - if not found, look in PEGASUS_HOME (if set)
423 // - if not found, use exe directory minus one level
424
|
425 tony 1.27 bool found_reg = _getRegInfo("home", home_pathname);
426 if (found_reg == true)
|
427 tony 1.22 {
|
428 tony 1.27 // Make sure home matches
429 String current_home(home_pathname);
430 String current_exe(exe_pathname);
431 current_home.toLower();
432 current_exe.toLower();
433
434 Uint32 pos = current_exe.find(current_home);
435 if (pos != PEG_NOT_FOUND)
436 {
437 home = home_pathname;
438 }
439 else
440 {
441 found_reg = false;
442 }
|
443 tony 1.22 }
|
444 tony 1.27 if (found_reg == false)
|
445 tony 1.22 {
446 const char* tmp = getenv("PEGASUS_HOME");
447 if (tmp)
448 {
449 home = tmp;
450 }
451 else
452 {
453 // ASSUMPTION: At a minimum, the cimserver program is running
454 // from a "bin" directory
455 home = FileSystem::extractFilePath(exe_pathname);
456 home.remove(home.size()-1, 1);
457 home = FileSystem::extractFilePath(home);
458 home.remove(home.size()-1, 1);
459 }
|
460 mike 1.7 }
461 }
462
|
463 s.hills 1.33 //
464 // Our console control handler
465 //
466
467 static BOOL WINAPI ControlHandler( DWORD dwCtrlType )
468 {
469 switch( dwCtrlType )
470 {
471 case CTRL_BREAK_EVENT: // use Ctrl+C or Ctrl+Break to simulate
472 case CTRL_C_EVENT: // SERVICE_CONTROL_STOP in debug mode
473 {
474 signal_shutdown();
475 return TRUE;
476 }
477 }
478 return FALSE;
479 }
480
481 //
482 // Platform specific run
483 //
|
484 mike 1.7
|
485 s.hills 1.33 int platform_run( int argc, char** argv, Boolean shutdownOption )
486 {
487 //
488 // Check for my command line options
489 //
|
490 tony 1.22
|
491 s.hills 1.33 for( int i = 1; i < argc; )
492 {
493 const char* arg = argv[i];
494
495 // Check for -option
496 if (*arg == '-')
497 {
498 // Get the option
499 const char* option = arg + 1;
500
501 if (strcmp(option, OPTION_INSTALL) == 0)
502 {
503 //
504 // Install as a NT service
505 //
506 char *opt_arg = NULL;
507 if (i+1 < argc)
508 {
509 opt_arg = argv[i+1];
510
511 }
512 s.hills 1.33 if(cimserver_install_nt_service(opt_arg))
513 {
514 //l10n
515 //cout << "\nPegasus installed as NT Service";
516 MessageLoaderParms parms(
517 "src.Server.cimserver.INSTALLED_NT_SERVICE",
|
518 david.dillard 1.39 "\nPegasus installed as a Windows service");
|
519 s.hills 1.33 cout << MessageLoader::getMessage(parms) << endl;
520 exit(0);
521 }
522 else
523 {
524 exit(0);
525 }
526 }
527 else if (strcmp(option, OPTION_REMOVE) == 0)
528 {
529 //
530 // Remove Pegasus as an NT service
531 //
532 char *opt_arg = NULL;
533 if (i+1 < argc)
534 {
535 opt_arg = argv[i+1];
536 }
537 if(cimserver_remove_nt_service(opt_arg))
538 {
539 //l10n
540 s.hills 1.33 //cout << "\nPegasus removed as NT Service";
541 MessageLoaderParms parms(
542 "src.Server.cimserver.REMOVED_NT_SERVICE",
|
543 david.dillard 1.39 "\nPegasus removed as a Windows service");
|
544 s.hills 1.33 cout << MessageLoader::getMessage(parms) << endl;
545 exit(0);
546 }
547 else
548 {
549 exit(0);
550 }
551
552 }
553 else if (strcmp(option, OPTION_START) == 0)
554 {
555 //
556 // Start as a NT service
557 //
558 char *opt_arg = NULL;
|
559 a.dunfey 1.40 int num_args = 0;
|
560 s.hills 1.33 if (i+1 < argc)
561 {
562 opt_arg = argv[i+1];
|
563 a.dunfey 1.40 num_args = argc - 3;
|
564 s.hills 1.33 }
|
565 a.dunfey 1.40 else
566 {
567 num_args = argc - 2;
568 }
569
570 char **service_args = &argv[1];
571 if(cimserver_start_nt_service(opt_arg, num_args, service_args))
|
572 s.hills 1.33 {
573 //l10n
574 //cout << "\nPegasus started as NT Service";
575 MessageLoaderParms parms(
576 "src.Server.cimserver.STARTED_NT_SERVICE",
|
577 david.dillard 1.39 "\nPegasus started as a Windows service");
|
578 s.hills 1.33 cout << MessageLoader::getMessage(parms) << endl;
579 exit(0);
580 }
581 else
582 {
583 exit(0);
584 }
585 }
586 else if (strcmp(option, OPTION_STOP) == 0)
587 {
588 //
589 // Stop as a NT service
590 //
591 char *opt_arg = NULL;
592 if (i+1 < argc)
593 {
594 opt_arg = argv[i+1];
595 }
596 if(cimserver_stop_nt_service(opt_arg))
597 {
598 //l10n
599 s.hills 1.33 //cout << "\nPegasus stopped as NT Service";
600 MessageLoaderParms parms(
601 "src.Server.cimserver.STOPPED_NT_SERVICE",
|
602 david.dillard 1.39 "\nPegasus stopped as a Windows service");
|
603 s.hills 1.33 cout << MessageLoader::getMessage(parms) << endl;
604 exit(0);
605 }
606 else
607 {
608 exit(0);
609 }
610 }
611 else
612 i++;
613 }
614 else
615 i++;
616 }
617
618 //
619 // Signal ourself as running
620 //
621
622 if( !shutdownOption )
623 _alreadyRunning.Init();
624 s.hills 1.33
625 //
626 // Check if already running
627 //
628 // Hmm, when starting as a service, should we do this here (before
629 // starting the control dispatcher)? If we do then the SCM reports
630 // a dumb message to the user. If we don't, and it in the serviceProc
631 // then the service will start up then die silently.
632 //
633
634 if( !shutdownOption && _alreadyRunning.IsAlreadyRunning() )
635 {
636 MessageLoaderParms parms(
637 "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
638 "Unable to start CIMServer.\nCIMServer is already running." );
639 Logger::put(
640 Logger::ERROR_LOG, "CIMServer", Logger::SEVERE,
641 MessageLoader::getMessage(parms) );
642 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
643 return 1;
644 }
645 s.hills 1.33
646 //
647 // Check if running from a console window. If so then just run
648 // as a console process.
649 //
650
651 char console_title[ _MAX_PATH ] = {0};
652 if( GetConsoleTitle( console_title, _MAX_PATH ) > 0 )
653 {
654 SetConsoleCtrlHandler( ControlHandler, TRUE );
655
656 return cimserver_run( argc, argv, shutdownOption );
657 }
658
659 //
660 // Run as a service
661 //
662
663 pegasus_service_event = CreateEvent( NULL, FALSE, FALSE, NULL );
664
665 Service::ReturnCode status;
666 s.hills 1.33 status = pegasus_service.Run( cimserver_windows_main );
667
668 if( status != Service::SERVICE_RETURN_SUCCESS )
669 {
670 // todo: put into localized messages when messages unfreezes.
671 Logger::put_l(
672 Logger::ERROR_LOG, "CIMServer", Logger::SEVERE,
673 "src.Server.cimserver_windows.LISTENING_ON_HTTP_PORT",
674 "Error during service run: code = $0.", status );
675 return 1;
676 }
677
678 return 0;
679 }
|