Date: Mon, 20 Mar 2000 13:24:57 -0500 From: Dan Papasian <bugg@bugg.strangled.net> To: Peter Wemm <peter@netplex.com.au> Cc: freebsd-bugs@FreeBSD.ORG Subject: Re: bin/17498: killall(1) is a slow perl script that's dependant on procfs Message-ID: <20000320132457.A689@moe.c705742-a.htfdw1.ct.home.com> In-Reply-To: <200003200440.UAA05593@freefall.freebsd.org>; from peter@netplex.com.au on Sun, Mar 19, 2000 at 08:40:02PM -0800 References: <200003200440.UAA05593@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Using getopt() would involve either introducing a worse hack to handle arguments such as -HUP or you'd have to force the user to use a format similar to -SIGHUP. Handling of -HUP, -KILL, etc. isn't done in a suitable manner by getopt. With regards to the error checking: Do you think that the sysctl needs to be checked? In the event that it fails, there's something _very_ wrong going on here, I suppose. Regardless, here is a diff that fixes the issue (and a problem with the shar): --- killall.c.orig Mon Mar 20 13:14:10 2000 +++ killall.c Mon Mar 20 13:21:54 2000 @@ -31,7 +31,7 @@ #include <ctype.h> #include <err.h> #include <fcntl.h> -x#include <signal.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -133,9 +133,18 @@ found = FALSE; - sysctl(mib, 3, NULL, &kplen, NULL, 0); - procall = kp = malloc(kplen); - sysctl(mib, 3, kp, &kplen, NULL, 0); + if(sysctl(mib, 3, NULL, &kplen, NULL, 0) == -1) { + perror("sysctl"); + errx(1,"First sysctl failed"); + } + + if((procall = kp = malloc(kplen)) == NULL) + errx(1,"Cannot allocate memory"); + + if(sysctl(mib, 3, kp, &kplen, NULL, 0) == -1) { + perror("sysctl"); + errx(1,"Second sysctl failed"); + } nentries = kplen / sizeof(*kp); (end) Good luck, -Dan On Sun, Mar 19, 2000 at 08:40:02PM -0800, Peter Wemm wrote: > The following reply was made to PR bin/17498; it has been noted by GNATS. > > From: Peter Wemm <peter@netplex.com.au> > To: bugg@bugg.strangled.net > Cc: FreeBSD-gnats-submit@FreeBSD.ORG > Subject: Re: bin/17498: killall(1) is a slow perl script that's dependant on procfs > Date: Mon, 20 Mar 2000 04:38:26 -0800 > > Dan Papasian wrote: > [..] > > X ++argv; > > X while (--argc > 0 && **argv == '-') { > > X > > X /* Remove dashes */ > > X while (**argv == '-') > > X ++* argv; > > X > > X /* If the argument ends here, it isn't the signal */ > > X /* If it is a digit, it is the signal. Don't pass to switch */ > > X if (argv[0][1] == '\0' && !isdigit(**argv)) { > > X switch (**argv) { > > X case 'd': > > X case 'v': > > This doesn't use getopt(), it probably should. > > > X sysctl(mib, 3, NULL, &kplen, NULL, 0); > > X procall = kp = malloc(kplen); > > X sysctl(mib, 3, kp, &kplen, NULL, 0); > > There is no error checking here.. > > Cheers, > -Peter > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-bugs" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000320132457.A689>