svn commit: r238060 - stable/9/usr.bin/killall

Konstantin Belousov kib at FreeBSD.org
Tue Jul 3 08:21:56 UTC 2012


Author: kib
Date: Tue Jul  3 08:21:56 2012
New Revision: 238060
URL: http://svn.freebsd.org/changeset/base/238060

Log:
  MFC r237844, r237845, r237846:
  Minor tweaks.

Modified:
  stable/9/usr.bin/killall/killall.c
Directory Properties:
  stable/9/usr.bin/killall/   (props changed)

Modified: stable/9/usr.bin/killall/killall.c
==============================================================================
--- stable/9/usr.bin/killall/killall.c	Tue Jul  3 08:03:07 2012	(r238059)
+++ stable/9/usr.bin/killall/killall.c	Tue Jul  3 08:21:56 2012	(r238060)
@@ -90,7 +90,7 @@ nosig(char *name)
 int
 main(int ac, char **av)
 {
-	struct kinfo_proc *procs = NULL, *newprocs;
+	struct kinfo_proc *procs, *newprocs;
 	struct stat	sb;
 	struct passwd	*pw;
 	regex_t		rgx;
@@ -273,9 +273,6 @@ main(int ac, char **av)
 	size = 0;
 	mib[0] = CTL_KERN;
 	mib[1] = KERN_PROC;
-	mib[2] = KERN_PROC_PROC;
-	mib[3] = 0;
-	miblen = 3;
 
 	if (user) {
 		mib[2] = eflag ? KERN_PROC_UID : KERN_PROC_RUID;
@@ -285,16 +282,20 @@ main(int ac, char **av)
 		mib[2] = KERN_PROC_TTY;
 		mib[3] = tdev;
 		miblen = 4;
+	} else {
+		mib[2] = KERN_PROC_PROC;
+		mib[3] = 0;
+		miblen = 3;
 	}
 
+	procs = NULL;
 	st = sysctl(mib, miblen, NULL, &size, NULL, 0);
 	do {
 		size += size / 10;
 		newprocs = realloc(procs, size);
-		if (newprocs == 0) {
-			if (procs)
-				free(procs);
-			errx(1, "could not reallocate memory");
+		if (newprocs == NULL) {
+			free(procs);
+			err(1, "could not reallocate memory");
 		}
 		procs = newprocs;
 		st = sysctl(mib, miblen, procs, &size, NULL, 0);
@@ -304,7 +305,7 @@ main(int ac, char **av)
 	if (size % sizeof(struct kinfo_proc) != 0) {
 		fprintf(stderr, "proc size mismatch (%zu total, %zu chunks)\n",
 			size, sizeof(struct kinfo_proc));
-		fprintf(stderr, "userland out of sync with kernel, recompile libkvm etc\n");
+		fprintf(stderr, "userland out of sync with kernel\n");
 		exit(1);
 	}
 	nprocs = size / sizeof(struct kinfo_proc);


More information about the svn-src-stable-9 mailing list