[att.unix] thanks for help with error message to tty after setpgrp

levy@ttrdc.UUCP (Daniel R. Levy) (05/19/88)

Thanks to all who posted or emailed suggestions for how I might get an
error message for a failed exec() back to the terminal that started the
command, if I had first closed all tty file descriptors and done a
setpgrp().

With the net's guruly help, I have found an answer.  I use pipe() to create a
(ya guessed it) pipe.  I then do a fork().  The child process closes the reading
end of the pipe, does a fcntl() on the writing end to make it close-on-exec,
then does setpgrp() and tries the exec.  The parent, meanwhile, has closed the
writing end of the pipe and is listening to the reading end.  If the child's
exec succeeds, the parent gets an EOF on the pipe (because the other end
was closed on the exec) and can go away happy.  If the child's exec fails,
it writes errno down the pipe, and the parent gets it and prints the
corresponding error message to /dev/tty.  And there is no need to worry about
the name of the controlling terminal.  Neat huh???

hack hack hack,
-- 
|------------Dan Levy------------|  Path: ihnp4,<most AT&T machines>!ttrdc!levy
|              AT&T              |  Weinberg's Principle:  An expert is a
|       Data Systems Group       |  person who avoids the small errors while
|--------Skokie, Illinois--------|  sweeping on to the grand fallacy.