From c0a9bffd03e62822959ba8cb0e8b083f1ec4b871 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 1 Sep 2003 02:05:32 +0000 Subject: [PATCH] * cygheap.cc (cygheap_init): Allocate space for sigaction array in cygheap. * cygheap.h (cygheap_types): Add HEAP_SIGS. * exceptions.cc (signal_fixup_after_exec): Remove from this file. * pinfo.h (pinfo::getsig): Just return global_sigs array. (pinfo::sigs): Delete. * sigproc.cc (signal_fixup_after_exec): Move it here. (global_sigs): New global array, moved from pinfo structure. (sigalloc): New function. Allocate global sigaction array here. (proc_subproc): Remove copysigs call. It's automatic now. * include/sys/cygwin.h (PID_NOCLDSTOP): New value. * signal.cc (sigaction): Set myself->PID_NODCLDSTOP when appropriate. * sigproc.h (sigalloc): Declare. * fnmatch.c (fnmatch): Use C90 parameters. (rangematch): Ditto. * fhandler.cc (fhandler_base::raw_read): Use right coercion to avoid a compiler warning. --- winsup/cygwin/ChangeLog | 22 ++++++++++++++++++++++ winsup/cygwin/cygheap.cc | 3 +++ winsup/cygwin/cygheap.h | 2 ++ winsup/cygwin/exceptions.cc | 12 ------------ winsup/cygwin/fhandler.cc | 2 +- winsup/cygwin/include/sys/cygwin.h | 2 +- winsup/cygwin/libc/fnmatch.c | 12 +----------- winsup/cygwin/pinfo.h | 7 +++---- winsup/cygwin/signal.cc | 6 ++++++ winsup/cygwin/sigproc.cc | 29 ++++++++++++++++++++++++++--- winsup/cygwin/sigproc.h | 1 + 11 files changed, 66 insertions(+), 32 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 43a85d1ef..3a02b3b45 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,25 @@ +2003-08-31 Christopher Faylor + + * cygheap.cc (cygheap_init): Allocate space for sigaction array in + cygheap. + * cygheap.h (cygheap_types): Add HEAP_SIGS. + * exceptions.cc (signal_fixup_after_exec): Remove from this file. + * pinfo.h (pinfo::getsig): Just return global_sigs array. + (pinfo::sigs): Delete. + * sigproc.cc (signal_fixup_after_exec): Move it here. + (global_sigs): New global array, moved from pinfo structure. + (sigalloc): New function. Allocate global sigaction array here. + (proc_subproc): Remove copysigs call. It's automatic now. + * include/sys/cygwin.h (PID_NOCLDSTOP): New value. + * signal.cc (sigaction): Set myself->PID_NODCLDSTOP when appropriate. + * sigproc.h (sigalloc): Declare. + + * fnmatch.c (fnmatch): Use C90 parameters. + (rangematch): Ditto. + + * fhandler.cc (fhandler_base::raw_read): Use right coercion to avoid a + compiler warning. + 2003-08-31 Christopher Faylor * net.cc (dup_ent): Make debugging output consistent. diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index c79b0017c..07151e960 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -22,6 +22,7 @@ #include "heap.h" #include "sync.h" #include "shared_info.h" +#include "sigproc.h" init_cygheap NO_COPY *cygheap; void NO_COPY *cygheap_max; @@ -203,6 +204,8 @@ cygheap_init () } if (!cygheap->fdtab) cygheap->fdtab.init (); + if (!cygheap->sigs) + sigalloc (); } /* Copyright (C) 1997, 2000 DJ Delorie */ diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index 2211af2be..7a637fa04 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -17,6 +17,7 @@ enum cygheap_types HEAP_ARGV, HEAP_BUF, HEAP_MOUNT, + HEAP_SIGS, HEAP_1_START, HEAP_1_STR, HEAP_1_ARGV, @@ -255,6 +256,7 @@ struct init_cygheap #ifdef DEBUGGING cygheap_debug debug; #endif + struct sigaction *sigs; }; #define CYGHEAPSIZE (sizeof (init_cygheap) + (16000 * sizeof (fhandler_union)) + (5 * 65536)) diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 075b3cc92..c63ed2058 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -731,18 +731,6 @@ signal_fixup_after_fork () sigproc_init (); } -void __stdcall -signal_fixup_after_exec () -{ - /* Set up child's signal handlers */ - for (int i = 0; i < NSIG; i++) - { - myself->getsig (i).sa_mask = 0; - if (myself->getsig (i).sa_handler != SIG_IGN) - myself->getsig (i).sa_handler = SIG_DFL; - } -} - static int interrupt_on_return (sigthread *, int, void *, struct sigaction&) __attribute__((regparm(3))); static int interrupt_on_return (sigthread *th, int sig, void *handler, struct sigaction& siga) diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 05dfa79ec..453eda4ae 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -264,7 +264,7 @@ fhandler_base::raw_read (void *ptr, size_t& ulen) int prio = 0; /* ditto */ DWORD len = ulen; - (ssize_t) ulen = -1; + ulen = (size_t) -1; if (read_state) { h = GetCurrentThread (); diff --git a/winsup/cygwin/include/sys/cygwin.h b/winsup/cygwin/include/sys/cygwin.h index dccff2068..ed0aa8dca 100644 --- a/winsup/cygwin/include/sys/cygwin.h +++ b/winsup/cygwin/include/sys/cygwin.h @@ -92,7 +92,7 @@ enum PID_SPLIT_HEAP = 0x0100, /* Set if the heap has been split, */ /* which means we can't fork again. */ PID_MYSELF = 0x0200, /* Flag that pid is me. */ - PID_UNUSED1 = 0x0400, /* Set if process uses Winsock. */ + PID_NOCLDSTOP = 0x0400, /* Set if no SIGCHLD signal on stop. */ PID_INITIALIZING = 0x0800, /* Set until ready to receive signals. */ PID_USETTY = 0x1000, /* Setting this enables or disables cygwin's */ /* tty support. This is inherited by */ diff --git a/winsup/cygwin/libc/fnmatch.c b/winsup/cygwin/libc/fnmatch.c index 709bc78c8..b48d9e00a 100644 --- a/winsup/cygwin/libc/fnmatch.c +++ b/winsup/cygwin/libc/fnmatch.c @@ -66,9 +66,7 @@ static char rcsid[] = "$OpenBSD: fnmatch.c,v 1.7 2000/03/23 19:13:51 millert Exp static int rangematch __P((const char *, char, int, char **)); int -fnmatch(pattern, string, flags) - const char *pattern, *string; - int flags; +fnmatch(const char *pattern, const char *string, int flags) { const char *stringstart; char *newp; @@ -168,15 +166,7 @@ fnmatch(pattern, string, flags) } static int -#ifdef __STDC__ rangematch(const char *pattern, char test, int flags, char **newp) -#else -rangematch(pattern, test, flags, newp) - char *pattern; - char test; - int flags; - char **newp; -#endif { int negate, ok; char c, c2; diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h index 89b683f94..e437328b6 100644 --- a/winsup/cygwin/pinfo.h +++ b/winsup/cygwin/pinfo.h @@ -36,6 +36,8 @@ enum picom PICOM_CMDLINE = 1 }; +extern struct sigaction *global_sigs; + class _pinfo { public: @@ -110,11 +112,9 @@ public: inline struct sigaction& getsig (int sig) { - return thread2signal ? thread2signal->sigs[sig] : sigs[sig]; + return global_sigs[sig]; } - inline void copysigs (_pinfo *p) {memcpy (sigs, p->sigs, sizeof (sigs));} - inline sigset_t& getsigmask () { return thread2signal ? *thread2signal->sigmask : sig_mask; @@ -143,7 +143,6 @@ public: friend void __stdcall set_myself (pid_t, HANDLE); private: - struct sigaction sigs[NSIG]; sigset_t sig_mask; /* one set for everything to ignore. */ LONG _sigtodo[NSIG + __SIGOFFSET]; pthread *thread2signal; // NULL means thread any other means a pthread diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc index baad718b9..2b890dd62 100644 --- a/winsup/cygwin/signal.cc +++ b/winsup/cygwin/signal.cc @@ -338,6 +338,12 @@ sigaction (int sig, const struct sigaction *newact, struct sigaction *oldact) if (newact->sa_handler == SIG_DFL && sig == SIGCHLD) sig_clear (sig); set_sigcatchers (oa.sa_handler, newact->sa_handler); + if (sig == SIGCHLD) + { + myself->process_state &= ~PID_NOCLDSTOP; + if (newact->sa_flags & SA_NOCLDSTOP); + myself->process_state |= PID_NOCLDSTOP; + } } if (oldact) diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index af2054112..b14fbac1b 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -17,6 +17,7 @@ details. */ #include #include #include +#include #include "cygerrno.h" #include "sync.h" #include "sigproc.h" @@ -48,12 +49,35 @@ details. */ #define NZOMBIES 256 -LONG local_sigtodo[TOTSIGS]; -inline LONG* getlocal_sigtodo (int sig) +static LONG local_sigtodo[TOTSIGS]; +struct sigaction *global_sigs; + +inline LONG * +getlocal_sigtodo (int sig) { return local_sigtodo + __SIGOFFSET + sig; } +void __stdcall +sigalloc () +{ + cygheap->sigs = global_sigs = + (struct sigaction *) ccalloc (HEAP_SIGS, NSIG, sizeof (struct sigaction)); +} + +void __stdcall +signal_fixup_after_exec () +{ + global_sigs = cygheap->sigs; + /* Set up child's signal handlers */ + for (int i = 0; i < NSIG; i++) + { + myself->getsig (i).sa_mask = 0; + if (myself->getsig (i).sa_handler != SIG_IGN) + myself->getsig (i).sa_handler = SIG_DFL; + } +} + /* * Global variables */ @@ -300,7 +324,6 @@ proc_subproc (DWORD what, DWORD val) vchild->sid = myself->sid; vchild->ctty = myself->ctty; vchild->process_state |= PID_INITIALIZING | (myself->process_state & PID_USETTY); - vchild->copysigs (myself); sigproc_printf ("added pid %d to wait list, slot %d, winpid %p, handle %p", vchild->pid, nchildren, vchild->dwProcessId, diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h index 5cedaeae3..360ae8bcb 100644 --- a/winsup/cygwin/sigproc.h +++ b/winsup/cygwin/sigproc.h @@ -120,6 +120,7 @@ int __stdcall sig_send (_pinfo *, int, DWORD ebp = (DWORD) __builtin_frame_addre void __stdcall signal_fixup_after_fork (); void __stdcall signal_fixup_after_exec (); void __stdcall wait_for_sigthread (); +void __stdcall sigalloc (); extern char myself_nowait_dummy[]; extern char myself_nowait_nonmain_dummy[];