From 323feb7398527294d1102e24470c0761b1661d99 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 30 May 2014 13:57:25 +0200 Subject: echo_srv: Write pidfile after we setup the listeners. Signed-off-by: Andreas Schneider Reviewed-by: Michael Adam --- tests/echo_srv.c | 20 +++++++++++--------- 1 file 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); -- cgit