90527e6bb26f73ba9614bb9f54488bcc029775e5
[feed/routing.git] / batmand / patches / 0001-Allow-one-to-disable-forking-to-background-in-debug_.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Sun, 1 Dec 2013 14:39:00 +0100
3 Subject: Allow one to disable forking to background in debug_mode 0
4
5 ---
6 posix/init.c | 19 ++++++++++++++-----
7 1 file changed, 14 insertions(+), 5 deletions(-)
8
9 diff --git a/posix/init.c b/posix/init.c
10 index afd409f..901c65a 100644
11 --- a/posix/init.c
12 +++ b/posix/init.c
13 @@ -44,6 +44,7 @@
14 #define IOCSETDEV 1
15
16 int8_t stop;
17 +int no_detach = 0;
18
19
20
21 @@ -159,6 +160,7 @@ void apply_init_args( int argc, char *argv[] ) {
22 {"purge-timeout", required_argument, 0, 'q'},
23 {"disable-aggregation", no_argument, 0, 'x'},
24 {"disable-client-nat", no_argument, 0, 'z'},
25 + {"no-detach", no_argument, 0, 'D'},
26 {0, 0, 0, 0}
27 };
28
29 @@ -166,7 +168,7 @@ void apply_init_args( int argc, char *argv[] ) {
30 stop = 0;
31 prog_name = argv[0];
32
33 - while ( ( optchar = getopt_long( argc, argv, "a:A:bcd:hHio:g:p:r:s:vV", long_options, &option_index ) ) != -1 ) {
34 + while ( ( optchar = getopt_long( argc, argv, "a:A:bcd:hHio:g:p:r:s:vVD", long_options, &option_index ) ) != -1 ) {
35
36 switch ( optchar ) {
37
38 @@ -378,6 +380,11 @@ void apply_init_args( int argc, char *argv[] ) {
39 found_args++;
40 break;
41
42 + case 'D':
43 + no_detach = 1;
44 + found_args++;
45 + break;
46 +
47 case 'h':
48 default:
49 usage();
50 @@ -536,12 +543,14 @@ void apply_init_args( int argc, char *argv[] ) {
51 /* daemonize */
52 if (debug_level == 0) {
53
54 - if (my_daemon() < 0) {
55 + if (!no_detach) {
56 + if (my_daemon() < 0) {
57
58 - printf("Error - can't fork to background: %s\n", strerror(errno));
59 - restore_defaults();
60 - exit(EXIT_FAILURE);
61 + printf("Error - can't fork to background: %s\n", strerror(errno));
62 + restore_defaults();
63 + exit(EXIT_FAILURE);
64
65 + }
66 }
67
68 openlog("batmand", LOG_PID, LOG_DAEMON);