From owner-freebsd-current Thu Nov 18 21: 8:30 1999 Delivered-To: freebsd-current@freebsd.org Received: from khavrinen.lcs.mit.edu (khavrinen.lcs.mit.edu [18.24.4.193]) by hub.freebsd.org (Postfix) with ESMTP id A2B7D15260 for ; Thu, 18 Nov 1999 21:08:28 -0800 (PST) (envelope-from wollman@khavrinen.lcs.mit.edu) Received: (from wollman@localhost) by khavrinen.lcs.mit.edu (8.9.3/8.9.3) id AAA43114; Fri, 19 Nov 1999 00:08:25 -0500 (EST) (envelope-from wollman) Date: Fri, 19 Nov 1999 00:08:25 -0500 (EST) From: Garrett Wollman Message-Id: <199911190508.AAA43114@khavrinen.lcs.mit.edu> To: Luoqi Chen Cc: current@FreeBSD.ORG Subject: Re: init runs with console as control terminal? In-Reply-To: <199911190359.WAA06557@lor.watermarkgroup.com> References: <199911190359.WAA06557@lor.watermarkgroup.com> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG < said: > Hmm, good point. So I still need to find a way to start up rc5des, it seems > that rc5des installs a SIGHUP handler and therefore nohup is > useless. Bug the authors to fix it? daemon(3) is provided for a reason! Here's my version of a simple daemonizing program.... Neither TIOCNOTTY nor setpgid() is sufficient to detach from a terminal session in a POSIX environment; setsid() is required. daemon(3) does a nice job of encapsulating this along with the other more obvious prerequisites. ------------------------------------ #include #include #include int main(int argv, char *argv) { static char *shargs[4] = { "sh", "-c" }; if (argv[1] == 0 || argv[2] != 0) errx(1, "must specify exactly one argument"); if (daemon(1, 0) < 0) err(1, "daemon"); shargs[2] = argv[1]; execv("/bin/sh", shargs); /* * Not much point in printing an error message since the tty * is already gone. It doesn't really matter what we return * here, either, since the only one waiting is init. */ return 1; } ------------------------------------ -GAWollman -- Garrett A. Wollman | O Siem / We are all family / O Siem / We're all the same wollman@lcs.mit.edu | O Siem / The fires of freedom Opinions not those of| Dance in the burning flame MIT, LCS, CRS, or NSA| - Susan Aglukark and Chad Irschick To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message