(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.
+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
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;
#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 ()
{
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 ()
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 ();
}
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;
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);
# 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
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_*/
}
int
-fhandler_base::close (void)
+fhandler_base::close ()
{
int res = -1;
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;
}
h = newh;
ProtectHandle2 (h, name);
}
+ setclexec_pid (h, not_inheriting);
#endif
}
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);}
__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 ();
MALLOC_CHECK;
+ debug_fixup_after_fork ();
pinfo_fixup_after_fork ();
cygheap->fdtab.fixup_after_fork (hParent);
signal_fixup_after_fork ();
}
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 */
}
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];
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 */
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 ()
{