chiark / gitweb /
Ignore boring return codes properly.
[tripe] / client / tripectl.c
index 514506162429860fd6047c85db2b49159c08b2ca..438edf376bf6dad65915e2eaf25a0c4655d14a0f 100644 (file)
@@ -92,6 +92,7 @@ static const char *bgtag = 0;
 #define f_noinput 64u
 #define f_warn 128u
 #define f_uclose 256u
+#define f_losing 512u
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -154,6 +155,7 @@ static void cline(char *p, size_t len, void *b)
   if (!p) {
     if (f & f_command)
       die(EXIT_FAILURE, "server dropped the connection");
+    f &= ~f_losing;
     exit(0);
   }
   q = str_getword(&p);
@@ -477,8 +479,6 @@ int main(int argc, char *argv[])
     die(EXIT_FAILURE, "couldn't set `%s' as current directory: %s",
        dir, strerror(errno));
   }
-  if (logname)
-    logfile(logname);
   if (!pidfile && (f & f_daemon) && ((f & f_syslog) || logname))
     pidfile = "tripectl.pid";
   if (pidfile && (pidfp = fopen(pidfile, "w")) == 0) {
@@ -519,11 +519,11 @@ int main(int argc, char *argv[])
       die(EXIT_FAILURE, "fork failed: %s", strerror(errno));
     if (!kid) {
       close(pfd[0]); close(efd[0]);
+      sigprocmask(SIG_SETMASK, &oldmask, 0);
       md[0].cur = pfd[1]; md[0].want = STDIN_FILENO;
       md[1].cur = pfd[1]; md[1].want = STDOUT_FILENO;
       md[2].cur = efd[1]; md[2].want = STDERR_FILENO;
       mdup(md, 3);
-      if (logfp) fclose(logfp);
       if (pidfp) fclose(pidfp);
       closelog();
       if (f & f_daemon) detachtty();
@@ -550,7 +550,10 @@ int main(int argc, char *argv[])
     }
   }
 
+  f |= f_losing; /* pessimism */
   u_setugid(u, g);
+  if (logname)
+    logfile(logname);
   if (f & f_daemon) {
     if (daemonize())
       die(EXIT_FAILURE, "error becoming daemon: %s", strerror(errno));