[comp.unix.wizards] deamon 'shell' wanted

brinkema@fjc.GOV (John R. Brinkema) (05/17/91)

I am writing a network daemon; it will be started up at 'rc' time.  After
startup, I want it to lose  all tty-group connections.  I also want it to
shutdown cleanly (say when shutdown is run).

Does anyone have an example or 'shell' for a deamon.  tnx.  jb.

subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (05/18/91)

In article <417@fjcp60.GOV> brinkema@fjc.GOV (John R. Brinkema) writes:
>I am writing a network daemon; it will be started up at 'rc' time.  After
>startup, I want it to lose  all tty-group connections.  I also want it to
>shutdown cleanly (say when shutdown is run).
>
>Does anyone have an example or 'shell' for a deamon.  tnx.  jb.

All you need to do to make sure that the daemon loses its tty associations
is this:

t = open("/dev/tty", O_RDONLY);
ioctl(t, TIOCNOTTY, NULL);
close(t); close(0); close(1); close(2);

This seems to work for my daemons. As for shutting down, if process exits
cleanly (i.e either voluntarily or via kill -9), then the operating system
will take care of closing all fds.



			-Kartik



		

--
internet% ypwhich

subbarao@phoenix.Princeton.EDU -| Internet
kartik@silvertone.Princeton.EDU (NeXT mail)  
SUBBARAO@PUCC.BITNET			          - Bitnet