On Tue, Mar 23, 2010 at 05:22:21PM -0700, Edward Pilatowicz wrote: > On Wed, Mar 24, 2010 at 01:16:28AM +0100, ????? ???????????? wrote: > > Now when I created the master, how to I pass the slave to a shell? > > Just dup(fd_slave) for stdin, stdout, stderr and pass it to > > fork()/exec()? Or do I have to use open()? Or just open once and pass > > the same fd for stdin, stdout, stderr to the shell? > > you probably want to do the dup() after the fork and before the exec(). > having the same fd for stdin, stdou, and stderr sounds right.
The best way, IMO, would be to fork() or vfork(), dup2() the slave into 0, 1 and 2, then close all other fildes other than those you explicitly want the child to have (yeah, you might CLOEXEC them, but still), preferably using closefrom(), then exec(). Nico --
