diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-09-28 17:34:44 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-09-28 17:34:44 -0400 |
commit | 382d597d018efcab0bb2cec19cb257e8048ba913 (patch) | |
tree | e0ff8c88bc426dc4e4bb73afb2c4adea650f3b4a | |
parent | 6215cf66a42ee436380f133daf13254030d0792e (diff) | |
download | gpsd-382d597d018efcab0bb2cec19cb257e8048ba913.tar.gz |
Eliminate a static global in favor of testing whether we're backgrounded.
-rw-r--r-- | gpsd.c | 7 |
1 files changed, 2 insertions, 5 deletions
@@ -139,7 +139,6 @@ static const int af = AF_INET; static fd_set all_fds; static int maxfd; -static bool in_background = false; #ifndef FORCE_GLOBAL_ENABLE static bool listen_global = false; #endif /* FORCE_GLOBAL_ENABLE */ @@ -236,7 +235,7 @@ void gpsd_report(int errlevel, const char *fmt, ...) visibilize(buf2, sizeof(buf2), buf); - if (in_background) + if (getpid() == getsid(getpid())) syslog((errlevel == 0) ? LOG_ERR : LOG_NOTICE, "%s", buf2); else (void)fputs(buf2, stderr); @@ -2026,9 +2025,7 @@ int main(int argc, char *argv[]) /* might be time to daemonize */ if (go_background) { /* not SuS/POSIX portable, but we have our own fallback version */ - if (daemon(0, 0) == 0) - in_background = true; - else + if (daemon(0, 0) != 0) gpsd_report(LOG_ERROR,"demonization failed: %s\n",strerror(errno)); } |