[comp.unix.xenix] How to make a daemon

bill@ssbn.WLK.COM (Bill Kennedy) (05/11/88)

I am in a bit of a quandry and it appears that the net is going to be
able to respond before SCO will, so here's my m'aidez -

I need to respawn a process like a getty so that's there's nearly always
a copy active.  In straight ahead System V (I have SCO Vr2.2.3 80386) I
just put an entry in /etc/inittab that says

30:23:respawn:/usr/lib/clubs/omron ttym07

And init will spawn one, catch the death of a child signal and spawn
another one, I do that all the time.  It appears that the SCO Xenix
/etc/inittab is just a pacifier for those of who live and die by telinit,
you can spawn anything you want as long as it's /etc/getty.

I have written a routine into the program named "phoenix()" which does a
while ( fork() ), but it has all of the nasty features of such stuff,
leaves zombies wandering around and copies with a priority so low that I
have to reboot (and fsck grrr!) to be rid of them when something burps.
Plain old System V will close the tty if I fail to do so (giving a DTR
cycle to the modem) and I get a bright shiny fresh copy of the process to
take over when the predecessor dies.  While phoenix() works, it's ugly.
Can anyone suggest something a little closer to what I thought I could do?

I joked to my SCO sales rep today that if it wasn't for this group, they'd
be three weeks behind instead of just three days.  Thanks,
-- 
Bill Kennedy  usenet      {rutgers,ihnp4!killer,cbosgd}!ssbn!bill
              internet    bill@ssbn.WLK.COM

stephm@sco.COM (Stephen P. Marr) (05/13/88)

In article <194@ssbn.WLK.COM> bill@ssbn.WLK.COM (Bill Kennedy) writes:
 =>I am in a bit of a quandry and it appears that the net is going to be
 =>able to respond before SCO will, so here's my m'aidez -

Surprise!  SCO Calling!

 =>I need to respawn a process like a getty so that's there's nearly always
 =>a copy active.  In straight ahead System V (I have SCO Vr2.2.3 80386) I
 =>just put an entry in /etc/inittab that says
 =>
 =>30:23:respawn:/usr/lib/clubs/omron ttym07
 =>
 =><...>
 =>
 =>I joked to my SCO sales rep today that if it wasn't for this group, they'd
 =>be three weeks behind instead of just three days.  Thanks,
 =>-- 
 =>Bill Kennedy  usenet      {rutgers,ihnp4!killer,cbosgd}!ssbn!bill
 =>              internet    bill@ssbn.WLK.COM

Here's a way to do it (albeit certainly not the only way):

set up an entry in /etc/gettydefs which utilizes the AUTO option e.g.

z # B9600 HUPCL # B9600 CS8 SANE TAB3 ECHOE IXANY # # p # AUTO prog_name

and then modify an entry in /etc/ttys to use this gettydef entry and enable
that port.  What will happen is this:  init will spawn a getty which will
see the AUTO keyword and fork (login by default) the specified program.
Note that argv[1] is going to be the basename of the controlling tty, and
that there is no utmp entry or any real environment to speak of.  Your
uid and gid are 0 at this point so standard setuid-root paranoia should
be applied.

More info could be gleaned from gettydefs(F) init(M) and getty(M).  SCO
support has further info if you need it.  Good luck.
-- 
Steph Marr,  The Santa Cruz Operation Inc.,  ...!{uunet,ihnp4,ucscc}!sco!stephm
Internet: (MX Handlers) stephm@sco.COM  (Others) @ucscc.ucsc.edu:stephm@sco.COM
"There was coffee.  Life would go on."     --William Gibson