]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add namespace related associations
authorMasatake YAMATO <yamato@redhat.com>
Fri, 16 Apr 2021 22:15:50 +0000 (07:15 +0900)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:53 +0000 (11:01 +0200)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-file.c
misc-utils/lsfd.c
misc-utils/lsfd.h

index 9e94b817297ebaa1ce67ed68551d21135e9ba460..e749578921a7ec5f8380c5560a1ca2d6c7148279 100644 (file)
@@ -35,6 +35,17 @@ static const char *assocstr[N_ASSOCS] = {
        /* "root" appears as user names, too.
         * So we use "rtd" here instead of "root". */
        [ASSOC_ROOT]      = "rtd",
+       [ASSOC_NS_CGROUP] = "cgroup",
+       [ASSOC_NS_IPC]    = "ipc",
+       [ASSOC_NS_MNT]    = "mnt",
+       [ASSOC_NS_NET]    = "net",
+       [ASSOC_NS_PID]    = "pid",
+       [ASSOC_NS_PID4C]  = "pid4c",
+       [ASSOC_NS_TIME]   = "time",
+       [ASSOC_NS_TIME4C] = "time4c",
+       [ASSOC_NS_USER]   = "user",
+       [ASSOC_NS_UTS]    = "uts",
+       [ASSOC_MEM]       = "mmap",
 };
 
 static const char *strftype(mode_t ftype)
index 629e0cf8df9e3ee4faec5414b677bc83ca02c0f6..40c2860fb4505364ac12e1bf6e7dc8a7288e3edb 100644 (file)
@@ -87,6 +87,7 @@ static struct colinfo infos[] = {
        [COL_USER]    = { "USER",     0, SCOLS_FL_RIGHT, N_("user of the process") },
        /* DEVICE */
        /* SIZE/OFF */
+       /* MNTID */
 };
 
 static int columns[ARRAY_SIZE(infos) * 2] = {-1};
@@ -308,26 +309,23 @@ static struct file *collect_outofbox_file(int dd, const char *name, int associat
        return collect_file(&sb, sym, association);
 }
 
-static void collect_outofbox_files(struct proc *proc)
+static void collect_outofbox_files(struct proc *proc,
+                                  const char *proc_template,
+                                  enum association assocs[],
+                                  const char* assoc_names[],
+                                  unsigned int count)
 {
        DIR *dirp;
        int dd;
 
-       dirp = opendirf("/proc/%d", proc->pid);
+       dirp = opendirf(proc_template, proc->pid);
        if (!dirp)
                return;
 
        if ((dd = dirfd(dirp)) < 0 )
                return;
 
-       enum association assocs[] = { ASSOC_CWD, ASSOC_EXE, ASSOC_ROOT };
-       const char* assoc_names[] = {
-               [ASSOC_CWD]  = "cwd",
-               [ASSOC_EXE]  = "exe",
-               [ASSOC_ROOT] = "root",
-       };
-
-       for (unsigned int i = 0; i < ARRAY_SIZE(assocs); i++) {
+       for (unsigned int i = 0; i < count; i++) {
                struct file *file;
 
                if ((file = collect_outofbox_file(dd,
@@ -348,7 +346,47 @@ static void fill_proc(struct proc *proc)
        if (!proc->command)
                err(EXIT_FAILURE, _("failed to get command name"));
 
-       collect_outofbox_files(proc);
+
+       const char *classical_template = "/proc/%d";
+       enum association classical_assocs[] = { ASSOC_CWD, ASSOC_EXE, ASSOC_ROOT };
+       const char* classical_assoc_names[] = {
+               [ASSOC_CWD]  = "cwd",
+               [ASSOC_EXE]  = "exe",
+               [ASSOC_ROOT] = "root",
+       };
+       collect_outofbox_files(proc, classical_template,
+                              classical_assocs, classical_assoc_names,
+                              ARRAY_SIZE(classical_assocs));
+
+       const char *namespace_template = "/proc/%d/ns";
+       enum association namespace_assocs[] = {
+               ASSOC_NS_CGROUP,
+               ASSOC_NS_IPC,
+               ASSOC_NS_MNT,
+               ASSOC_NS_NET,
+               ASSOC_NS_PID,
+               ASSOC_NS_PID4C,
+               ASSOC_NS_TIME,
+               ASSOC_NS_TIME4C,
+               ASSOC_NS_USER,
+               ASSOC_NS_UTS,
+       };
+       const char* namespace_assoc_names[] = {
+               [ASSOC_NS_CGROUP] = "cgroup",
+               [ASSOC_NS_IPC]    = "ipc",
+               [ASSOC_NS_MNT]    = "mnt",
+               [ASSOC_NS_NET]    = "net",
+               [ASSOC_NS_PID]    = "pid",
+               [ASSOC_NS_PID4C]  = "pid_for_children",
+               [ASSOC_NS_TIME]   = "time",
+               [ASSOC_NS_TIME4C] = "time_for_children",
+               [ASSOC_NS_USER]   = "user",
+               [ASSOC_NS_UTS]    = "uts",
+       };
+       collect_outofbox_files(proc, namespace_template,
+                              namespace_assocs, namespace_assoc_names,
+                              ARRAY_SIZE(namespace_assocs));
+
        collect_fd_files(proc);
 }
 
index 839660a10c763940ab9b349d770edcae9ce7efc9..7caa3bb9d99ef34ca30fb698f4fef9f27f47b7dc 100644 (file)
@@ -70,6 +70,17 @@ enum association {
        ASSOC_CWD = 1,
        ASSOC_EXE,
        ASSOC_ROOT,
+       ASSOC_NS_CGROUP,
+       ASSOC_NS_IPC,
+       ASSOC_NS_MNT,
+       ASSOC_NS_NET,
+       ASSOC_NS_PID,
+       ASSOC_NS_PID4C,
+       ASSOC_NS_TIME,
+       ASSOC_NS_TIME4C,
+       ASSOC_NS_USER,
+       ASSOC_NS_UTS,
+       ASSOC_MEM,
        N_ASSOCS,
 };