Date: Wed, 12 Dec 2012 15:45:04 +0000 (UTC) From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244154 - head/bin/ps Message-ID: <201212121545.qBCFj4Hl086444@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pjd Date: Wed Dec 12 15:45:03 2012 New Revision: 244154 URL: http://svnweb.freebsd.org/changeset/base/244154 Log: Use kern.max_pid sysctl to obtain maximum PID number instead of using local define. Reviewed by: jhb Modified: head/bin/ps/ps.c Modified: head/bin/ps/ps.c ============================================================================== --- head/bin/ps/ps.c Wed Dec 12 15:27:33 2012 (r244153) +++ head/bin/ps/ps.c Wed Dec 12 15:45:03 2012 (r244154) @@ -109,6 +109,7 @@ static int needcomm; /* -o "command" */ static int needenv; /* -e */ static int needuser; /* -o "user" */ static int optfatal; /* Fatal error parsing some list-option. */ +static int pid_max; /* kern.max_pid */ static enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT; @@ -148,6 +149,7 @@ static int pscomp(const void *, const v static void saveuser(KINFO *); static void scanvars(void); static void sizevars(void); +static void pidmax_init(void); static void usage(void); static char dfmt[] = "pid,tt,state,time,command"; @@ -200,6 +202,8 @@ main(int argc, char *argv[]) if (argc > 1) argv[1] = kludge_oldps_options(PS_ARGS, argv[1], argv[2]); + pidmax_init(); + all = descendancy = _fmt = nselectors = optfatal = 0; prtheader = showthreads = wflag = xkeep_implied = 0; xkeep = -1; /* Neither -x nor -X. */ @@ -722,7 +726,6 @@ addelem_gid(struct listinfo *inf, const return (1); } -#define BSD_PID_MAX 99999 /* Copy of PID_MAX from sys/proc.h. */ static int addelem_pid(struct listinfo *inf, const char *elem) { @@ -740,7 +743,7 @@ addelem_pid(struct listinfo *inf, const if (*endp != '\0' || tempid < 0 || elem == endp) { warnx("Invalid %s: %s", inf->lname, elem); errno = ERANGE; - } else if (errno != 0 || tempid > BSD_PID_MAX) { + } else if (errno != 0 || tempid > pid_max) { warnx("%s too large: %s", inf->lname, elem); errno = ERANGE; } @@ -753,7 +756,6 @@ addelem_pid(struct listinfo *inf, const inf->l.pids[(inf->count)++] = tempid; return (1); } -#undef BSD_PID_MAX /*- * The user can specify a device via one of three formats: @@ -1352,6 +1354,18 @@ kludge_oldps_options(const char *optlist } static void +pidmax_init(void) +{ + size_t intsize; + + intsize = sizeof(pid_max); + if (sysctlbyname("kern.pid_max", &pid_max, &intsize, NULL, 0) < 0) { + warn("unable to read kern.pid_max"); + pid_max = 99999; + } +} + +static void usage(void) { #define SINGLE_OPTS "[-aCcde" OPT_LAZY_f "HhjlmrSTuvwXxZ]"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212121545.qBCFj4Hl086444>