site_archiver@lists.apple.com Delivered-To: Darwin-dev@lists.apple.com Organization: WiredRoads User-agent: Thunderbird 2.0.0.0 (Macintosh/20070326) Hello, Hi, After the fork I do: int logfd = open(logName, O_WRONLY|O_APPEND|O_CREAT, 0644); dup2(logfd, STDOUT_FILENO); I presume that the above code snippet is in the child process, e.g.: if ( 0 == fork() ) { ... } Given the EBADF errno, I'd guess that either logfd or STDOUT_FILENO does not contain or refer to an expected value for an fd. As well as following other advice given in other posts, you might check whether some bit of custom kit in your 'old as dirt' and 'works fine elsewhere' code is (re)defining STDOUT_FILENO, or even 'dup2' or 'fork' to something unexpected. Also, check that some bug or side-effect is not changing the value of logName or what it references after your 'fork', and thus causing open() to intermittently fail (even though you might have successfully tested it before). If your code snippet happens to be in the parent process space instead, then it is also possible that the child process of a vfork() could be mucking things up for you. This bit of advice is worth repeating from other posts: Build and run a small test case. Best Regards --Mark Rhoads _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Norm Green wrote: I'm having a problem on Darwin i386 using dup2() in a child process. This is after a fork() call but before execve() call. The open() call succeeds but the dup2() call always fails with errno=9, which suggests one of the args is not an open fd. I'm sure I'm not closing either in my code. This email sent to site_archiver@lists.apple.com