diff options
author | Chris Dunlap <[email protected]> | 2014-08-27 13:18:01 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2014-09-02 14:18:53 -0700 |
commit | 5a8855b716ad9177ed393769834ce9e08d2a3cfe (patch) | |
tree | 4d05713b4b733c65b847f143d096c0c4050de631 /cmd/zed/zed_conf.c | |
parent | 6c3c3387b1cc81bb428a934a8a97c3c583fb1280 (diff) |
Fix race condition with zed pidfile creation
When the zed is started as a forking daemon (by default),
a race-condition exists where the parent process can terminate before
the pidfile has been created by the grandchild process. When invoked
as a Type=forking systemd service, this can result in the following:
systemd[1]: Starting ZFS Event Daemon (zed)...
systemd[1]: PID file /var/run/zed.pid not readable (yet?) after start.
This commit adds a daemonize pipe to allow the grandchild process to
signal the parent process that initialization is complete (and the
pidfile has been created). The parent process will wait for this
notification before exiting.
Signed-off-by: Chris Dunlap <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Issue #2252
Diffstat (limited to 'cmd/zed/zed_conf.c')
-rw-r--r-- | cmd/zed/zed_conf.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/cmd/zed/zed_conf.c b/cmd/zed/zed_conf.c index 78b45e910..e6f601f3a 100644 --- a/cmd/zed/zed_conf.c +++ b/cmd/zed/zed_conf.c @@ -430,7 +430,13 @@ zed_conf_scan_dir(struct zed_conf *zcp) /* * Write the PID file specified in [zcp]. * Return 0 on success, -1 on error. - * XXX: This must be called after fork()ing to become a daemon. + * This must be called after fork()ing to become a daemon (so the correct PID + * is recorded), but before daemonization is complete and the parent process + * exits (for synchronization with systemd). + * FIXME: Only update the PID file after verifying the PID previously stored + * in the PID file no longer exists or belongs to a foreign process + * in order to ensure the daemon cannot be started more than once. + * (This check is currently done by zed_conf_open_state().) */ int zed_conf_write_pid(struct zed_conf *zcp) |