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

@@ -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: