File: 000_and.c.diff

package info (click to toggle)
and 1.2.2-4.2
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 352 kB
  • sloc: ansic: 1,198; sh: 253; makefile: 164
file content (62 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#
# Description: Allow and to run in foreground
# Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=372746
# From: Patrick Schemitz <corediver@beamspot.de>
#
--- and-1.2.2.orig/and.c
+++ and-1.2.2/and.c
@@ -156,6 +156,7 @@
 struct {
   char hostname [512];
   int test;
+  int foreground;
   char *program;
   char *config_file;
   char *database_file;
@@ -179,6 +180,7 @@
 void set_defaults (int argc, char **argv)
 {
   and_config.test = 0;
+  and_config.foreground = 0;
   and_config.verbose = 0;
   and_config.to_stdout = 0;
   and_config.program = argv[0];
@@ -884,7 +886,7 @@
 
 void and_getopt (int argc, char** argv)
 {
-#define OPTIONS "c:d:i:vstxh"
+#define OPTIONS "c:d:i:vstxfh"
   int opt, value;
   opt = getopt(argc,argv,OPTIONS);
   while (opt != -1) {
@@ -921,12 +923,16 @@
     case 'x':
       and_config.test = 0;
       break;
+    case 'f':
+      and_config.foreground = 1;
+      break;
     case 'h':
       printf("auto nice daemon version %s (%s)\n"
 	     "%s [-v] [-s]  [-t] [-x] [-c configfile] [-d databasefile] [-i interval]\n"
 	     "-v: verbosity -v, -vv, -vvv etc\n"
 	     "-s: log to stdout (default is syslog, or debug.and)\n"
 	     "-x: really execute renices and kills (default)\n"
+             "-f: don't daemonize, stay in foreground\n"
 	     "-t: test configuration (don't really renice)\n"
 	     "-i interval: loop interval in seconds (default %i)\n"
 	     "-c configfile: specify config file (default %s)\n"
@@ -986,7 +992,11 @@
   if (and_config.test) {
     and_worker();
   } else {
-    if (fork() == 0) and_worker();
+    if (and_config.foreground) {
+      and_worker();
+    } else {
+      if (fork() == 0) and_worker();
+    }
   }
   return 0;
 }