Date: Fri, 19 Nov 1999 00:08:25 -0500 (EST) From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu> To: Luoqi Chen <luoqi@watermarkgroup.com> Cc: current@FreeBSD.ORG Subject: Re: init runs with console as control terminal? Message-ID: <199911190508.AAA43114@khavrinen.lcs.mit.edu> In-Reply-To: <199911190359.WAA06557@lor.watermarkgroup.com> References: <199911190359.WAA06557@lor.watermarkgroup.com>
next in thread | previous in thread | raw e-mail | index | archive | help
<<On Thu, 18 Nov 1999 22:59:28 -0500 (EST), Luoqi Chen <luoqi@watermarkgroup.com> 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 <sys/types.h>
#include <err.h>
#include <stdlib.h>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199911190508.AAA43114>
