Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!caen!uflorida!mlb.semi.harris.com!trantor.harris-atd.com!trantor!chuck From: chuck@trantor.harris-atd.com (Chuck Musciano) Newsgroups: comp.unix.questions Subject: Re: Reopening stdin Message-ID: <5208@trantor.harris-atd.com> Date: 8 Jan 91 13:13:26 GMT References: <5200@trantor.harris-atd.com> <8685@star.cs.vu.nl> Sender: news@trantor.harris-atd.com Reply-To: chuck@trantor.harris-atd.com (Chuck Musciano) Organization: Advanced Technology Dept, Harris Corp, Melbourne, FL Lines: 33 In article <8685@star.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes: > Does the following program fail too? > > main() > { > int fd, i; > > close(0); > fd = open("/etc/passwd", 0); > dup2(fd, 0); > i = system("cat"); > exit(i & 0377 ? i | 0200 : i >> 8); > } > > If so, it looks like a resurrection of the old dup2() bug: as stdin has > been closed, the open() will return file descriptor 0, so the next line > results in > dup2(0, 0) I checked dup2(), and it is returning 0, as you would expect. In the case of dup2(0, 0), I tried closing stdin, calling open(), and verified that I got 0 as the descriptor. I then skipped the dup2 call, called system(), and it still failed! -- Chuck Musciano ARPA : chuck@trantor.harris-atd.com Harris Corporation Usenet: ...!uunet!x102a!trantor!chuck PO Box 37, MS 3A/1912 AT&T : (407) 727-6131 Melbourne, FL 32902 FAX : (407) 729-2537 A good newspaper is never good enough, but a lousy newspaper is a joy forever. -- Garrison Keillor