procps/lib/nsutils.c
Filipe Brandenburger b56fd9d358 build-sys: split test cases in lib/ into their own files
In order to avoid compiling the same source files twice, with and
without the TEST_PROGRAM define.

Tested that the build still works and that `make distcheck` works as
expected.

Tested that the test_* programs in lib/ keep working. (Though they are
not really invoked by `make check` and in particular test_nsutils is
quite useless, test_fileutils also quite poor.)

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2015-05-01 17:43:51 -07:00

31 lines
575 B
C

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "proc/readproc.h"
#include "nsutils.h"
/* we need to fill in only namespace information */
int ns_read(pid_t pid, proc_t *ns_task)
{
struct stat st;
char buff[50];
int i, rc = 0;
for (i = 0; i < NUM_NS; i++) {
snprintf(buff, sizeof(buff), "/proc/%i/ns/%s", pid,
get_ns_name(i));
if (stat(buff, &st)) {
if (errno != ENOENT)
rc = errno;
ns_task->ns[i] = 0;
continue;
}
ns_task->ns[i] = st.st_ino;
}
return rc;
}