[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Why does login_tty(int fd) close fd at the end?



On Wed, Jun 6, 2012 at 1:01 AM, Regid Ichira <regid23@yahoo.com> wrote:
>  Isn't closing fd at the end makes all the work meaningless?
>
>    $ man login_tty| grep -A6 'The  login_tty() '
>           The  login_tty()  function  prepares for a login on the tty fd
>           (which may be a real tty device, or the slave of a  pseudoter-
>           minal  as  returned  by  openpty()) by creating a new session,
>           making fd the controlling terminal for  the  calling  process,
>           setting fd to be the standard input, output, and error streams
>           of the current process, and closing fd.
>

Note the "setting fd to be the standard input, output, and error
streams" text.  It will probably dup(2) the fd to be stdin, stdout,
and stderr.  After that closing the original fd has no effect on the
newly created descriptors.

-- 
regards,
kushal


Reply to: