Mail Archives: cygwin/2006/08/18/13:56:53
Cygwin popen does not match Linux popen when stdout is closed.
In cygwin window 1:
$ cat foo.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *f;
f = popen("sleep 30", "r");
if (!f)
return 1;
getc(f);
if (pclose(f))
return 2;
return 0;
}
$ ./foo >&-
In cygwin window 2, during the 30-second window:
$ pstree -p # determine pid of foo, sleep
...
$ ll /proc/<foo>/fd /proc/<sleep>/fd
/proc/5096/fd:
total 0
lrwxrwxrwx 1 eblake Domain Users 0 Aug 18 11:37 0 -> /dev/tty5
lrwxrwxrwx 1 eblake Domain Users 0 Aug 18 2006 2 -> /dev/tty5
/proc/9692/fd:
total 0
lrwxrwxrwx 1 eblake Domain Users 0 Aug 18 11:37 0 -> /dev/tty5
lrwxrwxrwx 1 eblake Domain Users 0 Aug 18 11:37 2 -> /dev/tty5
Repeat, but on Linux:
$ ll /proc/17837/fd /proc/17838/fd
/proc/17837/fd:
total 3
lrwx------ 1 ericb mauve 64 Aug 18 17:36 0 -> /dev/pts/0
lr-x------ 1 ericb mauve 64 Aug 18 17:36 1 -> pipe:[234602911]
lrwx------ 1 ericb mauve 64 Aug 18 17:36 2 -> /dev/pts/0
/proc/17838/fd:
total 3
lrwx------ 1 ericb mauve 64 Aug 18 17:36 0 -> /dev/pts/0
l-wx------ 1 ericb mauve 64 Aug 18 17:36 1 -> pipe:[234602911]
lrwx------ 1 ericb mauve 64 Aug 18 17:36 2 -> /dev/pts/0
Oops - when stdout is closed, and the pipe is output on child, cygwin popen
mistakenly lost the pipe in both processes.
The real world case that found this:
cygwin$ echo 'errprint(esyscmd(echo hi))dnl' | m4 >&-
sh: line 0: echo: write error: Bad file descriptor
linux$ echo 'errprint(esyscmd(echo hi))dnl' | m4 >&-
hi
--
Eric Blake
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -