chiark / gitweb /
Useful functions (u_daemon and versioncmp) moved to mLib.
[tripe] / client / tripectl.c
index ea8aadff7599c8f9b6ea91b68a582f274ffb6153..b27d3fdcbf331da023c15009b7ebabf35ff0786d 100644 (file)
@@ -51,6 +51,7 @@
 #include <netdb.h>
 
 #include <mLib/alloc.h>
+#include <mLib/daemonize.h>
 #include <mLib/darray.h>
 #include <mLib/dstr.h>
 #include <mLib/mdwopt.h>
@@ -60,6 +61,7 @@
 #include <mLib/selbuf.h>
 #include <mLib/sig.h>
 #include <mLib/str.h>
+#include <mLib/versioncmp.h>
 
 #include "util.h"
 
@@ -163,6 +165,7 @@ static void cline(char *p, size_t len, void *b)
   } else if (strcmp(q, "INFO") == 0) {
     checkfg();
     puts(p);
+    fflush(stdout);
   } else if (strcmp(q, "OK") == 0) {
     checkfg();
     exit(0);
@@ -176,6 +179,7 @@ static void cline(char *p, size_t len, void *b)
   } else if (strcmp(q, "BGINFO") == 0) {
     checkbg(&p);
     puts(p);
+    fflush(stdout);
   } else if (strcmp(q, "BGFAIL") == 0) {
     checkbg(&p);
     die(EXIT_FAILURE, "%s", p);
@@ -191,6 +195,7 @@ static void sline(char *p, size_t len, void *b)
     exit(0);
   }
   puts(p);
+  fflush(stdout);
 }
 
 static void uline(char *p, size_t len, void *b)
@@ -340,6 +345,8 @@ int main(int argc, char *argv[])
 
   if ((p = getenv("TRIPEDIR")) != 0)
     dir = p;
+  if ((p = getenv("TRIPESOCK")) != 0)
+    sock = p;
 
   /* --- Parse the arguments --- */
 
@@ -476,7 +483,7 @@ int main(int argc, char *argv[])
        fclose(pidfp);
       closelog();
       if (f & f_daemon)
-       u_detach();
+       detachtty();
       execvp(DA(&spawnopts)[0], DA(&spawnopts));
       die(127, "couldn't exec `%s': %s", spawnpath, strerror(errno));
     }
@@ -501,7 +508,7 @@ int main(int argc, char *argv[])
   }
 
   if (f & f_daemon) {
-    if (u_daemon())
+    if (daemonize())
       die(EXIT_FAILURE, "error becoming daemon: %s", strerror(errno));
   }
   if (pidfp) {