]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsns: fill UID and USER columns for interpolated namespaces
authorMasatake YAMATO <yamato@redhat.com>
Fri, 30 Apr 2021 13:14:22 +0000 (22:14 +0900)
committerKarel Zak <kzak@redhat.com>
Mon, 24 May 2021 11:39:53 +0000 (13:39 +0200)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
sys-utils/lsns.c

index ac31c8fd9b933accd8256234598f7cc2a9465d91..614fb8fc541d06fb9fc2d1d8da9a2ffb9faa3184 100644 (file)
@@ -159,6 +159,7 @@ struct lsns_namespace {
 
        struct lsns_namespace *related_ns[MAX_RELA];
        struct libscols_line *ns_outline;
+       uid_t uid_fallback;     /* refer this member if `proc' is NULL. */
 
        struct list_head namespaces;    /* lsns->processes member */
        struct list_head processes;     /* head of lsns_process *siblings */
@@ -730,6 +731,8 @@ static struct lsns_namespace *add_namespace_for_nsfd(struct lsns *ls, int fd, in
 
  add_ns:
        ns = add_namespace(ls, lsns_type, ino, ino_parent, ino_owner);
+       ioctl(fd, NS_GET_OWNER_UID, &ns->uid_fallback);
+       add_uid(uid_cache, ns->uid_fallback);
 
        if ((lsns_type == LSNS_ID_USER || lsns_type == LSNS_ID_PID)
            && ino_parent != ino && ino_parent != 0) {
@@ -998,14 +1001,10 @@ static void add_scols_line(struct lsns *ls, struct libscols_table *table,
                        xasprintf(&str, "/proc/%d/ns/%s", (int) proc->pid, ns_names[ns->type]);
                        break;
                case COL_UID:
-                       if (!proc)
-                               break;
-                       xasprintf(&str, "%d", (int) proc->uid);
+                       xasprintf(&str, "%d", proc? (int) proc->uid: (int) ns->uid_fallback);
                        break;
                case COL_USER:
-                       if (!proc)
-                               break;
-                       xasprintf(&str, "%s", get_id(uid_cache, proc->uid)->name);
+                       xasprintf(&str, "%s", get_id(uid_cache, proc? proc->uid: ns->uid_fallback)->name);
                        break;
                case COL_NETNSID:
                        if (!proc)