From d120710c956dac111ee2a0c3bfa66d1dde5aa0a8 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 24 Mar 2026 20:38:45 +0100 Subject: [PATCH] nbd-server: drop the double-fork ... as this breaks as systemd service: This is of type 'forking', so the (first) fork becomes the main and controlling process. The second fork makes the main process exit, and the service is stopped. Calling setsid() should be sufficient to detatch from terminal. Closes: https://github.com/NetworkBlockDevice/nbd/issues/182 --- nbd-server.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/nbd-server.c b/nbd-server.c index 6a87d445..b77429ba 100644 --- a/nbd-server.c +++ b/nbd-server.c @@ -3816,12 +3816,6 @@ void daemonize() { if(dup2(2, newfd) < 0) { err("dup2 stderr"); } - child=fork(); - if(child < 0) { - err("fork"); - } else if(child > 0) { - exit(EXIT_SUCCESS); - } FILE*pidf=fopen(pidfname, "w"); if(pidf) { fprintf(pidf,"%d\n", (int)getpid());