From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 25 16:45:23 2010 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 23239106564A for ; Thu, 25 Feb 2010 16:45:23 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 71A538FC13 for ; Thu, 25 Feb 2010 16:45:21 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o1PGjFvB033940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 25 Feb 2010 18:45:15 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id o1PGjEQq095606; Thu, 25 Feb 2010 18:45:14 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id o1PGjE9a095605; Thu, 25 Feb 2010 18:45:14 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 25 Feb 2010 18:45:14 +0200 From: Kostik Belousov To: Peter Steele Message-ID: <20100225164514.GB2489@deviant.kiev.zoral.com.ua> References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB385D60B7@MBX03.exg5.exghost.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> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="NDin8bjvE/0mNLFQ" Content-Disposition: inline In-Reply-To: <7B9397B189EB6E46A5EE7B4C8A4BB7CB39E95703@MBX03.exg5.exghost.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: Alexandr Rybalko , "hackers@freebsd.org" Subject: Re: ntpd hangs under FBSD 8 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2010 16:45:23 -0000 --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 +#include +#include + +#include +#include +#include +#include +#include +#include + +#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--