summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-09-28 17:34:44 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-09-28 17:34:44 -0400
commit382d597d018efcab0bb2cec19cb257e8048ba913 (patch)
treee0ff8c88bc426dc4e4bb73afb2c4adea650f3b4a
parent6215cf66a42ee436380f133daf13254030d0792e (diff)
downloadgpsd-382d597d018efcab0bb2cec19cb257e8048ba913.tar.gz
Eliminate a static global in favor of testing whether we're backgrounded.
-rw-r--r--gpsd.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/gpsd.c b/gpsd.c
index a7d50d41..617c73e1 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -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));
}