This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

popen bug


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]