From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id B7E593858403; Tue, 1 Mar 2022 15:24:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7E593858403 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: /proc//status: Fill SigPnd, SigBlk and SigIgn values with life X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 195169186bfd58e45aaa31236575fb9d5957adad X-Git-Newrev: 9a3c058f661217b6757a464b1b1d8898f88c1567 Message-Id: <20220301152445.B7E593858403@sourceware.org> Date: Tue, 1 Mar 2022 15:24:45 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Mar 2022 15:24:45 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D9a3c058f661= 217b6757a464b1b1d8898f88c1567 commit 9a3c058f661217b6757a464b1b1d8898f88c1567 Author: Corinna Vinschen Date: Tue Mar 1 16:19:41 2022 +0100 Cygwin: /proc//status: Fill SigPnd, SigBlk and SigIgn values with = life =20 So far the values of SigPnd and SigBlk were always 0 and SigIgn was incorrectly set to the block mask of the current thread of the calling process. =20 Fix that by adding a _pinfo::siginfo method and a PICOM_SIGINFO message to allow to request actual signal info of any running process. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler_process.cc | 9 ++++++- winsup/cygwin/pinfo.cc | 51 +++++++++++++++++++++++++++++++++++= +--- winsup/cygwin/pinfo.h | 18 ++++++++++---- winsup/cygwin/sigproc.cc | 4 +-- 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_pro= cess.cc index 7f69027d0..4c42bc015 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -1199,6 +1199,8 @@ format_process_status (void *data, char *&destbuf) int state =3D 'R'; const char *state_str =3D "unknown"; size_t vmsize =3D 0, vmrss =3D 0, vmdata =3D 0, vmlib =3D 0, vmtext =3D = 0, vmshare =3D 0; + sigset_t pnd =3D 0, blk =3D 0, ign =3D 0; + bool fetch_siginfo =3D false; =20 PWCHAR last_slash =3D wcsrchr (p->progname, L'\\'); sys_wcstombs (cmd, NAME_MAX + 1, last_slash ? last_slash + 1 : p->progna= me); @@ -1221,13 +1223,16 @@ format_process_status (void *data, char *&destbuf) { case 'O': state_str =3D "running"; + fetch_siginfo =3D true; break; case 'D': case 'S': state_str =3D "sleeping"; + fetch_siginfo =3D true; break; case 'R': state_str =3D "runnable"; + fetch_siginfo =3D true; break; case 'Z': state_str =3D "zombie"; @@ -1238,6 +1243,8 @@ format_process_status (void *data, char *&destbuf) } get_mem_values (p->dwProcessId, vmsize, vmrss, vmtext, vmdata, vmlib, vmshare); + if (fetch_siginfo) + p->siginfo (pnd, blk, ign); /* The real uid value for *this* process is stored at cygheap->user.real= _uid but we can't get at the real uid value for any other process, so just fake it as p->uid. Similar for p->gid. */ @@ -1270,7 +1277,7 @@ format_process_status (void *data, char *&destbuf) vmsize * kb_per_page, 0UL, vmrss * kb_per_page, vmdata * kb_per_page, 0UL, vmtext * kb_per_page, vmlib * kb_per_page, - 0, 0, _my_tls.sigmask + pnd, blk, ign ); } =20 diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 5e04ea3da..ad65e59c1 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -668,6 +668,20 @@ commune_process (void *arg) sigproc_printf ("WritePipeOverlapped root failed, %E"); break; } + case PICOM_SIGINFO: + { + sigproc_printf ("processing PICOM_SIGINFO"); + commune_result cr; + sigpending (&cr.pnd); + cr.pnd =3D sig_send (myself, __SIGPENDINGALL, NULL); + cr.blk =3D cygheap->compute_sigblkmask (); + for (int sig =3D 1; sig < NSIG; ++sig) + if (global_sigs[sig].sa_handler =3D=3D SIG_IGN) + cr.ign |=3D SIGTOMASK (sig); + if (!WritePipeOverlapped (tothem, &cr, sizeof cr, &nr, 1000L)) + sigproc_printf ("WritePipeOverlapped siginfo failed, %E"); + break; + } case PICOM_FDS: { sigproc_printf ("processing PICOM_FDS"); @@ -788,16 +802,13 @@ commune_result _pinfo::commune_request (__uint32_t code, ...) { DWORD nr; - commune_result res; + commune_result res =3D { 0 }; va_list args; siginfo_t si =3D {0}; HANDLE& hp =3D si._si_commune._si_process_handle; HANDLE& fromthem =3D si._si_commune._si_read_handle; HANDLE request_sync =3D NULL; =20 - res.s =3D NULL; - res.n =3D 0; - if (!pid) { set_errno (ESRCH); @@ -877,6 +888,14 @@ _pinfo::commune_request (__uint32_t code, ...) res.n =3D p - res.s; } break; + case PICOM_SIGINFO: + if (!ReadPipeOverlapped (fromthem, &res, sizeof res, &nr, 1000L) + || nr !=3D sizeof res) + { + __seterrno (); + goto err; + } + break; } goto out; =20 @@ -996,6 +1015,30 @@ _pinfo::root (size_t& n) return s; } =20 +int +_pinfo::siginfo (sigset_t &pnd, sigset_t &blk, sigset_t &ign) +{ + if (!pid) + return -1; + if (pid !=3D myself->pid && !ISSTATE (this, PID_NOTCYGWIN)) + { + commune_result cr =3D commune_request (PICOM_SIGINFO); + pnd =3D cr.pnd; + blk =3D cr.blk; + ign =3D cr.ign; + } + else + { + pnd =3D sig_send (myself, __SIGPENDING, NULL); + blk =3D cygheap->compute_sigblkmask (); + ign =3D 0; + for (int sig =3D 1; sig < NSIG; ++sig) + if (global_sigs[sig].sa_handler =3D=3D SIG_IGN) + ign |=3D SIGTOMASK (sig); + } + return -1; +} + static HANDLE open_commune_proc_parms (DWORD pid, PRTL_USER_PROCESS_PARAMETERS prupp) { diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h index 69c1223f3..7e46cfbec 100644 --- a/winsup/cygwin/pinfo.h +++ b/winsup/cygwin/pinfo.h @@ -11,11 +11,17 @@ details. */ #include #include "thread.h" =20 -struct commune_result +union commune_result { - char *s; - DWORD n; - HANDLE handles[2]; + struct { + char *s; + size_t n; + }; + struct { + sigset_t pnd; + sigset_t blk; + sigset_t ign; + }; }; =20 enum picom @@ -28,7 +34,8 @@ enum picom PICOM_FD =3D 5, PICOM_PIPE_FHANDLER =3D 6, PICOM_FILE_PATHCONV =3D 7, - PICOM_ENVIRON =3D 8 + PICOM_ENVIRON =3D 8, + PICOM_SIGINFO =3D 9 }; =20 #define EXITCODE_SET 0x8000000 @@ -109,6 +116,7 @@ public: char *cmdline (size_t &); char *environ (size_t &); char *win_heap_info (size_t &); + int siginfo (sigset_t &, sigset_t &, sigset_t &); bool set_ctty (class fhandler_termios *, int); bool alert_parent (char); int __reg2 kill (siginfo_t&); diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 449777cda..d3f2b0c6a 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -683,7 +683,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) sigset_t pending; if (!its_me) pack.mask =3D NULL; - else if (si.si_signo =3D=3D __SIGPENDING) + else if (si.si_signo =3D=3D __SIGPENDING || si.si_signo =3D=3D __SIGPEND= INGALL) pack.mask =3D &pending; else if (si.si_signo =3D=3D __SIGFLUSH || si.si_signo > 0) { @@ -801,7 +801,7 @@ out: } if (pack.wakeup) ForceCloseHandle (pack.wakeup); - if (si.si_signo !=3D __SIGPENDING) + if (si.si_signo !=3D __SIGPENDING && si.si_signo !=3D __SIGPENDINGALL) /* nothing */; else if (!rc) rc =3D pending;