2 #include "ace/Reactor.h"
3 #include "ace/Signal.h"
4 #include "ace/Service_Config.h"
5 #include "ace/Log_Msg.h"
7 #if !defined (ACE_LACKS_FORK)
8 static volatile bool bShutdown
= false;
9 static void shutdown_func(int)
11 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) Shutdown requested\n")));
17 ACE_TMAIN(int, ACE_TCHAR
** argv
)
20 #if !defined (ACE_LACKS_FORK)
21 ACE_Sig_Action
sigUSR2((ACE_SignalHandler
) shutdown_func
, SIGUSR2
);
22 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) SIGUSR2 shutdown handler installed\n")));
23 ACE_UNUSED_ARG(sigUSR2
);
27 ACE_Log_Msg::instance ()->sync (argv
[0]); // Make %P|%t work right
29 if (pid
== 0) // child
31 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) child waiting\n")));
33 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) signaling parent\n")));
34 result
= ACE_OS::kill(ACE_OS::getppid(), SIGUSR2
);
35 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) signaled parent\n")));
36 // ACE_OS::sleep (100000);
39 else if (pid
> 0) // parent
41 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) parent using ACE_Service_Config, pid=%d\n"), pid
));
42 ACE_Service_Config serviceConfig
;
45 ACE_OS::sprintf(signum
, ACE_TEXT("%d"), SIGUSR1
);
49 args
.add(ACE_TEXT("-s"));
52 result
= serviceConfig
.open (
55 ACE_DEFAULT_LOGGER_KEY
,
56 1, // ignore_static_svcs = 1,
57 1, // ignore_default_svc_conf_file = 0,
58 0 // ignore_debug_flag = 0
62 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("(%P|%t) Error: serviceConfig.open failed\n")));
65 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) serviceConfig.open done\n")));
67 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) serviceConfig.process_file ...\n")));
68 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
69 result
= serviceConfig
.process_file(ACE_TEXT("Bug_3251.conf"));
71 result
= serviceConfig
.process_file(ACE_TEXT("Bug_3251.conf.xml"));
75 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("(%P|%t) Error: serviceConfig.process_file failed\n")));
78 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) serviceConfig.process_file done\n")));
80 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("run_event_loop ...\n")));
83 ACE_OS::last_error(0);
84 result
= ACE_Reactor::run_event_loop();
85 // reenter loop on EINTR
86 if(0 != result
&& EINTR
== ACE_OS::last_error())
95 ACE_TEXT ("(%P|%t) run_event_loop failed (%s, %d)\n"),
96 ACE_OS::strerror(ACE_OS::last_error()),
102 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) run_event_loop done\n")));
104 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) serviceConfig.fini_svcs ...\n")));
105 result
= serviceConfig
.fini_svcs();
108 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("(%P|%t) Error: serviceConfig.fini_svcs failed\n")));
111 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) serviceConfig.fini_svcs done\n")));
113 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) serviceConfig.close ...\n")));
114 result
= serviceConfig
.close();
117 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("(%P|%t) Error: serviceConfig.close failed\n")));
120 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("(%P|%t) serviceConfig.close done\n")));
126 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("(%P|%t) Error: fork failed\n")));
130 ACE_UNUSED_ARG (argv
);
131 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Fork not available\n")));