X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/b9537f3be119d9a099c96bbf9329fcd5b51e5312..d3731285e1e3638e7f4877c78ed9e27e1fd72233:/client/tripectl.c diff --git a/client/tripectl.c b/client/tripectl.c index 51450616..438edf37 100644 --- a/client/tripectl.c +++ b/client/tripectl.c @@ -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));