Package: and
Version: 1.2.2-1
Severity: wishlist
Tags: patch

Hi,

the attached patch adds a '-f' switch to and(8) that causes it to stay in
the foreground. This is useful when running it under a service monitor like
runit.

Thanks

Andras

-- 
                 Andras Korn <korn at chardonnay.math.bme.hu>
                 <http://chardonnay.math.bme.hu/~korn/> QOTD:
                    Barium: what you do with dead chemists.
diff -u -r and-1.2.2/and.8.man and-1.2.2+fg/and.8.man
--- and-1.2.2/and.8.man 2006-06-11 14:24:31.752873281 +0200
+++ and-1.2.2+fg/and.8.man      2006-06-11 14:23:49.636154000 +0200
@@ -5,7 +5,7 @@
 
 .SH "SYNOPSIS"
 .B and
-.RB [ \-htvsx ]
+.RB [ \-htvsxf ]
 .RB [ \-i
 .IR interval ]
 .RB [ \-c
@@ -101,6 +101,10 @@
 Run in full operational mode, i.e. really renice or kill things.
 This is the default.
 
+.TP 0.5i
+.B \-f
+Foreground mode. Don't daemonize.
+
 .SH "SIGNALS"
 
 On
diff -u -r and-1.2.2/and.c and-1.2.2+fg/and.c
--- and-1.2.2/and.c     2004-04-05 21:19:01.000000000 +0200
+++ and-1.2.2+fg/and.c  2006-06-11 14:21:01.217289000 +0200
@@ -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;
 }

Reply via email to