From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: open-pipe fd duplications Date: Tue, 29 Jul 2003 09:13:18 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87lluikzxt.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1059434650 14938 80.91.224.249 (28 Jul 2003 23:24:10 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 28 Jul 2003 23:24:10 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jul 29 01:24:09 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19hHKj-0003p5-00 for ; Tue, 29 Jul 2003 01:23:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19hHIa-0005Lt-27 for guile-devel@m.gmane.org; Mon, 28 Jul 2003 19:21:00 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19hHF6-0004WP-G2 for guile-devel@gnu.org; Mon, 28 Jul 2003 19:17:24 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19hHCU-0003pM-6f for guile-devel@gnu.org; Mon, 28 Jul 2003 19:14:43 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19hHBI-0003Sy-Fl for guile-devel@gnu.org; Mon, 28 Jul 2003 19:13:28 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) by snoopy.pacific.net.au (8.12.3/8.12.3/Debian-6.4) with ESMTP id h6SNDQiI001596 for ; Tue, 29 Jul 2003 09:13:26 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h6SNDQQg006072 for ; Tue, 29 Jul 2003 09:13:26 +1000 (EST) Original-Received: from localhost (ppp97.dyn228.pacific.net.au [203.143.228.97]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h6SNDOaB001412 for ; Tue, 29 Jul 2003 09:13:24 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19hHB8-0000dC-00; Tue, 29 Jul 2003 09:13:18 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2663 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2663 --=-=-= I think open-pipe leaves an extra copy of its input or output fd in the forked child. For instance, using showfds.c below and (use-modules (ice-9 popen)) (let ((p (open-input-pipe "./showfds"))) (sleep 1) (close-pipe p)) (let ((p (open-output-pipe "./showfds"))) (sleep 1) (close-pipe p)) I take it the intention is to leave the child clean except for the normal 0, 1 and 2. * popen.scm (open-process): Close input-fdes, output-fdes and error-fdes after duping them to 0, 1 and 2. I think this is worth putting in the 1.6 branch too. The only likely ill effect I could spot from the current code was that for an output pipe the extra copy of the read side means that if the spawned program closes stdin, a write from the parent (ie. guile) won't produce a SIGPIPE. For instance the following contrivance currently gets a SIGPIPE only when the sleep finishes and the shell exits, whereas with the change above it happens immediately. (use-modules (ice-9 popen)) (let ((p (open-output-pipe "exec 0>/dev/null; sleep 10"))) (while #t (display "x" p))) --=-=-= Content-Disposition: attachment; filename=popen.scm.close.diff --- popen.scm.~1.11.~ 2003-04-07 08:04:58.000000000 +1000 +++ popen.scm 2003-07-27 14:08:21.000000000 +1000 @@ -1,6 +1,6 @@ ;; popen emulation, for non-stdio based ports. -;;;; Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. +;;;; Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -90,14 +90,18 @@ (set! output-fdes (dup->fdes 0))) (if (= error-fdes 0) (set! error-fdes (dup->fdes 0))) - (dup2 input-fdes 0))) + (dup2 input-fdes 0) + (close-fdes input-fdes))) (cond ((not (= output-fdes 1)) (if (= error-fdes 1) (set! error-fdes (dup->fdes 1))) - (dup2 output-fdes 1))) + (dup2 output-fdes 1) + (close-fdes output-fdes))) - (dup2 error-fdes 2) + (cond ((not (= error-fdes 2)) + (dup2 error-fdes 2) + (close-fdes error-fdes))) (apply execlp prog prog args))) --=-=-= Content-Type: text/x-csrc Content-Disposition: attachment; filename=showfds.c #include #include #include int main (void) { int i, found = 0; struct stat st; fprintf (stderr, "file descriptors open:\n"); for (i = 0; i < 20; i++) { if (fstat (i, &st) != -1) { found = 1; fprintf (stderr, "%d: %X %s\n", i, st.st_mode, S_ISREG (st.st_mode) ? "reg" : S_ISCHR (st.st_mode) ? "chr" : S_ISFIFO (st.st_mode) ? "fifo" : "unknown"); } } if (! found) fprintf (stderr, " none\n"); return 0; } --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--