Date: Thu, 25 Feb 2010 18:45:14 +0200 From: Kostik Belousov <kostikbel@gmail.com> To: Peter Steele <psteele@maxiscale.com> Cc: Alexandr Rybalko <ray@dlink.ua>, "hackers@freebsd.org" <hackers@freebsd.org> Subject: Re: ntpd hangs under FBSD 8 Message-ID: <20100225164514.GB2489@deviant.kiev.zoral.com.ua> In-Reply-To: <7B9397B189EB6E46A5EE7B4C8A4BB7CB39E95703@MBX03.exg5.exghost.com> References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB385D60B7@MBX03.exg5.exghost.com> <bc2d971002220751i256f2329g3f29efdc763bca97@mail.gmail.com> <7B9397B189EB6E46A5EE7B4C8A4BB7CB385D60DD@MBX03.exg5.exghost.com> <7B9397B189EB6E46A5EE7B4C8A4BB7CB39E95389@MBX03.exg5.exghost.com> <20100224190035.GA5026@wep4035.physik.uni-wuerzburg.de> <7B9397B189EB6E46A5EE7B4C8A4BB7CB39E95522@MBX03.exg5.exghost.com> <20100225125838.13cd6c0e.ray@dlink.ua> <7B9397B189EB6E46A5EE7B4C8A4BB7CB39E95689@MBX03.exg5.exghost.com> <20100225151828.GA2489@deviant.kiev.zoral.com.ua> <7B9397B189EB6E46A5EE7B4C8A4BB7CB39E95703@MBX03.exg5.exghost.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--NDin8bjvE/0mNLFQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 met= hods of spawning. >=20 > 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(= ).=20 >=20 > In my searches I came across this link: >=20 > http://bugs.python.org/msg61870 >=20 > 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 t= his article. >=20 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=3D procstat.c \ procstat_files.c \ procstat_kstack.c \ procstat_threads.c \ + procstat_threads_sigs.c \ procstat_vm.c =20 LDADD+=3D -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 @@ =20 #include "procstat.h" =20 -static int aflag, bflag, cflag, fflag, kflag, sflag, tflag, vflag; +static int aflag, bflag, cflag, fflag, iflag, kflag, sflag, tflag, vflag; int hflag; =20 static void @@ -46,7 +46,7 @@ usage(void) { =20 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; =20 interval =3D 0; - while ((ch =3D getopt(argc, argv, "abcfkhstvw:")) !=3D -1) { + while ((ch =3D getopt(argc, argv, "abcfikhstvw:")) !=3D -1) { switch (ch) { case 'a': aflag++; @@ -127,6 +129,10 @@ main(int argc, char *argv[]) fflag++; break; =20 + 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); =20 #endif /* !PROCSTAT_H */ diff --git a/usr.bin/procstat/procstat_threads_sigs.c b/usr.bin/procstat/pr= ocstat_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 PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * 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, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * 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] =3D CTL_KERN; + name[1] =3D KERN_PROC; + name[2] =3D KERN_PROC_PID | KERN_PROC_INC_THREAD; + name[3] =3D pid; + + len =3D 0; + error =3D sysctl(name, 4, NULL, &len, NULL, 0); + if (error < 0 && errno !=3D ESRCH) { + warn("sysctl: kern.proc.pid: %d", pid); + return; + } + if (error < 0) + return; + + kip =3D malloc(len); + if (kip =3D=3D 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 =3D 0; i < len / sizeof(*kipp); i++) { + kipp =3D &kip[i]; + for (j =3D 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 >=3D SIGRTMIN && j <=3D 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); +} --NDin8bjvE/0mNLFQ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAkuGqRoACgkQC3+MBN1Mb4hZ0gCgvRRR8hhBzZPcLRtkjkUJWAE9 u3gAoMtmruhpGnvvMOkInWB+oY7570BH =1nhM -----END PGP SIGNATURE----- --NDin8bjvE/0mNLFQ--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100225164514.GB2489>