From patchwork Sat Oct 8 10:02:24 2005 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Enrico Scholz X-Patchwork-Id: 12059 Received: from moutng.kundenserver.de ([212.227.126.188]) by www.linuxtv.org with esmtp (Exim 4.50) id 1EOBXO-0004Kt-96 for vdr@linuxtv.org; Sat, 08 Oct 2005 12:02:42 +0200 Received: from p54B4E9F0.dip.t-dialin.net [84.180.233.240] (helo=mail.bigo.ensc.de) by mrelayeu.kundenserver.de with ESMTP (Nemesis), id 0ML29c-1EOBXA1BLb-0005bK; Sat, 08 Oct 2005 12:02:28 +0200 Received: from kosh.bigo.ensc.de (kosh.bigo.ensc.de [192.168.46.2]) by mail.bigo.ensc.de (8.13.4/8.13.3) with ESMTP id j98A2Pw5002144 for ; Sat, 8 Oct 2005 12:02:26 +0200 Received: (from ensc@localhost) by kosh.bigo.ensc.de (8.13.4/8.13.3/Submit) id j98A2Phw010005; Sat, 8 Oct 2005 12:02:25 +0200 To: vdr@linuxtv.org From: Enrico Scholz Date: Sat, 08 Oct 2005 12:02:24 +0200 Message-ID: <87mzlk9vin.fsf@kosh.bigo.ensc.de> User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.17 (Jumbo Shrimp, linux) MIME-Version: 1.0 X-Provags-ID: kundenserver.de abuse@kundenserver.de login:cf015127439e61eb16a460417aa16ac1 Subject: [vdr] [PATCH] Use daemon(3) instead of forking manually X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Klaus Schmidinger's VDR List-Id: Klaus Schmidinger's VDR List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2005 10:02:42 -0000 Status: O X-Status: X-Keywords: X-UID: 5390 Hello, the attached patch uses daemon(3) instead of forking manually. This executes setsid(2) (which is missing currently) and gives better FDs 0-2 (it is a little bit unclean to use these standard fds for other things). daemon(3) is called with a set 'nochdir' flag to allow core-file generation in writable directories. Enrico 2005-09-17 17:52 Enrico Scholz - vdr.c: use daemon(3) instead of forking manually; this executes 'setsid()' and creates better FDs 0-2 --- vdr-1.3.32/vdr.c.daemon 2005-09-17 13:40:57.000000000 +0200 +++ vdr-1.3.32/vdr.c 2005-09-17 13:46:41.000000000 +0200 @@ -508,17 +508,11 @@ // Daemon mode: if (DaemonMode) { - pid_t pid = fork(); - if (pid < 0) { - fprintf(stderr, "%m\n"); + if (daemon(1, 0)==-1) { esyslog("ERROR: %m"); + perror("daemon()"); return 2; - } - if (pid != 0) - return 0; // initial program immediately returns - fclose(stdin); - fclose(stdout); - fclose(stderr); + } } else if (Terminal) { // Claim new controlling terminal