Merge commit 'refs/merge-requests/13' of git://gitorious.org/procps/procps into merge-requests/13

Conflicts:
	pgrep.c
	ps/output.c
	ps/ps.1
This commit is contained in:
Craig Small
2013-09-11 21:34:05 +10:00
12 changed files with 350 additions and 10 deletions

View File

@ -11,6 +11,8 @@ global:
escaped_copy;
free_slabinfo;
freeproc;
get_ns_id;
get_ns_name;
get_pid_digits;
get_slabinfo;
getbtime;

View File

@ -457,6 +457,51 @@ static void oomadj2proc(const char* S, proc_t *restrict P)
#endif
///////////////////////////////////////////////////////////////////////
static ino_t _ns2proc(unsigned pid, const char *ns)
{
struct stat s;
char filename[40];
snprintf(filename, sizeof(filename), "/proc/%i/ns/%s", pid, ns);
if (stat(filename, &s) == -1)
return 0;
return s.st_ino;
}
static const char *ns_names[] = {
[IPCNS] = "ipc",
[MNTNS] = "mnt",
[NETNS] = "net",
[PIDNS] = "pid",
[USERNS] = "user",
[UTSNS] = "uts",
};
const char *get_ns_name(int id) {
if (id >= NUM_NS)
return NULL;
return ns_names[id];
}
int get_ns_id(const char *name) {
int i;
for (i = 0; i < NUM_NS; i++)
if (!strcmp(ns_names[i], name))
return i;
return -1;
}
static void ns2proc(proc_t *restrict P) {
int i;
for (i = 0; i < NUM_NS; i++)
P->ns[i] = _ns2proc(P->tgid, ns_names[i]);
}
///////////////////////////////////////////////////////////////////////
// Reads /proc/*/stat files, being careful not to trip over processes with
// names like ":-) 1 2 3 4 5 6".
@ -757,6 +802,7 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
static struct stat sb; // stat() buffer
char *restrict const path = PT->path;
unsigned flags = PT->flags;
int i;
if (unlikely(stat(path, &sb) == -1)) /* no such dirent (anymore) */
goto next_proc;
@ -844,6 +890,12 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
}
#endif
if (unlikely(flags & PROC_FILLNS)) // read /proc/#/ns/*
ns2proc(p);
else
for (i = 0; i < NUM_NS; i++)
p->ns[i] = 0;
return p;
next_proc:
return NULL;
@ -862,6 +914,7 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
static struct utlbuf_s ub = { NULL, 0 }; // buf for stat,statm,status
static struct stat sb; // stat() buffer
unsigned flags = PT->flags;
int i;
if (unlikely(stat(path, &sb) == -1)) /* no such dirent (anymore) */
goto next_task;
@ -974,6 +1027,11 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
oomadj2proc(ub.buf, t);
}
#endif
if (unlikely(flags & PROC_FILLNS))
ns2proc(t);
else
for (i = 0; i < NUM_NS; i++)
t->ns[i] = 0;
return t;
next_task:

View File

@ -31,6 +31,18 @@ EXTERN_C_BEGIN
// neither tgid nor tid seemed correct. (in other words, FIXME)
#define XXXID tid
#define NUM_NS 6
enum ns_type {
IPCNS = 0,
MNTNS,
NETNS,
PIDNS,
USERNS,
UTSNS
};
extern const char *get_ns_name(int id);
extern int get_ns_id(const char *name);
// Basic data structure which holds all information we can get about a process.
// (unless otherwise specified, fields are read from /proc/#/stat)
//
@ -157,6 +169,8 @@ typedef struct proc_t {
oom_score, // oom_score (badness for OOM killer)
oom_adj; // oom_adj (adjustment to OOM score)
#endif
ino_t
ns[NUM_NS]; // ns/* inode number of /proc/<pid>/ns/*
} proc_t;
// PROCTAB: data structure holding the persistent information readproc needs
@ -266,6 +280,7 @@ extern proc_t * get_proc_stats(pid_t pid, proc_t *p);
#define PROC_FILLCGROUP 0x0200 // alloc and fill in `cgroup`
#define PROC_FILLSUPGRP 0x0400 // resolve supplementary group id -> group name
#define PROC_FILLOOM 0x0800 // fill in proc_t oom_score and oom_adj
#define PROC_FILLNS 0x8000 // fill in proc_t namespace information
#define PROC_LOOSE_TASKS 0x2000 // treat threads as if they were processes