Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_3251_Regression / server.cpp
blobe8fc3c46a4322539da684ca841616c51f3c9af54
1 #include "ace/ARGV.h"
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")));
12 bShutdown = true;
14 #endif
16 int
17 ACE_TMAIN(int, ACE_TCHAR ** argv)
19 int result = 0;
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);
25 pid_t pid = -1;
26 pid = ACE_OS::fork();
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")));
32 ACE_OS::sleep(5);
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);
37 return 0;
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;
44 ACE_TCHAR signum[64];
45 ACE_OS::sprintf(signum, ACE_TEXT("%d"), SIGUSR1);
47 ACE_ARGV args;
48 args.add(argv[0]);
49 args.add(ACE_TEXT("-s"));
50 args.add(signum);
52 result = serviceConfig.open (
53 args.argc(),
54 args.argv(),
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
60 if(0 != result)
62 ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.open failed\n")));
63 return result;
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"));
70 #else
71 result = serviceConfig.process_file(ACE_TEXT("Bug_3251.conf.xml"));
72 #endif
73 if(0 != result)
75 ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.process_file failed\n")));
76 return result;
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")));
81 while(!bShutdown)
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())
88 if(bShutdown)
89 break;
91 else if(0 != result)
93 ACE_DEBUG ((
94 LM_INFO,
95 ACE_TEXT ("(%P|%t) run_event_loop failed (%s, %d)\n"),
96 ACE_OS::strerror(ACE_OS::last_error()),
97 ACE_OS::last_error()
98 ));
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();
106 if(0 != result)
108 ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.fini_svcs failed\n")));
109 return result;
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();
115 if(0 != result)
117 ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.close failed\n")));
118 return result;
120 ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.close done\n")));
122 return result;
123 } /* end of if */
124 else // fork failed
126 ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: fork failed\n")));
127 return 1;
128 } /* end of else */
129 #else
130 ACE_UNUSED_ARG (argv);
131 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Fork not available\n")));
132 #endif
133 return result;