At 2005-01-12T14:27:22+1300, Carl Cerecke wrote:
> closing is not the problem, only opening is.
Well, my not particularly imaginative example involves co-operating
processes wanting to do the following:
Process A:
close(STDERR_FILENO);
execl("/path/to/other/processb", "processb", (const char *)0);
Which then becomes Process B, and does:
open("/path/to/desired/stderr.log", O_WRONLY);
You can't achieve this with only the restricted open() and dup2().
Process A would is then forced to prepare the file descriptors before
exec()ing Process B.
> If you've closed, say, 2 and then want to reopen it, then you can:
> close(2);
> fd = open("foo","w");
^^^
Sinner! You've been using fopen() too much. ;-)
This doesn't make sense to me. Is this example assuming a system with
your restricted open()? If so, you have no way to reopen descriptor
2--remember that it's not valid to pass dup2() a invalid (e.g. closed)
descriptor. If not, open() is going to return 2 (assuming 0 and 1 are
still open) and the dup2() is not required.
> if (dup2(fd,2) == -1) {
[...]
> close(fid);
^^^
fd
Cheers,
-mjg
--
Matthew Gregan |/
/| [EMAIL PROTECTED]