diff options
author | Andreas Schneider <asn@samba.org> | 2014-05-30 13:57:25 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-05-31 03:42:19 +0200 |
commit | 323feb7398527294d1102e24470c0761b1661d99 (patch) | |
tree | 08c065b882b010633ff2629577c5c918350fbf84 /tests/echo_srv.c | |
parent | 1dbbd7211cef0434d89d12fd28cfd28274b57956 (diff) | |
download | socket_wrapper-323feb7398527294d1102e24470c0761b1661d99.tar.gz socket_wrapper-323feb7398527294d1102e24470c0761b1661d99.tar.xz socket_wrapper-323feb7398527294d1102e24470c0761b1661d99.zip |
echo_srv: Write pidfile after we setup the listeners.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'tests/echo_srv.c')
-rw-r--r-- | tests/echo_srv.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/tests/echo_srv.c b/tests/echo_srv.c index 88d8170..e3973f5 100644 --- a/tests/echo_srv.c +++ b/tests/echo_srv.c @@ -153,7 +153,7 @@ static int pidfile(const char *path) return 0; } -static int become_daemon(struct echo_srv_opts *opts) +static int become_daemon(void) { int ret; pid_t child_pid; @@ -178,13 +178,6 @@ static int become_daemon(struct echo_srv_opts *opts) chdir(WORKING_DIR); #endif - ret = pidfile(opts->pidfile); - if (ret != 0) { - fprintf(stderr, "Cannot create pidfile %s: %s\n", - opts->pidfile, strerror(ret)); - return ret; - } - ret = setsid(); if (ret == -1) { ret = errno; @@ -895,7 +888,7 @@ int main(int argc, char **argv) } if (opts.daemon) { - ret = become_daemon(&opts); + ret = become_daemon(); if (ret != 0) { fprintf(stderr, "Cannot become daemon: %s\n", strerror(ret)); goto done; @@ -908,6 +901,15 @@ int main(int argc, char **argv) goto done; } + if (opts.daemon && opts.pidfile != NULL) { + ret = pidfile(opts.pidfile); + if (ret != 0) { + fprintf(stderr, "Cannot create pidfile %s: %s\n", + opts.pidfile, strerror(ret)); + goto done; + } + } + echo(sock, &opts); close(sock); |