100 (void)l; (void)srcaddr;
104 g_message(
"%s.%d: Received back alive notification (type %d) over the 'wire'."
110 g_warning(
"%s.%d: Received a FrameSet of type %d over the 'wire' (OOPS!)."
113 DEBUGMSG3(
"%s.%d: Received a FrameSet of type %d over the 'wire'."
158 g_message(
"%s: exiting on %s.",
procname, (
sigterm ?
"SIGTERM" :
"SIGINT"));
174 fprintf(stderr,
"usage: %s [arguments...]\n", cmdname);
175 fprintf(stderr,
"Legal arguments are:\n");
176 fprintf(stderr,
"\t-c --cmaaddr <address:port-of-CMA>\n");
177 fprintf(stderr,
"\t-b --bind <address:port-to-listen-on-locally>\n");
178 fprintf(stderr,
"\t-t --ttl <multi cast ttl (default == 31)>\n");
181 fprintf(stderr,
"\t-f --foreground (stay in foreground.)\n");
183 fprintf(stderr,
"\t-k --kill (send SIGTERM to the running service.)\n");
184 fprintf(stderr,
"\t-p --pidfile <pid-file-pathname>.\n");
185 fprintf(stderr,
"\t-s --status (report nanoprobe status)\n");
186 fprintf(stderr,
"\t-d --debug <debug-level (0-5)>\n");
188 fprintf(stderr,
"\t-d --debug <debug-level (0-5)>\n");
200 static char defaultCMAaddr[] =
CMAADDR;
206 #ifdef HAVE_SIGACTION
207 struct sigaction sigact;
209 static char *
localaddr = defaultlocaladdress;
210 static char *
cmaaddr = defaultCMAaddr;
211 static int debug = 0;
212 gboolean anyportpermitted = TRUE;
213 static int mcast_ttl = 31;
214 static gboolean stay_in_foreground = FALSE;
215 static gboolean dostatusonly = FALSE;
216 static gboolean dokillonly = FALSE;
217 static char* pidfile = NULL;
222 GError *error = NULL;
223 static GOptionEntry long_options[] = {
224 {
"bind",
'b', 0, G_OPTION_ARG_STRING, &
localaddr,
"<address:port-to-listen-on-locally>", NULL},
225 {
"cmaaddr",
'c', 0, G_OPTION_ARG_STRING, &
cmaaddr,
"<address:port-of-CMA>", NULL},
226 {
"debug",
'd', 0, G_OPTION_ARG_INT, &debug,
" set debug level", NULL},
227 {
"ttl",
't', 0, G_OPTION_ARG_INT, &mcast_ttl,
"<multicast-ttl> (default is 31)", NULL},
228 {
"kill",
'k', 0, G_OPTION_ARG_NONE, &dokillonly,
"send SIGTERM to the running service", NULL},
229 {
"pidfile",
'p', 0, G_OPTION_ARG_STRING, &pidfile,
"<pid-file-pathname>", NULL},
230 {
"status",
's', 0, G_OPTION_ARG_NONE, &dostatusonly,
"report nanoprobe status", NULL},
232 {
"foreground",
'f', 0, G_OPTION_ARG_NONE, &stay_in_foreground,
"stay in foreground", NULL},
234 {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
237 GOptionContext *context = g_option_context_new(
"- start nanoprobe");
238 g_option_context_add_main_entries(context, long_options, NULL);
242 if(!(g_option_context_parse(context, &argc, &argv, &error)))
244 g_print(
"option parsing failed %s\n", error->message);
251 if(debug > 0 && debug <= 5) {
258 if (pidfile == NULL) {
271 fprintf(stderr,
"%s: could not stop service [%s]\n",
"nanoprobe", g_strerror(errno));
272 g_warning(
"%s: could not stop service [%s]\n",
"nanoprobe", g_strerror(errno));
287 g_warning(
"This OS DOES NOT support dual ipv4/v6 sockets - this may not work!!");
289 #ifndef HAVE_SIGACTION
291 if (stay_in_foreground) {
299 memset(&sigact, 0,
sizeof(sigact));
301 sigaction(SIGTERM, &sigact, NULL);
302 if (stay_in_foreground) {
303 struct sigaction oldact;
304 sigaction(SIGINT, &sigact, &oldact);
305 if (oldact.sa_handler == SIG_IGN) {
307 sigaction(SIGINT, &oldact, NULL);
311 struct sigaction ignoreme;
312 memset(&ignoreme, 0,
sizeof(ignoreme));
313 ignoreme.sa_handler = SIG_IGN;
314 sigaction(SIGINT, &ignoreme, NULL);
316 sigaction(SIGUSR1, &sigact, NULL);
317 sigaction(SIGUSR2, &sigact, NULL);
324 g_return_val_if_fail(NULL != nettransport, 2);
329 g_info(
"CMA address: %s", cmaaddr);
330 if (destaddr->
ismcast(destaddr)) {
331 if (!nettransport->
setmcast_ttl(nettransport, mcast_ttl)) {
332 g_warning(
"Unable to set multicast TTL to %d [%s %d]", mcast_ttl
333 , g_strerror(errno), errno);
337 g_return_val_if_fail(NULL != destaddr, 3);
338 g_return_val_if_fail(destaddr->
port(destaddr) != 0, 4);
344 g_return_val_if_fail(NULL != localbindaddr, 5);
348 bindret = nettransport->
bindaddr(nettransport, localbindaddr, anyportpermitted);
349 UNREF(localbindaddr);
352 if (anyportpermitted) {
353 guint8
anyaddr[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
355 g_return_val_if_fail(NULL != localbindaddr, 5);
356 bindret = nettransport->
bindaddr(nettransport, localbindaddr, FALSE);
357 UNREF(localbindaddr);
358 localbindaddr = NULL;
359 g_return_val_if_fail(bindret, 6);
361 g_warning(
"Cannot bind to local address [%s] and cannot use any free port.", localaddr);
369 g_info(
"Local address: %s", boundstr);
373 g_warning(
"Unable to determine local address!");
379 netpkt =
netgsource_new(nettransport, NULL, G_PRIORITY_HIGH, FALSE, NULL, 0, NULL);
385 otherlistener->
associate(otherlistener,netpkt);
389 UNREF(otherlistener);
403 mainloop = g_main_loop_new(g_main_context_default(), TRUE);
435 g_warning(
"Too many objects (%d) alive at end of test.",
439 g_info(
"No objects left alive. Awesome!");