<<On Thu, 18 Nov 1999 22:59:28 -0500 (EST), Luoqi Chen <[EMAIL PROTECTED]> 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
[EMAIL PROTECTED]  | 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 [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to