diff options
author | Christopher Faylor <me@cgf.cx> | 2001-09-01 09:17:34 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2001-09-01 09:17:34 +0400 |
commit | e62ac9e86925090d0727605b33a1628d01b86158 (patch) | |
tree | e93ee4d420d352cc36cf1a9fbd530cf7f500f8d3 /winsup/cygwin/debug.cc | |
parent | a26a4cdbe0572f4c83d91b7193d5c53828757125 (diff) |
* 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.
Diffstat (limited to 'winsup/cygwin/debug.cc')
-rw-r--r-- | winsup/cygwin/debug.cc | 50 |
1 files changed, 37 insertions, 13 deletions
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); |