On Thu, Feb 25, 2010 at 09:57:48AM -0600, Peter Steele wrote:
> >Very wild guess, check the process signal mask of the child for both methods 
> >of spawning.
> 
> I'm running ntpd through Python. How do I check the process signal mask? I 
> did some quick searches and it seems Python does not support sigprocmask(). 
> 
> In my searches I came across this link:
> 
> http://bugs.python.org/msg61870
> 
> I think you might be right that this is related to the signal mask. In my 
> scenario the select call is hanging indefinitely, just like discussed in this 
> article.
> 

Below is the quickly made patch to add ability to show signal disposition
to the procstat(1). I am not sure about duplicating information about
catch/ignore state of the signal for all threads (this information is
process-global), but I think this is more usable for scripts.

diff --git a/usr.bin/procstat/Makefile b/usr.bin/procstat/Makefile
index 1c187b0..251fc06 100644
--- a/usr.bin/procstat/Makefile
+++ b/usr.bin/procstat/Makefile
@@ -10,6 +10,7 @@ SRCS= procstat.c              \
        procstat_files.c        \
        procstat_kstack.c       \
        procstat_threads.c      \
+       procstat_threads_sigs.c \
        procstat_vm.c
 
 LDADD+=        -lutil
diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c
index bc02682..cbd4eca 100644
--- a/usr.bin/procstat/procstat.c
+++ b/usr.bin/procstat/procstat.c
@@ -38,7 +38,7 @@
 
 #include "procstat.h"
 
-static int aflag, bflag, cflag, fflag, kflag, sflag, tflag, vflag;
+static int aflag, bflag, cflag, fflag, iflag, kflag, sflag, tflag, vflag;
 int    hflag;
 
 static void
@@ -46,7 +46,7 @@ usage(void)
 {
 
        fprintf(stderr, "usage: procstat [-h] [-w interval] [-b | -c | -f | "
-           "-k | -s | -t | -v]\n");
+           "-i | -k | -s | -t | -v]\n");
        fprintf(stderr, "                [-a | pid ...]\n");
        exit(EX_USAGE);
 }
@@ -61,6 +61,8 @@ procstat(pid_t pid, struct kinfo_proc *kipp)
                procstat_args(pid, kipp);
        else if (fflag)
                procstat_files(pid, kipp);
+       else if (iflag)
+               procstat_threads_sigs(pid, kipp);
        else if (kflag)
                procstat_kstack(pid, kipp, kflag);
        else if (sflag)
@@ -109,7 +111,7 @@ main(int argc, char *argv[])
        char *dummy;
 
        interval = 0;
-       while ((ch = getopt(argc, argv, "abcfkhstvw:")) != -1) {
+       while ((ch = getopt(argc, argv, "abcfikhstvw:")) != -1) {
                switch (ch) {
                case 'a':
                        aflag++;
@@ -127,6 +129,10 @@ main(int argc, char *argv[])
                        fflag++;
                        break;
 
+               case 'i':
+                       iflag++;
+                       break;
+
                case 'k':
                        kflag++;
                        break;
diff --git a/usr.bin/procstat/procstat.h b/usr.bin/procstat/procstat.h
index 8bacab7..10f8fce 100644
--- a/usr.bin/procstat/procstat.h
+++ b/usr.bin/procstat/procstat.h
@@ -41,6 +41,7 @@ void  procstat_cred(pid_t pid, struct kinfo_proc *kipp);
 void   procstat_files(pid_t pid, struct kinfo_proc *kipp);
 void   procstat_kstack(pid_t pid, struct kinfo_proc *kipp, int kflag);
 void   procstat_threads(pid_t pid, struct kinfo_proc *kipp);
+void   procstat_threads_sigs(pid_t pid, struct kinfo_proc *kipp);
 void   procstat_vm(pid_t pid, struct kinfo_proc *kipp);
 
 #endif /* !PROCSTAT_H */
diff --git a/usr.bin/procstat/procstat_threads_sigs.c 
b/usr.bin/procstat/procstat_threads_sigs.c
new file mode 100644
index 0000000..814f0c4
--- /dev/null
+++ b/usr.bin/procstat/procstat_threads_sigs.c
@@ -0,0 +1,111 @@
+/*-
+ * Copyright (c) 2007 Robert N. M. Watson
+ * Copyright (c) 2010 Konstantin Belousov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+
+#include <err.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "procstat.h"
+
+static inline void
+procstat_print_sig(const sigset_t *set, int sig)
+{
+
+       printf("%4s ", sigismember(set, sig) ? "t" : "f");
+}
+
+void
+procstat_threads_sigs(pid_t pid, struct kinfo_proc *kipp)
+{
+       struct kinfo_proc *kip;
+       int error, name[4], j;
+       char rtname[8];
+       unsigned int i;
+       size_t len;
+
+       if (!hflag)
+               printf("%5s %6s %7s %4s %4s %4s %4s\n", "PID",
+                   "TID", "SIG", "PEND", "BLKC", "IGNR", "CTCH");
+
+       /*
+        * We need to re-query for thread information, so don't use *kipp.
+        */
+       name[0] = CTL_KERN;
+       name[1] = KERN_PROC;
+       name[2] = KERN_PROC_PID | KERN_PROC_INC_THREAD;
+       name[3] = pid;
+
+       len = 0;
+       error = sysctl(name, 4, NULL, &len, NULL, 0);
+       if (error < 0 && errno != ESRCH) {
+               warn("sysctl: kern.proc.pid: %d", pid);
+               return;
+       }
+       if (error < 0)
+               return;
+
+       kip = malloc(len);
+       if (kip == NULL)
+               err(-1, "malloc");
+
+       if (sysctl(name, 4, kip, &len, NULL, 0) < 0) {
+               warn("sysctl: kern.proc.pid: %d", pid);
+               free(kip);
+               return;
+       }
+
+       kinfo_proc_sort(kip, len / sizeof(*kipp));
+       for (i = 0; i < len / sizeof(*kipp); i++) {
+               kipp = &kip[i];
+               for (j = 1; j < _SIG_MAXSIG; j++) {
+                       printf("%5d ", pid);
+                       printf("%6d ", kipp->ki_tid);
+                       if (j < sys_nsig)
+                               printf("%7s ", sys_signame[j]);
+                       else if (j >= SIGRTMIN && j <= SIGRTMAX) {
+                               snprintf(rtname, sizeof(rtname), "rt%d", j);
+                               printf("%7s ", rtname);
+                       } else
+                               printf("%7d ", j);
+                       procstat_print_sig(&kipp->ki_siglist, j);
+                       procstat_print_sig(&kipp->ki_sigmask, j);
+                       procstat_print_sig(&kipp->ki_sigignore, j);
+                       procstat_print_sig(&kipp->ki_sigcatch, j);
+                       printf("\n");
+               }
+       }
+       free(kip);
+}

Attachment: pgpjoT4fAMEjA.pgp
Description: PGP signature

Reply via email to