summaryrefslogtreecommitdiffstats
path: root/usr.sbin/powerd
diff options
context:
space:
mode:
authornjl <njl@FreeBSD.org>2005-10-20 05:12:20 +0000
committernjl <njl@FreeBSD.org>2005-10-20 05:12:20 +0000
commitcd579e831a1baa37bf0078180c99d3f610b19217 (patch)
tree42aa1071c35792ded258a54b621c535a2013ae8e /usr.sbin/powerd
parentaf52aff9fb7105bd301d51c309d414262a0d0286 (diff)
downloadFreeBSD-src-cd579e831a1baa37bf0078180c99d3f610b19217.zip
FreeBSD-src-cd579e831a1baa37bf0078180c99d3f610b19217.tar.gz
Set the signal handlers before creating the thread. This is so it inherits
the parent's signal mask. Once daemon() forked, signals would be ignored in the child thread. While I'm here, check the return value of daemon(). This fixes termination in the daemon case (bug introduced in last commit). Noticed by: Frederik Lindberg
Diffstat (limited to 'usr.sbin/powerd')
-rw-r--r--usr.sbin/powerd/powerd.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/usr.sbin/powerd/powerd.c b/usr.sbin/powerd/powerd.c
index 123e649..301ca53 100644
--- a/usr.sbin/powerd/powerd.c
+++ b/usr.sbin/powerd/powerd.c
@@ -479,6 +479,15 @@ main(int argc, char * argv[])
if (read_freqs(&numfreqs, &freqs, &mwatts))
err(1, "error reading supported CPU frequencies");
+ /*
+ * Exit cleanly on signals; devd may send a SIGPIPE if it dies. We
+ * do this before acline_init() since it may create a thread and we
+ * want it to inherit our signal mask.
+ */
+ signal(SIGINT, handle_sigs);
+ signal(SIGTERM, handle_sigs);
+ signal(SIGPIPE, SIG_IGN);
+
/* Decide whether to use ACPI or APM to read the AC line status. */
acline_init();
@@ -494,12 +503,14 @@ main(int argc, char * argv[])
}
warn("cannot open pid file");
}
- daemon(0, 0);
+ if (daemon(0, 0) != 0) {
+ warn("cannot enter daemon mode, exiting");
+ pidfile_remove(pfh);
+ exit(EXIT_FAILURE);
+
+ }
pidfile_write(pfh);
}
- signal(SIGINT, handle_sigs);
- signal(SIGTERM, handle_sigs);
- signal(SIGPIPE, SIG_IGN);
/* Main loop. */
for (;;) {
OpenPOWER on IntegriCloud