From 421ba492fa95161ec0f42b51303411142e1a0360 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 18 Aug 2009 15:21:47 +0000 Subject: [PATCH] * dtable.cc (dtable::fixup_after_exec): Close any popen'ed file handles here. * fhandler.h (fhandler_*::ispipe): New function. (fhandler_base::get_popen_pid): Define virtual function. (fhandler_*::isdevice): Make const. (fhandler_*::isfifo): Ditto. --- winsup/cygwin/ChangeLog | 8 ++++++++ winsup/cygwin/dtable.cc | 2 ++ winsup/cygwin/fhandler.h | 12 ++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e29a935b5..1e21dd02f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2009-08-18 Christopher Faylor + + * dtable.cc (dtable::fixup_after_exec): Close any popen'ed file handles here. + * fhandler.h (fhandler_*::ispipe): New function. + (fhandler_base::get_popen_pid): Define virtual function. + (fhandler_*::isdevice): Make const. + (fhandler_*::isfifo): Ditto. + 2009-08-17 Christopher Faylor * syscalls.cc (popen): Reorganize slightly for clarity. Fix a comment. diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 3789ff50e..8783a6270 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -753,6 +753,8 @@ dtable::fixup_after_exec () } release (i); } + else if (fh->get_popen_pid ()) + close (i); else if (i == 0) SetStdHandle (std_consts[i], fh->get_io_handle ()); else if (i <= 2) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 7733d8f50..1544cc60c 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -342,8 +342,10 @@ class fhandler_base virtual int tcsetpgrp (const pid_t pid); virtual int tcgetpgrp (); virtual bool is_tty () const { return false; } - virtual bool isdevice () { return true; } - virtual bool isfifo () { return false; } + virtual bool ispipe () const { return false; } + virtual pid_t get_popen_pid () const {return 0;} + virtual bool isdevice () const { return true; } + virtual bool isfifo () const { return false; } virtual char *ptsname () { return NULL;} virtual class fhandler_socket *is_socket () { return NULL; } virtual class fhandler_console *is_console () { return 0; } @@ -559,6 +561,8 @@ public: OVERLAPPED *get_overlapped_buffer () {return &io_status;} void set_overlapped (OVERLAPPED *ov) {overlapped = ov;} + bool ispipe() const { return true; } + void set_popen_pid (pid_t pid) {popen_pid = pid;} pid_t get_popen_pid () const {return popen_pid;} _off64_t lseek (_off64_t offset, int whence); @@ -607,7 +611,7 @@ public: int open (int, mode_t); int close (); int dup (fhandler_base *child); - bool isfifo () { return true; } + bool isfifo () const { return true; } void set_close_on_exec (bool val); int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2))); OVERLAPPED *get_overlapped () {return &io_status;} @@ -723,7 +727,7 @@ class fhandler_disk_file: public fhandler_base int open (int flags, mode_t mode); int lock (int, struct __flock64 *); - bool isdevice () { return false; } + bool isdevice () const { return false; } int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2))); int __stdcall fchmod (mode_t mode) __attribute__ ((regparm (1))); int __stdcall fchown (__uid32_t uid, __gid32_t gid) __attribute__ ((regparm (2)));