* 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.
This commit is contained in:
parent
a26a4cdbe0
commit
e62ac9e869
@ -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>
|
Fri Aug 31 21:39:00 2001 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* security.cc (create_token): Change initialization of `exp' to comply
|
* security.cc (create_token): Change initialization of `exp' to comply
|
||||||
|
@ -179,13 +179,14 @@ typedef struct _h
|
|||||||
const char *name;
|
const char *name;
|
||||||
const char *func;
|
const char *func;
|
||||||
int ln;
|
int ln;
|
||||||
|
DWORD clexec_pid;
|
||||||
struct _h *next;
|
struct _h *next;
|
||||||
} handle_list;
|
} 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 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]))
|
#define NFREEH (sizeof (freeh) / sizeof (freeh[0]))
|
||||||
|
|
||||||
static muto NO_COPY *debug_lock = NULL;
|
static muto NO_COPY *debug_lock = NULL;
|
||||||
@ -196,6 +197,8 @@ static muto NO_COPY *debug_lock = NULL;
|
|||||||
#define unlock_debug() \
|
#define unlock_debug() \
|
||||||
do {if (debug_lock) debug_lock->release (); } while (0)
|
do {if (debug_lock) debug_lock->release (); } while (0)
|
||||||
|
|
||||||
|
static bool __stdcall mark_closed (const char *, int, HANDLE, const char *, BOOL);
|
||||||
|
|
||||||
void
|
void
|
||||||
debug_init ()
|
debug_init ()
|
||||||
{
|
{
|
||||||
@ -217,6 +220,14 @@ out:
|
|||||||
return hl;
|
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 */
|
/* Create a new handle record */
|
||||||
static handle_list * __stdcall
|
static handle_list * __stdcall
|
||||||
newh ()
|
newh ()
|
||||||
@ -275,8 +286,28 @@ out:
|
|||||||
unlock_debug ();
|
unlock_debug ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool __stdcall
|
static void __stdcall
|
||||||
debug_mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force)
|
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;
|
handle_list *hl;
|
||||||
lock_debug ();
|
lock_debug ();
|
||||||
@ -299,14 +330,7 @@ debug_mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL fo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hl)
|
if (hl)
|
||||||
{
|
delete_handle (hl);
|
||||||
handle_list *hnuke = hl->next;
|
|
||||||
hl->next = hl->next->next;
|
|
||||||
if (hnuke->allocated)
|
|
||||||
free (hnuke);
|
|
||||||
else
|
|
||||||
memset (hnuke, 0, sizeof (*hnuke));
|
|
||||||
}
|
|
||||||
|
|
||||||
unlock_debug ();
|
unlock_debug ();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -320,7 +344,7 @@ close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force)
|
|||||||
BOOL ret;
|
BOOL ret;
|
||||||
lock_debug ();
|
lock_debug ();
|
||||||
|
|
||||||
if (!debug_mark_closed (func, ln, h, name, force))
|
if (!mark_closed (func, ln, h, name, force))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
ret = CloseHandle (h);
|
ret = CloseHandle (h);
|
||||||
|
@ -43,8 +43,8 @@ int __stdcall iscygthread ();
|
|||||||
# define ProtectHandle1(h,n) do {} while (0)
|
# define ProtectHandle1(h,n) do {} while (0)
|
||||||
# define ProtectHandle2(h,n) do {} while (0)
|
# define ProtectHandle2(h,n) do {} while (0)
|
||||||
# define debug_init() do {} while (0)
|
# define debug_init() do {} while (0)
|
||||||
# define MarkCLosed(h) do {} while (0)
|
# define setclexec_pid(h, b) do {} while (0)
|
||||||
# define debug_mark_closed(func, ln, h, name, force) (1)
|
# define debug_fixup_after_fork() do {} while (0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -59,23 +59,22 @@ int __stdcall iscygthread ();
|
|||||||
close_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n, TRUE)
|
close_handle (__PRETTY_FUNCTION__, __LINE__, (h), #n, TRUE)
|
||||||
# define ForceCloseHandle2(h,n) \
|
# define ForceCloseHandle2(h,n) \
|
||||||
close_handle (__PRETTY_FUNCTION__, __LINE__, (h), n, TRUE)
|
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
|
# endif
|
||||||
|
|
||||||
# define ProtectHandle(h) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #h)
|
# define ProtectHandle(h) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), #h)
|
||||||
# define ProtectHandle1(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)
|
# define ProtectHandle2(h, n) add_handle (__PRETTY_FUNCTION__, __LINE__, (h), n)
|
||||||
|
|
||||||
void debug_init ();
|
void debug_init ();
|
||||||
void __stdcall add_handle (const char *, int, HANDLE, const char *);
|
void __stdcall add_handle (const char *, int, HANDLE, const char *)
|
||||||
BOOL __stdcall close_handle (const char *, int, HANDLE, const char *, BOOL);
|
__attribute__ ((regparm (3)));
|
||||||
int __stdcall lpfu (const char *, int, DWORD timeout);
|
BOOL __stdcall close_handle (const char *, int, HANDLE, const char *, BOOL)
|
||||||
void __stdcall cygbench (const char *s);
|
__attribute__ ((regparm (3)));
|
||||||
extern int pinger;
|
void __stdcall cygbench (const char *s) __attribute__ ((regparm (1)));
|
||||||
extern "C" void console_printf (const char *fmt,...);
|
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 /*DEBUGGING*/
|
||||||
#endif /*_DEBUG_H_*/
|
#endif /*_DEBUG_H_*/
|
||||||
|
@ -785,7 +785,7 @@ fhandler_base::lseek (off_t offset, int whence)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fhandler_base::close (void)
|
fhandler_base::close ()
|
||||||
{
|
{
|
||||||
int res = -1;
|
int res = -1;
|
||||||
|
|
||||||
@ -1317,8 +1317,8 @@ out:
|
|||||||
int
|
int
|
||||||
fhandler_disk_file::close ()
|
fhandler_disk_file::close ()
|
||||||
{
|
{
|
||||||
int res;
|
int res = this->fhandler_base::close ();
|
||||||
if ((res = this->fhandler_base::close ()) == 0)
|
if (!res)
|
||||||
cygwin_shared->delqueue.process_queue ();
|
cygwin_shared->delqueue.process_queue ();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -1545,6 +1545,7 @@ fhandler_base::set_inheritance (HANDLE &h, int not_inheriting, const char *namep
|
|||||||
h = newh;
|
h = newh;
|
||||||
ProtectHandle2 (h, name);
|
ProtectHandle2 (h, name);
|
||||||
}
|
}
|
||||||
|
setclexec_pid (h, not_inheriting);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,8 +400,8 @@ public:
|
|||||||
int get_socket () { return (int) get_handle(); }
|
int get_socket () { return (int) get_handle(); }
|
||||||
fhandler_socket * is_socket () { return this; }
|
fhandler_socket * is_socket () { return this; }
|
||||||
|
|
||||||
int saw_shutdown_read () const {return FHISSETF (SHUTRD);}
|
bool saw_shutdown_read () const {return FHISSETF (SHUTRD);}
|
||||||
int saw_shutdown_write () const {return FHISSETF (SHUTWR);}
|
bool saw_shutdown_write () const {return FHISSETF (SHUTWR);}
|
||||||
|
|
||||||
void set_shutdown_read () {FHSETF (SHUTRD);}
|
void set_shutdown_read () {FHSETF (SHUTRD);}
|
||||||
void set_shutdown_write () {FHSETF (SHUTWR);}
|
void set_shutdown_write () {FHSETF (SHUTWR);}
|
||||||
|
@ -479,13 +479,13 @@ fhandler_tty_slave::open (const char *, int flags, mode_t)
|
|||||||
__small_sprintf (buf, OUTPUT_DONE_EVENT, ttynum);
|
__small_sprintf (buf, OUTPUT_DONE_EVENT, ttynum);
|
||||||
output_done_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf);
|
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");
|
termios_printf ("open output mutex failed, %E");
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
return 0;
|
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");
|
termios_printf ("open input mutex failed, %E");
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
|
@ -276,6 +276,7 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
|
|||||||
|
|
||||||
MALLOC_CHECK;
|
MALLOC_CHECK;
|
||||||
|
|
||||||
|
debug_fixup_after_fork ();
|
||||||
pinfo_fixup_after_fork ();
|
pinfo_fixup_after_fork ();
|
||||||
cygheap->fdtab.fixup_after_fork (hParent);
|
cygheap->fdtab.fixup_after_fork (hParent);
|
||||||
signal_fixup_after_fork ();
|
signal_fixup_after_fork ();
|
||||||
|
@ -327,13 +327,13 @@ tty::init (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
HANDLE
|
HANDLE
|
||||||
tty::get_event (const char *fmt, BOOL inherit, BOOL manual_reset)
|
tty::get_event (const char *fmt, BOOL manual_reset)
|
||||||
{
|
{
|
||||||
HANDLE hev;
|
HANDLE hev;
|
||||||
char buf[40];
|
char buf[40];
|
||||||
|
|
||||||
__small_sprintf (buf, fmt, ntty);
|
__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);
|
termios_printf ("couldn't create %s", buf);
|
||||||
set_errno (ENOENT); /* FIXME this can't be the right errno */
|
set_errno (ENOENT); /* FIXME this can't be the right errno */
|
||||||
@ -406,15 +406,15 @@ tty::common_init (fhandler_pty_master *ptym)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!(ptym->output_done_event = get_event (OUTPUT_DONE_EVENT, FALSE)))
|
if (!(ptym->output_done_event = get_event (OUTPUT_DONE_EVENT)))
|
||||||
return FALSE;
|
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;
|
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;
|
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;
|
return FALSE;
|
||||||
|
|
||||||
char buf[40];
|
char buf[40];
|
||||||
|
@ -86,7 +86,8 @@ class fhandler_pty_master;
|
|||||||
|
|
||||||
class tty: public tty_min
|
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:
|
public:
|
||||||
HWND hwnd; /* Console window handle tty belongs to */
|
HWND hwnd; /* Console window handle tty belongs to */
|
||||||
|
|
||||||
@ -107,17 +108,17 @@ public:
|
|||||||
HWND gethwnd () {return hwnd;}
|
HWND gethwnd () {return hwnd;}
|
||||||
void sethwnd (HWND wnd) {hwnd = wnd;}
|
void sethwnd (HWND wnd) {hwnd = wnd;}
|
||||||
int make_pipes (fhandler_pty_master *ptym);
|
int make_pipes (fhandler_pty_master *ptym);
|
||||||
HANDLE open_output_mutex (BOOL inherit = FALSE)
|
HANDLE open_output_mutex ()
|
||||||
{
|
{
|
||||||
char buf[80];
|
char buf[80];
|
||||||
__small_sprintf (buf, OUTPUT_MUTEX, ntty);
|
__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];
|
char buf[80];
|
||||||
__small_sprintf (buf, INPUT_MUTEX, ntty);
|
__small_sprintf (buf, INPUT_MUTEX, ntty);
|
||||||
return OpenMutex (MUTEX_ALL_ACCESS, inherit, buf);
|
return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
|
||||||
}
|
}
|
||||||
BOOL exists ()
|
BOOL exists ()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user