X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: popen bug Date: Fri, 18 Aug 2006 17:55:59 +0000 (UTC) Lines: 64 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Cygwin popen does not match Linux popen when stdout is closed. In cygwin window 1: $ cat foo.c #include #include 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//fd /proc//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/