[net.unix-wizards] rlogind / BRL Sys V problem

aegl@root44.UUCP (Tony Luck) (04/23/86)

We run Berkeley 4.2 (with most of the Usenet/MtXinu bug fixes) together
with Doug Gwyn's system V emulation package on a VAX 11/750.
A problem arises with programs that fork children and then wait for them
(e.g. make, cc, ...) which are compiled with Doug's package and then run
from an rlogin connection on a pseudo-terminal.

/etc/rlogind ignores SIGCHLD before invoking /bin/login - thus all child
processes inherit this. The wait(2) library code in Doug's package checks
to see if you are ignoring SIGCHLD, if you are it waits for all children
and returns -1 with errno=ECHILD.

1) Why does /etc/rlogind leave SIGCHLD in SIG_IGN state when execl'ing
   /bin/login - this appears to be a simple oversight - but too many users
   here will want to break my arms if I just change it and then discover a
   good reason for this behaivour later!

2) Why does the "wait()" code check for SIGCHLD and then wait for all children
to die - this might be to try to emulate the "if a process ignores SIGCLD
then it's children won't turn into zombies when they die" mode of system V
(I thought you needed garlic+holy water for that!)

Any helpful hints will be gratefully received by mail to:
	...!mcvax!ukc!root44!aegl
I'll summarize anything remotely interesting back to the net.

P.S. If you have to port code written for Sys V to a 4.2 system then
Doug Gwyn's package is *excellent*. Apart from a few oddities with ioctls
that can't be mapped right and the above problem I've had no problems
worth mentioning with it.

gwyn@brl-smoke.ARPA (Doug Gwyn ) (04/28/86)

In article <5530@root44.UUCP> aegl@root44.UUCP (Tony Luck) writes:
>/etc/rlogind ignores SIGCHLD before invoking /bin/login - thus all child
>processes inherit this. The wait(2) library code in Doug's package checks
>to see if you are ignoring SIGCHLD, if you are it waits for all children
>and returns -1 with errno=ECHILD.
>
>1) Why does /etc/rlogind leave SIGCHLD in SIG_IGN state when execl'ing
>   /bin/login - this appears to be a simple oversight - but too many users
>   here will want to break my arms if I just change it and then discover a
>   good reason for this behaivour later!

It's a bug.  SIGCHLD should be set to SIG_DFL to ignore it, not to
SIG_IGN.  (Yes, I am serious!)  I think we found all these and
stamped them out in the BRL edition of 4.2BSD.

>2) Why does the "wait()" code check for SIGCHLD and then wait for all children
>to die - this might be to try to emulate the "if a process ignores SIGCLD
>then it's children won't turn into zombies when they die" mode of system V
>(I thought you needed garlic+holy water for that!)

The emulation does this because the System V documentation says so.
I personally think it's a crock and wouldn't object if you modify
your copy of the emulation to disable this feature.  I see that the
feature is not mentioned in the latest SVID, so portable code should
not depend on it anyway.  If you don't have source, here's the module
in question (compile it under the System V environment):

/*
	wait -- system call emulation for 4.2BSD or BRL PDP-11 UNIX

	last edit:	18-Sep-1983	D A Gwyn
*/

#include	<errno.h>
#include	<signal.h>

extern int	_wait();

int
wait( stat_loc )
	int	*stat_loc;		/* where to put status */
	{
	register void	(*sig)();	/* entry SIGCLD state */

	if ( (sig = signal( SIGCLD, SIG_IGN )) == SIG_IGN )
		{
		while ( _wait( stat_loc ) != -1 || errno != ECHILD )
			;		/* wait for all children */
		return -1;		/* ECHILD */
		}
	else	{
		(void)signal( SIGCLD, sig );	/* restore entry state */
		return _wait( stat_loc );
		}
	}

>... Apart from a few oddities with ioctls that can't be mapped right ...

I'm considering adjusting the terminal ioctl emulation to use CBREAK
under suitable circumstances.  Another possibility is to try to do
something more intelligent with the MIN, TIME fields.  There are
certain mode combinations that can't be emulated correctly, since
the Berkeley terminal driver doesn't have adequate orthogonality.
Of course, the best solution would be to have the kernel provide an
entire AT&T-style terminal handler as a separate line discipline.