[comp.unix.ultrix] Ultrix 4.1 setpgrp

D. Allen [CGL]" <idallen@watcgl.waterloo.edu> (03/05/91)

The man page for setpgrp() says I can do anything I want to my own
processes, and indeed under 4.3BSD I can.  But you can't do this on
Ultrix 4.1 (or Ultrix 3.x) any more:

    main()
    {
	    if( setpgrp(0,0) == -1 )
		    perror("setpgrp(0,0)");
	    if( setpgrp(getpid(),0) == -1 )
		    perror("setpgrp(getpid(),0)");
    }

You get this:

    setpgrp(0,0): Not owner
    setpgrp(getpid(),0): Not owner

This should be an SPR, but I don't have a typewriter handy.

ULTRIX V4.1 (Rev. 52) on a DS5400
-- 
-IAN! (Ian! D. Allen) idallen@watcgl.uwaterloo.ca idallen@watcgl.waterloo.edu
 [129.97.128.64]  Computer Graphics Lab/University of Waterloo/Ontario/Canada

D. Allen [CGL]) (03/05/91)

> Input:  if( setpgrp(0,0) == -1 ) perror("setpgrp(0,0)");
> Output: setpgrp(0,0): Not owner

This is worse than I thought.  Because of the above Ultrix bug, you
can't write a non-root process that can reliably adopt a new control
terminal from a tty.  On BSD systems, the above setpgrp(0,0) will
always disconnect your control tty as well as zero the process group,
so the next tty you open becomes your adopted control terminal.  You
can't use setpgrp(0,0) when you aren't root, because of the Ultrix bug,
so you have to use the TIOCNOTTY ioctl to disconnect the control tty
and zero the process group.  But if your program is started from a
daemon (e.g. via rsh) and 1) has no control tty, and 2) has a non-zero
process group, you can't use TIOCNOTTY (because you have no tty) and
you cannot make your program adopt a new control tty (because you can't
set your process group to zero because of the Ultrix bug).

Can you imagine trying to figure this stuff out without kernel sources?
You can see the problem in kern_prot.c; non-root users are just not
allowed to set a pgrp of zero using setpgrp.  You have to use TIOCNOTTY
to do it, and as the above illustrates that isn't always possible.

#include <standard wish for an electronic SPR address>
-- 
-IAN! (Ian! D. Allen) idallen@watcgl.uwaterloo.ca idallen@watcgl.waterloo.edu
 [129.97.128.64]  Computer Graphics Lab/University of Waterloo/Ontario/Canada