return 0;
}
-static int become_daemon(struct echo_srv_opts *opts)
+static int become_daemon(void)
{
int ret;
pid_t child_pid;
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;
}
if (opts.daemon) {
- ret = become_daemon(&opts);
+ ret = become_daemon();
if (ret != 0) {
fprintf(stderr, "Cannot become daemon: %s\n", strerror(ret));
goto done;
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);