Page MenuHomeFreeBSD

D43077.id131544.diff
No OneTemporary

D43077.id131544.diff

diff --git a/bin/pkill/pkill.c b/bin/pkill/pkill.c
--- a/bin/pkill/pkill.c
+++ b/bin/pkill/pkill.c
@@ -67,7 +67,6 @@
#define STATUS_ERROR 3
#define MIN_PID 5
-#define MAX_PID 99999
/* Ignore system-processes (if '-S' flag is not specified) and myself. */
#define PSKIP(kp) ((kp)->ki_pid == mypid || \
@@ -868,7 +867,7 @@
rval = strtol(line, &endp, 10);
if (*endp != '\0' && !isspace((unsigned char)*endp))
errx(STATUS_ERROR, "Invalid pid in file `%s'", pidfile);
- else if (rval < MIN_PID || rval > MAX_PID)
+ else if (rval < MIN_PID)
errx(STATUS_ERROR, "Invalid pid in file `%s'", pidfile);
return (rval);
}
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -1468,8 +1468,7 @@
intsize = sizeof(pid_max);
if (sysctlbyname("kern.pid_max", &pid_max, &intsize, NULL, 0) < 0) {
- xo_warn("unable to read kern.pid_max");
- pid_max = 99999;
+ xo_err(1, "unable to read kern.pid_max");
}
}
diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c
--- a/lib/libc/gen/sched_getaffinity.c
+++ b/lib/libc/gen/sched_getaffinity.c
@@ -28,6 +28,7 @@
#define _WANT_P_OSREL
#include <sys/param.h>
+#include <sys/sysctl.h>
#include <errno.h>
#include <sched.h>
#include <string.h>
@@ -37,11 +38,20 @@
int
sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset)
{
+ static int pidmax;
cpuwhich_t which;
+ size_t sz;
int error;
if (__getosreldate() < P_OSREL_TIDPID) {
- if (pid == 0 || pid > _PID_MAX)
+ if (pidmax == 0) {
+ sz = sizeof(pidmax);
+ error = sysctlbyname("kern.pid_max", &pidmax, &sz,
+ NULL, 0);
+ if (error == -1)
+ return (error);
+ }
+ if (pid == 0 || pid > pidmax)
which = CPU_WHICH_TID;
else
which = CPU_WHICH_PID;
diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c
--- a/lib/libc/gen/sched_setaffinity.c
+++ b/lib/libc/gen/sched_setaffinity.c
@@ -38,14 +38,21 @@
int
sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset)
{
- static int mp_maxid;
+ static int mp_maxid, pidmax;
cpuwhich_t which;
cpuset_t c;
int error, lbs, cpu;
- size_t len, sz;
+ size_t sz;
if (__getosreldate() < P_OSREL_TIDPID) {
- if (pid == 0 || pid > _PID_MAX)
+ if (pidmax == 0) {
+ sz = sizeof(pidmax);
+ error = sysctlbyname("kern.pid_max", &pidmax, &sz,
+ NULL, 0);
+ if (error == -1)
+ return (error);
+ }
+ if (pid == 0 || pid > pidmax)
which = CPU_WHICH_TID;
else
which = CPU_WHICH_PID;
@@ -58,8 +65,8 @@
/* Linux ignores high bits */
if (mp_maxid == 0) {
- len = sizeof(mp_maxid);
- error = sysctlbyname("kern.smp.maxid", &mp_maxid, &len,
+ sz = sizeof(mp_maxid);
+ error = sysctlbyname("kern.smp.maxid", &mp_maxid, &sz,
NULL, 0);
if (error == -1)
return (error);
diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -39,12 +39,6 @@
extern char **environ;
-/*
- * The kernel doesn't expose PID_MAX to the user space. Save it here
- * to allow to run a newer world on a pre-1400079 kernel.
- */
-#define _PID_MAX 99999
-
/*
* This global flag is non-zero when a process has created one
* or more threads. It is used to avoid calling locking functions
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -955,7 +955,7 @@
* in a pid_t, as it is used to represent "no process group".
*/
#define PID_MAX 99999
-#define NO_PID 100000
+#define NO_PID (PID_MAX + 1)
#define THREAD0_TID NO_PID
extern pid_t pid_max;
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -245,7 +245,7 @@
/* mpid == -1 implies this system doesn't have an _mpid */
if (mpid != -1)
{
- printf("last pid: %5d; ", mpid);
+ printf("last pid: %*d; ", maxpidlen, mpid);
}
printf("load averages");
@@ -270,7 +270,7 @@
if (mpid != lmpid)
{
Move_to(x_lastpid, y_lastpid);
- printf("%5d", mpid);
+ printf("%*d", maxpidlen, mpid);
lmpid = mpid;
}
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -88,6 +88,8 @@
void get_system_info(struct system_info *si);
int machine_init(struct statics *statics);
+extern int maxpidlen;
+
/* non-int routines typically used by the machine dependent module */
extern struct process_select ps;
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -182,6 +182,9 @@
static int carc_enabled;
static int pageshift; /* log base 2 of the pagesize */
+static int maxcpulen;
+int maxpidlen;
+
/* define pagetok in terms of pageshift */
#define pagetok(size) ((size) << pageshift)
@@ -273,6 +276,22 @@
}
}
+static int
+numlen(const char *name)
+{
+ int len, val;
+
+ GETSYSCTL(name, val);
+
+ len = 0;
+ do {
+ val /= 10;
+ len++;
+ } while (val > 0);
+
+ return (len);
+}
+
int
machine_init(struct statics *statics)
{
@@ -307,6 +326,12 @@
GETSYSCTL("kern.ccpu", ccpu);
+ if (smpmode)
+ maxcpulen = numlen("hw.ncpu");
+ else
+ maxcpulen = 1;
+ maxpidlen = numlen("kern.pid_max");
+
/* this is used in calculating WCPU -- calculate it ahead of time */
logcpu = log(loaddouble(ccpu));
@@ -398,9 +423,11 @@
switch (displaymode) {
case DISP_CPU: {
- sbuf_printf(header, " %s", ps.thread_id ? " THR" : "PID");
+ sbuf_printf(header, "%*s",
+ ps.thread_id ? maxpidlen + 1 : maxpidlen,
+ ps.thread_id ? "THR" : "PID");
sbuf_printf(header, "%*s", ps.jail ? TOP_JID_LEN : 0,
- ps.jail ? " JID" : "");
+ ps.jail ? "JID" : "");
sbuf_printf(header, " %-*.*s ", namelength, namelength, uname_field);
if (!ps.thread) {
sbuf_cat(header, "THR ");
@@ -409,9 +436,9 @@
if (ps.swap) {
sbuf_printf(header, "%*s ", TOP_SWAP_LEN - 1, "SWAP");
}
- sbuf_cat(header, "STATE ");
+ sbuf_cat(header, "STATE ");
if (smpmode) {
- sbuf_cat(header, "C ");
+ sbuf_printf(header, "%*s ", maxcpulen, "C");
}
sbuf_cat(header, "TIME ");
sbuf_printf(header, " %6s ", ps.wcpu ? "WCPU" : "CPU");
@@ -420,9 +447,10 @@
break;
}
case DISP_IO: {
- sbuf_printf(header, " %s%*s %-*.*s",
- ps.thread_id ? " THR" : "PID",
- ps.jail ? TOP_JID_LEN : 0, ps.jail ? " JID" : "",
+ sbuf_printf(header, "%*s%*s %-*.*s",
+ ps.thread_id ? maxpidlen + 1 : maxpidlen,
+ ps.thread_id ? "THR" : "PID",
+ ps.jail ? TOP_JID_LEN : 0, ps.jail ? "JID" : "",
namelength, namelength, uname_field);
sbuf_cat(header, " VCSW IVCSW READ WRITE FAULT TOTAL PERCENT COMMAND");
sbuf_finish(header);
@@ -1080,6 +1108,13 @@
}
}
+ sbuf_printf(procbuf, "%*d ", (ps.thread_id) ? maxpidlen + 1 : maxpidlen,
+ (ps.thread_id) ? pp->ki_tid : pp->ki_pid);
+ if (ps.jail) {
+ sbuf_printf(procbuf, "%*d ", TOP_JID_LEN - 1, pp->ki_jid);
+ }
+ sbuf_printf(procbuf, "%-*.*s", namelength, namelength, (*get_userid)(pp->ki_ruid));
+
if (displaymode == DISP_IO) {
oldp = get_old_proc(pp);
if (oldp != NULL) {
@@ -1097,12 +1132,6 @@
p_tot = rup->ru_inblock + rup->ru_oublock + rup->ru_majflt;
s_tot = total_inblock + total_oublock + total_majflt;
- sbuf_printf(procbuf, "%5d ", (ps.thread_id) ? pp->ki_tid : pp->ki_pid);
-
- if (ps.jail) {
- sbuf_printf(procbuf, "%*d ", TOP_JID_LEN - 1, pp->ki_jid);
- }
- sbuf_printf(procbuf, "%-*.*s", namelength, namelength, (*get_userid)(pp->ki_ruid));
sbuf_printf(procbuf, "%6ld ", rup->ru_nvcsw);
sbuf_printf(procbuf, "%6ld ", rup->ru_nivcsw);
sbuf_printf(procbuf, "%6ld ", rup->ru_inblock);
@@ -1112,16 +1141,10 @@
sbuf_printf(procbuf, "%6.2f%% ", s_tot == 0 ? 0.0 : (p_tot * 100.0 / s_tot));
} else {
- sbuf_printf(procbuf, "%5d ", (ps.thread_id) ? pp->ki_tid : pp->ki_pid);
- if (ps.jail) {
- sbuf_printf(procbuf, "%*d ", TOP_JID_LEN - 1, pp->ki_jid);
- }
- sbuf_printf(procbuf, "%-*.*s ", namelength, namelength, (*get_userid)(pp->ki_ruid));
-
if (!ps.thread) {
- sbuf_printf(procbuf, "%4d ", pp->ki_numthreads);
+ sbuf_printf(procbuf, " %4d ", pp->ki_numthreads);
} else {
- sbuf_printf(procbuf, " ");
+ sbuf_printf(procbuf, " ");
}
sbuf_printf(procbuf, "%3d ", pp->ki_pri.pri_level - PZERO);
@@ -1141,7 +1164,7 @@
} else {
cpu = pp->ki_lastcpu;
}
- sbuf_printf(procbuf, "%3d ", cpu);
+ sbuf_printf(procbuf, "%*d ", maxcpulen, cpu);
}
sbuf_printf(procbuf, "%6s ", format_time(cputime));
sbuf_printf(procbuf, "%6.2f%% ", ps.wcpu ? 100.0 * weighted_cpu(PCTCPU(pp), pp) : 100.0 * PCTCPU(pp));
diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c
--- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c
+++ b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c
@@ -45,10 +45,7 @@
#include "hostres_oid.h"
#include "hostres_tree.h"
-/*
- * Ugly thing: PID_MAX, NO_PID defined only in kernel
- */
-#define NO_PID 100000
+static int no_pid;
enum SWRunType {
SRT_UNKNOWN = 1,
@@ -361,6 +358,8 @@
struct swrun_entry *entry;
struct kld_file_stat stat;
+ assert(no_pid > 0);
+
for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
stat.version = sizeof(struct kld_file_stat);
if (kldstat(fileid, &stat) < 0) {
@@ -373,10 +372,10 @@
* NO_PID + 1; NO_PID is PID_MAX + 1 thus it will be no risk to
* overlap with real PIDs which are in range of 1 .. NO_PID
*/
- entry = swrun_entry_find_by_index(NO_PID + 1 + stat.id);
+ entry = swrun_entry_find_by_index(no_pid + 1 + stat.id);
if (entry == NULL) {
/* new entry - get memory for it */
- entry = swrun_entry_create(NO_PID + 1 + stat.id);
+ entry = swrun_entry_create(no_pid + 1 + stat.id);
if (entry == NULL)
continue;
}
@@ -429,9 +428,10 @@
int nproc;
struct kld_file_stat stat;
- assert(entry != NULL);
+ assert(entry != NULL);
+ assert(no_pid > 0);
- if (entry->index >= NO_PID + 1) {
+ if (entry->index >= no_pid + 1) {
/*
* kernel and kernel files (*.ko) will be indexed
* starting with NO_PID + 1; NO_PID is PID_MAX + 1
@@ -439,13 +439,13 @@
* which are in range of 1 .. NO_PID
*/
stat.version = sizeof(stat);
- if (kldstat(entry->index - NO_PID - 1, &stat) == -1) {
+ if (kldstat(entry->index - no_pid - 1, &stat) == -1) {
/*
* not found, it's gone. Mark it as invalid for now, it
* will be removed from the list at next global refersh
*/
HRDBG("missing item with kid=%d",
- entry->index - NO_PID - 1);
+ entry->index - no_pid - 1);
entry->status = (int32_t)SRS_INVALID;
} else
kld_file_stat_to_swrun(&stat, entry);
@@ -473,12 +473,12 @@
int nproc;
struct kld_file_stat stat;
- assert(entry != NULL);
+ assert(entry != NULL);
+ assert(no_pid > 0);
- if (entry->index >= NO_PID + 1) {
+ if (entry->index >= no_pid + 1) {
/* this is a kernel item */
- HRDBG("attempt to unload KLD %d",
- entry->index - NO_PID - 1);
+ HRDBG("attempt to unload KLD %d", entry->index - no_pid - 1);
if (entry->index == SWOSIndex) {
/* can't invalidate the kernel itself */
@@ -486,14 +486,14 @@
}
stat.version = sizeof(stat);
- if (kldstat(entry->index - NO_PID - 1, &stat) == -1) {
+ if (kldstat(entry->index - no_pid - 1, &stat) == -1) {
/*
* not found, it's gone. Mark it as invalid for now, it
* will be removed from the list at next global
* refresh
*/
HRDBG("missing item with kid=%d",
- entry->index - NO_PID - 1);
+ entry->index - no_pid - 1);
entry->status = (int32_t)SRS_INVALID;
return (SNMP_ERR_NOERROR);
}
@@ -551,6 +551,17 @@
void
init_swrun_tbl(void)
{
+ size_t size;
+
+ if (no_pid == 0) {
+ size = sizeof(no_pid);
+ if (sysctlbyname("kern.pid_max", &no_pid, &size, NULL, 0) < 0) {
+ syslog(LOG_ERR,"Unable to read kern.pid_max sysctl: %s",
+ strerror(errno));
+ abort();
+ }
+ no_pid++;
+ }
refresh_swrun_tbl();
HRDBG("done");

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 28, 6:21 AM (13 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28063867
Default Alt Text
D43077.id131544.diff (11 KB)

Event Timeline