-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathidns.c
87 lines (64 loc) · 1.56 KB
/
idns.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Tool displaying the ids of namespaces
Author: R. Koucha
Date: 25-Mar-2020
*/
#include <errno.h>
#include <sys/types.h>
#include <stdio.h>
#include <libgen.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include "util.h"
int main(int ac, char *av[])
{
int i, rc;
char tpath[256];
struct stat st;
char *ns_all[] = {"cgroup", "ipc", "mnt", "net", "pid", "uts", "user", NULL };
char **ns;
if (ac < 2) {
fprintf(stderr, "Usage: %s pid [ns_names...]\n", basename(av[0]));
return 1;
}
if (!is_pid(av[1])) {
fprintf(stderr, "Parameter '%s' must be a pid\n", av[1]);
return 1;
}
// If all is passed, use "all"
if (2 == ac) {
ns = ns_all;
} else {
ns = (char **)0;
}
for (i = 2; i < ac; i ++) {
if (!strcmp(av[i], "all")) {
ns = ns_all;
break;
}
} // End for
// Namespaces are on the command line
if (!ns) {
ns = &(av[2]);
}
// For all the namespaces passed as parameter
for (i = 0; ns[i]; i ++) {
if (!is_ns_name(ns[i])) {
fprintf(stderr, "Unknown namespace name '%s'\n", ns[i]);
return 1;
}
// Build the pathname of the namespace
snprintf(tpath, sizeof(tpath), "/proc/%s/ns/%s", av[1], ns[i]);
// Get the information of the namespace
rc = stat(tpath, &st);
if (rc < 0) {
ERR("stat(%s): '%m' (%d)\n", tpath, errno);
return 1;
}
printf("%s [Device,Inode]: [%lu,%lu]\n", tpath, st.st_dev, st.st_ino);
} // End for
return 0;
} // main