From 81a8e138c7781fef5c6daacef2567f535f1f0b84 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 18 May 2011 14:07:05 -0300 Subject: [PATCH] tools/dirtpan/dirtpan.c: new option -b to background/daemonize - dirtpan.c (usage): added detailed description of the arguments - dirtpan.c (usage, main): new option -b to daemonize after initialization --- tools/dirtpan/dirtpan.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/dirtpan/dirtpan.c b/tools/dirtpan/dirtpan.c index 737e523..6b0c1dc 100644 --- a/tools/dirtpan/dirtpan.c +++ b/tools/dirtpan/dirtpan.c @@ -533,7 +533,14 @@ static int open_tun(const char *cmd) static void usage(const char *name) { fprintf(stderr, -"usage: %s [-d [-d]] pan_id src_addr dst_addr [command]\n" +"usage: %s [-b] [-d [-d]] pan_id src_addr dst_addr [command]\n\n" +" pan_id PAN (network) identifier\n" +" src_addr source short address\n" +" dst_addr destination short address\n" +" command configuration command to run after creating the TUN interface.\n" +" The environment variable $ITF is set to the interface name.\n\n" +" -b background the process after initialization\n" +" -d ... increase verbosity of debug output\n" , name); exit(1); } @@ -557,10 +564,14 @@ int main(int argc, char **argv) { const char *cmd = NULL; uint16_t pan, src, dst; + int foreground = 1; int c; - while ((c = getopt(argc, argv, "d")) != EOF) + while ((c = getopt(argc, argv, "bd")) != EOF) switch (c) { + case 'b': + foreground = 0; + break; case 'd': debug++; break; @@ -583,8 +594,10 @@ int main(int argc, char **argv) net = open_net(pan, src, dst); tun = open_tun(cmd); - while (1) - event(); + + if (foreground || !daemonize()) + while (1) + event(); return 0; }