Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog25
-rw-r--r--winsup/cygwin/debug.cc50
-rw-r--r--winsup/cygwin/debug.h25
-rw-r--r--winsup/cygwin/fhandler.cc7
-rw-r--r--winsup/cygwin/fhandler.h4
-rw-r--r--winsup/cygwin/fhandler_tty.cc4
-rw-r--r--winsup/cygwin/fork.cc1
-rw-r--r--winsup/cygwin/tty.cc12
-rw-r--r--winsup/cygwin/tty.h11
9 files changed, 95 insertions, 44 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index e3b4b7c7c..aa491eabb 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,28 @@
+Sat Sep 1 01:10:07 2001 Christopher Faylor <cgf@cygnus.com>
+
+ * debug.cc (mark_closed): Rename from debug_mark_closed and make
+ static.
+ (setclexec_pid): New function for marking saved handle as
+ close-on-exec.
+ (delete_handle): New function.
+ (debug_fixup_after_fork): New function.
+ * debug.h: Declare new functions, remove obsolete ones.
+ * fork.cc (debug_fixup_after_fork): Call to cleanup close-on-exec
+ handles.
+
+ * fhandler.cc (fhandler_disk_file::close): Minor reorg.
+ (fhandler_base::set_inheritance): Set flag appropriately for debugging
+ when close-on-exec so forked process can delete closed handles.
+ * tty.h (open_output_mutex): Eliminate unneeded argument.
+ (open_input_mutex): Ditto.
+ * fhandler_tty.cc (fhandler_tty_slave::open): reflect open_*_mutex
+ argument changes.
+ * fhandler.h (fhandler_socket): Make saw_shutdown_* functions type
+ bool.
+ * tty.cc (tty::get_event): Eliminate unneeded argument.
+ (tty::common_init): Reflect change to get_event. Events should always
+ be inherited.
+
Fri Aug 31 21:39:00 2001 Corinna Vinschen <corinna@vinschen.de>
* security.cc (create_token): Change initialization of `exp' to comply
diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc
index 551a12d7d..c32ac6733 100644
--- a/winsup/cygwin/debug.cc
+++ b/winsup/cygwin/debug.cc
@@ -179,13 +179,14 @@ typedef struct _h
const char *name;
const char *func;
int ln;
+ DWORD clexec_pid;
struct _h *next;
} handle_list;
-static NO_COPY handle_list starth = {0, NULL, NULL, NULL, 0, NULL};
+static NO_COPY handle_list starth = {0, NULL, NULL, NULL, 0, 0, NULL};
static NO_COPY handle_list *endh = NULL;
-static handle_list NO_COPY freeh[1000] = {{0, NULL, NULL, NULL, 0, NULL}};
+static handle_list NO_COPY freeh[1000] = {{0, NULL, NULL, NULL, 0, 0, NULL}};
#define NFREEH (sizeof (freeh) / sizeof (freeh[0]))
static muto NO_COPY *debug_lock = NULL;
@@ -196,6 +197,8 @@ static muto NO_COPY *debug_lock = NULL;
#define unlock_debug() \
do {if (debug_lock) debug_lock->release (); } while (0)
+static bool __stdcall mark_closed (const char *, int, HANDLE, const char *, BOOL);
+
void
debug_init ()
{
@@ -217,6 +220,14 @@ out:
return hl;
}
+void
+setclexec_pid (HANDLE h, bool setit)
+{
+ handle_list *hl = find_handle (h);
+ if (hl)
+ hl->clexec_pid = setit ? GetCurrentProcessId () : 0;
+}
+
/* Create a new handle record */
static handle_list * __stdcall
newh ()
@@ -275,8 +286,28 @@ out:
unlock_debug ();
}
-bool __stdcall
-debug_mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force)
+static void __stdcall
+delete_handle (handle_list *hl)
+{
+ handle_list *hnuke = hl->next;
+ hl->next = hl->next->next;
+ if (hnuke->allocated)
+ free (hnuke);
+ else
+ memset (hnuke, 0, sizeof (*hnuke));
+}
+
+void
+debug_fixup_after_fork ()
+{
+ handle_list *hl;
+ for (hl = &starth; hl->next != NULL; hl = hl->next)
+ if (hl->next->clexec_pid)
+ delete_handle (hl);
+}
+
+static bool __stdcall
+mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force)
{
handle_list *hl;
lock_debug ();
@@ -299,14 +330,7 @@ debug_mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL fo
}
if (hl)
- {
- handle_list *hnuke = hl->next;
- hl->next = hl->next->next;
- if (hnuke->allocated)
- free (hnuke);
- else
- memset (hnuke, 0, sizeof (*hnuke));
- }
+ delete_handle (hl);
unlock_debug ();
return TRUE;
@@ -320,7 +344,7 @@ close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force)
BOOL ret;
lock_debug ();
- if (!debug_mark_closed (func, ln, h, name, force))
+ if (!mark_closed (func, ln, h, name, force))
return FALSE;
ret = CloseHandle (h);
diff --git a/winsup/cygwin/debug.h b/winsup/cygwin/debug.h
index 015627f3b..3c0d20b7b 100644
--- a/winsup/cygwin/debug.h
+++ b/winsup/cygwin/debug.h
@@ -43,8 +43,8 @@ int __stdcall iscygthread ();
# define ProtectHandle1(h,n) do {} while (0)
# define ProtectHandle2(h,n) do {} while (0)
# define debug_init() do {} while (0)
-# define MarkCLosed(h) do {} while (0)
-# define debug_mark_closed(func, ln, h, name, force) (1)
+# define setclexec_pid(h, b) do {} while (0)
+# define debug_fixup_after_fork() do {} while (0)
#else
@@ -59,23 +59,22 @@ int __stdcall iscygthread ();
close_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n, TRUE)
# define ForceCloseHandle2(h,n) \
close_handle (__PRETTY_FUNCTION__, __LINE__, (h), n, TRUE)
-# define MarkClosed(h) \
- debug_mark_closed (__PRETTY_FUNCTION__, __LINE__, (h), #h, TRUE)
-# define lock_pinfo_for_update(n) lpfu(__PRETTY_FUNCTION__, __LINE__, n)
# endif
# define ProtectHandle(h) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #h)
-# define ProtectHandle1(h,n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n)
-# define ProtectHandle2(h,n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), n)
+# define ProtectHandle1(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n)
+# define ProtectHandle2(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), n)
void debug_init ();
-void __stdcall add_handle (const char *, int, HANDLE, const char *);
-BOOL __stdcall close_handle (const char *, int, HANDLE, const char *, BOOL);
-int __stdcall lpfu (const char *, int, DWORD timeout);
-void __stdcall cygbench (const char *s);
-extern int pinger;
+void __stdcall add_handle (const char *, int, HANDLE, const char *)
+ __attribute__ ((regparm (3)));
+BOOL __stdcall close_handle (const char *, int, HANDLE, const char *, BOOL)
+ __attribute__ ((regparm (3)));
+void __stdcall cygbench (const char *s) __attribute__ ((regparm (1)));
extern "C" void console_printf (const char *fmt,...);
-bool debug_mark_closed (const char *, int, HANDLE, const char *, BOOL);
+void setclexec_pid (HANDLE, bool);
+void debug_fixup_after_fork ();
+extern int pinger;
#endif /*DEBUGGING*/
#endif /*_DEBUG_H_*/
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 86c6b4df6..4060a3819 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -785,7 +785,7 @@ fhandler_base::lseek (off_t offset, int whence)
}
int
-fhandler_base::close (void)
+fhandler_base::close ()
{
int res = -1;
@@ -1317,8 +1317,8 @@ out:
int
fhandler_disk_file::close ()
{
- int res;
- if ((res = this->fhandler_base::close ()) == 0)
+ int res = this->fhandler_base::close ();
+ if (!res)
cygwin_shared->delqueue.process_queue ();
return res;
}
@@ -1545,6 +1545,7 @@ fhandler_base::set_inheritance (HANDLE &h, int not_inheriting, const char *namep
h = newh;
ProtectHandle2 (h, name);
}
+ setclexec_pid (h, not_inheriting);
#endif
}
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index dae48258d..17f90cdad 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -400,8 +400,8 @@ public:
int get_socket () { return (int) get_handle(); }
fhandler_socket * is_socket () { return this; }
- int saw_shutdown_read () const {return FHISSETF (SHUTRD);}
- int saw_shutdown_write () const {return FHISSETF (SHUTWR);}
+ bool saw_shutdown_read () const {return FHISSETF (SHUTRD);}
+ bool saw_shutdown_write () const {return FHISSETF (SHUTWR);}
void set_shutdown_read () {FHSETF (SHUTRD);}
void set_shutdown_write () {FHSETF (SHUTWR);}
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 5d51ca00a..dc6c3d396 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -479,13 +479,13 @@ fhandler_tty_slave::open (const char *, int flags, mode_t)
__small_sprintf (buf, OUTPUT_DONE_EVENT, ttynum);
output_done_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf);
- if (!(output_mutex = get_ttyp ()->open_output_mutex (TRUE)))
+ if (!(output_mutex = get_ttyp ()->open_output_mutex ()))
{
termios_printf ("open output mutex failed, %E");
__seterrno ();
return 0;
}
- if (!(input_mutex = get_ttyp ()->open_input_mutex (TRUE)))
+ if (!(input_mutex = get_ttyp ()->open_input_mutex ()))
{
termios_printf ("open input mutex failed, %E");
__seterrno ();
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 238106cc6..834c356d7 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -276,6 +276,7 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
MALLOC_CHECK;
+ debug_fixup_after_fork ();
pinfo_fixup_after_fork ();
cygheap->fdtab.fixup_after_fork (hParent);
signal_fixup_after_fork ();
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 7b44b169c..ee31b193b 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -327,13 +327,13 @@ tty::init (void)
}
HANDLE
-tty::get_event (const char *fmt, BOOL inherit, BOOL manual_reset)
+tty::get_event (const char *fmt, BOOL manual_reset)
{
HANDLE hev;
char buf[40];
__small_sprintf (buf, fmt, ntty);
- if (!(hev = CreateEvent (inherit ? &sec_all : &sec_all_nih, manual_reset, FALSE, buf)))
+ if (!(hev = CreateEvent (&sec_all, manual_reset, FALSE, buf)))
{
termios_printf ("couldn't create %s", buf);
set_errno (ENOENT); /* FIXME this can't be the right errno */
@@ -406,15 +406,15 @@ tty::common_init (fhandler_pty_master *ptym)
}
else
{
- if (!(ptym->output_done_event = get_event (OUTPUT_DONE_EVENT, FALSE)))
+ if (!(ptym->output_done_event = get_event (OUTPUT_DONE_EVENT)))
return FALSE;
- if (!(ptym->ioctl_done_event = get_event (IOCTL_DONE_EVENT, FALSE)))
+ if (!(ptym->ioctl_done_event = get_event (IOCTL_DONE_EVENT)))
return FALSE;
- if (!(ptym->ioctl_request_event = get_event (IOCTL_REQUEST_EVENT, FALSE)))
+ if (!(ptym->ioctl_request_event = get_event (IOCTL_REQUEST_EVENT)))
return FALSE;
}
- if (!(ptym->input_available_event = get_event (INPUT_AVAILABLE_EVENT, FALSE, TRUE)))
+ if (!(ptym->input_available_event = get_event (INPUT_AVAILABLE_EVENT, TRUE)))
return FALSE;
char buf[40];
diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h
index 4b2ad7f4b..0730e51a9 100644
--- a/winsup/cygwin/tty.h
+++ b/winsup/cygwin/tty.h
@@ -86,7 +86,8 @@ class fhandler_pty_master;
class tty: public tty_min
{
- HANDLE get_event (const char *fmt, BOOL inherit, BOOL manual_reset = FALSE);
+ HANDLE get_event (const char *fmt, BOOL manual_reset = FALSE)
+ __attribute__ ((regparm (2)));
public:
HWND hwnd; /* Console window handle tty belongs to */
@@ -107,17 +108,17 @@ public:
HWND gethwnd () {return hwnd;}
void sethwnd (HWND wnd) {hwnd = wnd;}
int make_pipes (fhandler_pty_master *ptym);
- HANDLE open_output_mutex (BOOL inherit = FALSE)
+ HANDLE open_output_mutex ()
{
char buf[80];
__small_sprintf (buf, OUTPUT_MUTEX, ntty);
- return OpenMutex (MUTEX_ALL_ACCESS, inherit, buf);
+ return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
}
- HANDLE open_input_mutex (BOOL inherit = FALSE)
+ HANDLE open_input_mutex ()
{
char buf[80];
__small_sprintf (buf, INPUT_MUTEX, ntty);
- return OpenMutex (MUTEX_ALL_ACCESS, inherit, buf);
+ return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
}
BOOL exists ()
{