]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/lsns.c
rfkill: merge rfkill.8 project to util-linux
[thirdparty/util-linux.git] / sys-utils / lsns.c
1 /*
2 * lsns(8) - list system namespaces
3 *
4 * Copyright (C) 2015 Karel Zak <kzak@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 #include <stdio.h>
21 #include <string.h>
22 #include <getopt.h>
23 #include <stdlib.h>
24 #include <assert.h>
25 #include <dirent.h>
26 #include <unistd.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <wchar.h>
30 #include <libsmartcols.h>
31
32 #include "pathnames.h"
33 #include "nls.h"
34 #include "xalloc.h"
35 #include "c.h"
36 #include "list.h"
37 #include "closestream.h"
38 #include "optutils.h"
39 #include "procutils.h"
40 #include "strutils.h"
41 #include "namespace.h"
42 #include "path.h"
43 #include "idcache.h"
44
45 #include "debug.h"
46
47 static UL_DEBUG_DEFINE_MASK(lsns);
48 UL_DEBUG_DEFINE_MASKNAMES(lsns) = UL_DEBUG_EMPTY_MASKNAMES;
49
50 #define LSNS_DEBUG_INIT (1 << 1)
51 #define LSNS_DEBUG_PROC (1 << 2)
52 #define LSNS_DEBUG_NS (1 << 3)
53 #define LSNS_DEBUG_ALL 0xFFFF
54
55 #define DBG(m, x) __UL_DBG(lsns, LSNS_DEBUG_, m, x)
56 #define ON_DBG(m, x) __UL_DBG_CALL(lsns, LSNS_DEBUG_, m, x)
57
58 static struct idcache *uid_cache = NULL;
59
60 /* column IDs */
61 enum {
62 COL_NS = 0,
63 COL_TYPE,
64 COL_PATH,
65 COL_NPROCS,
66 COL_PID,
67 COL_PPID,
68 COL_COMMAND,
69 COL_UID,
70 COL_USER
71 };
72
73 /* column names */
74 struct colinfo {
75 const char *name; /* header */
76 double whint; /* width hint (N < 1 is in percent of termwidth) */
77 int flags; /* SCOLS_FL_* */
78 const char *help;
79 };
80
81 /* columns descriptions */
82 static const struct colinfo infos[] = {
83 [COL_NS] = { "NS", 10, SCOLS_FL_RIGHT, N_("namespace identifier (inode number)") },
84 [COL_TYPE] = { "TYPE", 5, 0, N_("kind of namespace") },
85 [COL_PATH] = { "PATH", 0, 0, N_("path to the namespace")},
86 [COL_NPROCS] = { "NPROCS", 5, SCOLS_FL_RIGHT, N_("number of processes in the namespace") },
87 [COL_PID] = { "PID", 5, SCOLS_FL_RIGHT, N_("lowest PID in the namespace") },
88 [COL_PPID] = { "PPID", 5, SCOLS_FL_RIGHT, N_("PPID of the PID") },
89 [COL_COMMAND] = { "COMMAND", 0, SCOLS_FL_TRUNC, N_("command line of the PID")},
90 [COL_UID] = { "UID", 0, SCOLS_FL_RIGHT, N_("UID of the PID")},
91 [COL_USER] = { "USER", 0, 0, N_("username of the PID")}
92 };
93
94 static int columns[ARRAY_SIZE(infos) * 2];
95 static size_t ncolumns;
96
97 enum {
98 LSNS_ID_MNT = 0,
99 LSNS_ID_NET,
100 LSNS_ID_PID,
101 LSNS_ID_UTS,
102 LSNS_ID_IPC,
103 LSNS_ID_USER,
104 LSNS_ID_CGROUP
105 };
106
107 static char *ns_names[] = {
108 [LSNS_ID_MNT] = "mnt",
109 [LSNS_ID_NET] = "net",
110 [LSNS_ID_PID] = "pid",
111 [LSNS_ID_UTS] = "uts",
112 [LSNS_ID_IPC] = "ipc",
113 [LSNS_ID_USER] = "user",
114 [LSNS_ID_CGROUP] = "cgroup"
115 };
116
117 struct lsns_namespace {
118 ino_t id;
119 int type; /* LSNS_* */
120 int nprocs;
121
122 struct lsns_process *proc;
123
124 struct list_head namespaces; /* lsns->processes member */
125 struct list_head processes; /* head of lsns_process *siblings */
126 };
127
128 struct lsns_process {
129 pid_t pid; /* process PID */
130 pid_t ppid; /* parent's PID */
131 pid_t tpid; /* thread group */
132 char state;
133 uid_t uid;
134
135 ino_t ns_ids[ARRAY_SIZE(ns_names)];
136 struct list_head ns_siblings[ARRAY_SIZE(ns_names)];
137
138 struct list_head processes; /* list of processes */
139
140 struct libscols_line *outline;
141 struct lsns_process *parent;
142 };
143
144 struct lsns {
145 struct list_head processes;
146 struct list_head namespaces;
147
148 pid_t fltr_pid; /* filter out by PID */
149 ino_t fltr_ns; /* filter out by namespace */
150 int fltr_types[ARRAY_SIZE(ns_names)];
151 int fltr_ntypes;
152
153 unsigned int raw : 1,
154 json : 1,
155 tree : 1,
156 list : 1,
157 notrunc : 1,
158 no_headings: 1;
159 };
160
161 static void lsns_init_debug(void)
162 {
163 __UL_INIT_DEBUG(lsns, LSNS_DEBUG_, 0, LSNS_DEBUG);
164 }
165
166 static int ns_name2type(const char *name)
167 {
168 size_t i;
169
170 for (i = 0; i < ARRAY_SIZE(ns_names); i++) {
171 if (strcmp(ns_names[i], name) == 0)
172 return i;
173 }
174 return -1;
175 }
176
177 static int column_name_to_id(const char *name, size_t namesz)
178 {
179 size_t i;
180
181 assert(name);
182
183 for (i = 0; i < ARRAY_SIZE(infos); i++) {
184 const char *cn = infos[i].name;
185
186 if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
187 return i;
188 }
189 warnx(_("unknown column: %s"), name);
190 return -1;
191 }
192
193 static inline int get_column_id(int num)
194 {
195 assert(num >= 0);
196 assert((size_t) num < ncolumns);
197 assert(columns[num] < (int) ARRAY_SIZE(infos));
198
199 return columns[num];
200 }
201
202 static inline const struct colinfo *get_column_info(unsigned num)
203 {
204 return &infos[ get_column_id(num) ];
205 }
206
207 static int get_ns_ino(int dir, const char *nsname, ino_t *ino)
208 {
209 struct stat st;
210 char path[16];
211
212 snprintf(path, sizeof(path), "ns/%s", nsname);
213
214 if (fstatat(dir, path, &st, 0) != 0)
215 return -errno;
216 *ino = st.st_ino;
217 return 0;
218 }
219
220 static int parse_proc_stat(FILE *fp, pid_t *pid, char *state, pid_t *ppid)
221 {
222 char *line = NULL, *p;
223 size_t len = 0;
224 int rc;
225
226 if (getline(&line, &len, fp) < 0) {
227 rc = -errno;
228 goto error;
229 }
230
231 p = strrchr(line, ')');
232 if (p == NULL ||
233 sscanf(line, "%d (", pid) != 1 ||
234 sscanf(p, ") %c %d*[^\n]", state, ppid) != 2) {
235 rc = -EINVAL;
236 goto error;
237 }
238 rc = 0;
239
240 error:
241 free(line);
242 return rc;
243 }
244
245 static int read_process(struct lsns *ls, pid_t pid)
246 {
247 struct lsns_process *p = NULL;
248 char buf[BUFSIZ];
249 DIR *dir;
250 int rc = 0, fd;
251 FILE *f = NULL;
252 size_t i;
253 struct stat st;
254
255 DBG(PROC, ul_debug("reading %d", (int) pid));
256
257 snprintf(buf, sizeof(buf), "/proc/%d", pid);
258 dir = opendir(buf);
259 if (!dir)
260 return -errno;
261
262 p = xcalloc(1, sizeof(*p));
263 if (!p) {
264 rc = -ENOMEM;
265 goto done;
266 }
267
268 if (fstat(dirfd(dir), &st) == 0) {
269 p->uid = st.st_uid;
270 add_uid(uid_cache, st.st_uid);
271 }
272
273 fd = openat(dirfd(dir), "stat", O_RDONLY);
274 if (fd < 0) {
275 rc = -errno;
276 goto done;
277 }
278 if (!(f = fdopen(fd, "r"))) {
279 rc = -errno;
280 goto done;
281 }
282 rc = parse_proc_stat(f, &p->pid, &p->state, &p->ppid);
283 if (rc < 0)
284 goto done;
285 rc = 0;
286
287 for (i = 0; i < ARRAY_SIZE(p->ns_ids); i++) {
288 INIT_LIST_HEAD(&p->ns_siblings[i]);
289
290 if (!ls->fltr_types[i])
291 continue;
292
293 rc = get_ns_ino(dirfd(dir), ns_names[i], &p->ns_ids[i]);
294 if (rc && rc != -EACCES && rc != -ENOENT)
295 goto done;
296 rc = 0;
297 }
298
299 INIT_LIST_HEAD(&p->processes);
300
301 DBG(PROC, ul_debugobj(p, "new pid=%d", p->pid));
302 list_add_tail(&p->processes, &ls->processes);
303 done:
304 if (f)
305 fclose(f);
306 closedir(dir);
307 if (rc)
308 free(p);
309 return rc;
310 }
311
312 static int read_processes(struct lsns *ls)
313 {
314 struct proc_processes *proc = NULL;
315 pid_t pid;
316 int rc = 0;
317
318 DBG(PROC, ul_debug("opening /proc"));
319
320 if (!(proc = proc_open_processes())) {
321 rc = -errno;
322 goto done;
323 }
324
325 while (proc_next_pid(proc, &pid) == 0) {
326 rc = read_process(ls, pid);
327 if (rc && rc != -EACCES && rc != -ENOENT)
328 break;
329 rc = 0;
330 }
331 done:
332 DBG(PROC, ul_debug("closing /proc"));
333 proc_close_processes(proc);
334 return rc;
335 }
336
337 static struct lsns_namespace *get_namespace(struct lsns *ls, ino_t ino)
338 {
339 struct list_head *p;
340
341 list_for_each(p, &ls->namespaces) {
342 struct lsns_namespace *ns = list_entry(p, struct lsns_namespace, namespaces);
343
344 if (ns->id == ino)
345 return ns;
346 }
347 return NULL;
348 }
349
350 static int namespace_has_process(struct lsns_namespace *ns, pid_t pid)
351 {
352 struct list_head *p;
353
354 list_for_each(p, &ns->processes) {
355 struct lsns_process *proc = list_entry(p, struct lsns_process, ns_siblings[ns->type]);
356
357 if (proc->pid == pid)
358 return 1;
359 }
360 return 0;
361 }
362
363 static struct lsns_namespace *add_namespace(struct lsns *ls, int type, ino_t ino)
364 {
365 struct lsns_namespace *ns = xcalloc(1, sizeof(*ns));
366
367 if (!ns)
368 return NULL;
369
370 DBG(NS, ul_debugobj(ns, "new %s[%ju]", ns_names[type], (uintmax_t)ino));
371
372 INIT_LIST_HEAD(&ns->processes);
373 INIT_LIST_HEAD(&ns->namespaces);
374
375 ns->type = type;
376 ns->id = ino;
377
378 list_add_tail(&ns->namespaces, &ls->namespaces);
379 return ns;
380 }
381
382 static int add_process_to_namespace(struct lsns *ls, struct lsns_namespace *ns, struct lsns_process *proc)
383 {
384 struct list_head *p;
385
386 DBG(NS, ul_debugobj(ns, "add process [%p] pid=%d to %s[%ju]",
387 proc, proc->pid, ns_names[ns->type], (uintmax_t)ns->id));
388
389 list_for_each(p, &ls->processes) {
390 struct lsns_process *xproc = list_entry(p, struct lsns_process, processes);
391
392 if (xproc->pid == proc->ppid) /* my parent */
393 proc->parent = xproc;
394 else if (xproc->ppid == proc->pid) /* my child */
395 xproc->parent = proc;
396 }
397
398 list_add_tail(&proc->ns_siblings[ns->type], &ns->processes);
399 ns->nprocs++;
400
401 if (!ns->proc || ns->proc->pid > proc->pid)
402 ns->proc = proc;
403
404 return 0;
405 }
406
407 static int cmp_namespaces(struct list_head *a, struct list_head *b,
408 __attribute__((__unused__)) void *data)
409 {
410 struct lsns_namespace *xa = list_entry(a, struct lsns_namespace, namespaces),
411 *xb = list_entry(b, struct lsns_namespace, namespaces);
412
413 return cmp_numbers(xa->id, xb->id);
414 }
415
416 static int read_namespaces(struct lsns *ls)
417 {
418 struct list_head *p;
419
420 DBG(NS, ul_debug("reading namespace"));
421
422 list_for_each(p, &ls->processes) {
423 size_t i;
424 struct lsns_namespace *ns;
425 struct lsns_process *proc = list_entry(p, struct lsns_process, processes);
426
427 for (i = 0; i < ARRAY_SIZE(proc->ns_ids); i++) {
428 if (proc->ns_ids[i] == 0)
429 continue;
430 if (!(ns = get_namespace(ls, proc->ns_ids[i]))) {
431 ns = add_namespace(ls, i, proc->ns_ids[i]);
432 if (!ns)
433 return -ENOMEM;
434 }
435 add_process_to_namespace(ls, ns, proc);
436 }
437 }
438
439 list_sort(&ls->namespaces, cmp_namespaces, NULL);
440
441 return 0;
442 }
443
444 static void add_scols_line(struct lsns *ls, struct libscols_table *table,
445 struct lsns_namespace *ns, struct lsns_process *proc)
446 {
447 size_t i;
448 struct libscols_line *line;
449
450 assert(ns);
451 assert(table);
452
453 line = scols_table_new_line(table,
454 ls->tree && proc->parent ? proc->parent->outline : NULL);
455 if (!line) {
456 warn(_("failed to add line to output"));
457 return;
458 }
459
460 for (i = 0; i < ncolumns; i++) {
461 char *str = NULL;
462
463 switch (get_column_id(i)) {
464 case COL_NS:
465 xasprintf(&str, "%ju", (uintmax_t)ns->id);
466 break;
467 case COL_PID:
468 xasprintf(&str, "%d", (int) proc->pid);
469 break;
470 case COL_PPID:
471 xasprintf(&str, "%d", (int) proc->ppid);
472 break;
473 case COL_TYPE:
474 xasprintf(&str, "%s", ns_names[ns->type]);
475 break;
476 case COL_NPROCS:
477 xasprintf(&str, "%d", ns->nprocs);
478 break;
479 case COL_COMMAND:
480 str = proc_get_command(proc->pid);
481 if (!str)
482 str = proc_get_command_name(proc->pid);
483 break;
484 case COL_PATH:
485 xasprintf(&str, "/proc/%d/ns/%s", (int) proc->pid, ns_names[ns->type]);
486 break;
487 case COL_UID:
488 xasprintf(&str, "%d", (int) proc->uid);
489 break;
490 case COL_USER:
491 xasprintf(&str, "%s", get_id(uid_cache, proc->uid)->name);
492 break;
493 default:
494 break;
495 }
496
497 if (str && scols_line_refer_data(line, i, str) != 0)
498 err_oom();
499 }
500
501 proc->outline = line;
502 }
503
504 static struct libscols_table *init_scols_table(struct lsns *ls)
505 {
506 struct libscols_table *tab;
507 size_t i;
508
509 tab = scols_new_table();
510 if (!tab) {
511 warn(_("failed to initialize output table"));
512 return NULL;
513 }
514
515 scols_table_enable_raw(tab, ls->raw);
516 scols_table_enable_json(tab, ls->json);
517 scols_table_enable_noheadings(tab, ls->no_headings);
518
519 if (ls->json)
520 scols_table_set_name(tab, "namespaces");
521
522 for (i = 0; i < ncolumns; i++) {
523 const struct colinfo *col = get_column_info(i);
524 int flags = col->flags;
525
526 if (ls->notrunc)
527 flags &= ~SCOLS_FL_TRUNC;
528 if (ls->tree && get_column_id(i) == COL_COMMAND)
529 flags |= SCOLS_FL_TREE;
530
531 if (!scols_table_new_column(tab, col->name, col->whint, flags)) {
532 warnx(_("failed to initialize output column"));
533 goto err;
534 }
535 }
536
537 return tab;
538 err:
539 scols_unref_table(tab);
540 return NULL;
541 }
542
543 static int show_namespaces(struct lsns *ls)
544 {
545 struct libscols_table *tab;
546 struct list_head *p;
547 int rc = 0;
548
549 tab = init_scols_table(ls);
550 if (!tab)
551 return -ENOMEM;
552
553 list_for_each(p, &ls->namespaces) {
554 struct lsns_namespace *ns = list_entry(p, struct lsns_namespace, namespaces);
555
556 if (ls->fltr_pid != 0 && !namespace_has_process(ns, ls->fltr_pid))
557 continue;
558
559 add_scols_line(ls, tab, ns, ns->proc);
560 }
561
562 scols_print_table(tab);
563 scols_unref_table(tab);
564 return rc;
565 }
566
567 static void show_process(struct lsns *ls, struct libscols_table *tab,
568 struct lsns_process *proc, struct lsns_namespace *ns)
569 {
570 /*
571 * create a tree from parent->child relation, but only if the parent is
572 * within the same namespace
573 */
574 if (ls->tree
575 && proc->parent
576 && !proc->parent->outline
577 && proc->parent->ns_ids[ns->type] == proc->ns_ids[ns->type])
578 show_process(ls, tab, proc->parent, ns);
579
580 add_scols_line(ls, tab, ns, proc);
581 }
582
583
584 static int show_namespace_processes(struct lsns *ls, struct lsns_namespace *ns)
585 {
586 struct libscols_table *tab;
587 struct list_head *p;
588
589 tab = init_scols_table(ls);
590 if (!tab)
591 return -ENOMEM;
592
593 list_for_each(p, &ns->processes) {
594 struct lsns_process *proc = list_entry(p, struct lsns_process, ns_siblings[ns->type]);
595
596 if (!proc->outline)
597 show_process(ls, tab, proc, ns);
598 }
599
600
601 scols_print_table(tab);
602 scols_unref_table(tab);
603 return 0;
604 }
605
606 static void __attribute__((__noreturn__)) usage(void)
607 {
608 FILE *out = stdout;
609 size_t i;
610
611 fputs(USAGE_HEADER, out);
612
613 fprintf(out,
614 _(" %s [options] [<namespace>]\n"), program_invocation_short_name);
615
616 fputs(USAGE_SEPARATOR, out);
617 fputs(_("List system namespaces.\n"), out);
618
619 fputs(USAGE_OPTIONS, out);
620 fputs(_(" -J, --json use JSON output format\n"), out);
621 fputs(_(" -l, --list use list format output\n"), out);
622 fputs(_(" -n, --noheadings don't print headings\n"), out);
623 fputs(_(" -o, --output <list> define which output columns to use\n"), out);
624 fputs(_(" -p, --task <pid> print process namespaces\n"), out);
625 fputs(_(" -r, --raw use the raw output format\n"), out);
626 fputs(_(" -u, --notruncate don't truncate text in columns\n"), out);
627 fputs(_(" -t, --type <name> namespace type (mnt, net, ipc, user, pid, uts, cgroup)\n"), out);
628
629 fputs(USAGE_SEPARATOR, out);
630 printf(USAGE_HELP_OPTIONS(24));
631
632 fputs(USAGE_COLUMNS, out);
633 for (i = 0; i < ARRAY_SIZE(infos); i++)
634 fprintf(out, " %11s %s\n", infos[i].name, _(infos[i].help));
635
636 printf(USAGE_MAN_TAIL("lsns(8)"));
637
638 exit(EXIT_SUCCESS);
639 }
640
641
642 int main(int argc, char *argv[])
643 {
644 struct lsns ls;
645 int c;
646 int r = 0;
647 char *outarg = NULL;
648 static const struct option long_opts[] = {
649 { "json", no_argument, NULL, 'J' },
650 { "task", required_argument, NULL, 'p' },
651 { "help", no_argument, NULL, 'h' },
652 { "output", required_argument, NULL, 'o' },
653 { "notruncate", no_argument, NULL, 'u' },
654 { "version", no_argument, NULL, 'V' },
655 { "noheadings", no_argument, NULL, 'n' },
656 { "list", no_argument, NULL, 'l' },
657 { "raw", no_argument, NULL, 'r' },
658 { "type", required_argument, NULL, 't' },
659 { NULL, 0, NULL, 0 }
660 };
661
662 static const ul_excl_t excl[] = { /* rows and cols in ASCII order */
663 { 'J','r' },
664 { 0 }
665 };
666 int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
667
668 setlocale(LC_ALL, "");
669 bindtextdomain(PACKAGE, LOCALEDIR);
670 textdomain(PACKAGE);
671 atexit(close_stdout);
672
673 lsns_init_debug();
674 memset(&ls, 0, sizeof(ls));
675
676 INIT_LIST_HEAD(&ls.processes);
677 INIT_LIST_HEAD(&ls.namespaces);
678
679 while ((c = getopt_long(argc, argv,
680 "Jlp:o:nruhVt:", long_opts, NULL)) != -1) {
681
682 err_exclusive_options(c, long_opts, excl, excl_st);
683
684 switch(c) {
685 case 'J':
686 ls.json = 1;
687 break;
688 case 'l':
689 ls.list = 1;
690 break;
691 case 'o':
692 outarg = optarg;
693 break;
694 case 'V':
695 printf(UTIL_LINUX_VERSION);
696 return EXIT_SUCCESS;
697 case 'p':
698 ls.fltr_pid = strtos32_or_err(optarg, _("invalid PID argument"));
699 break;
700 case 'h':
701 usage();
702 case 'n':
703 ls.no_headings = 1;
704 break;
705 case 'r':
706 ls.raw = 1;
707 break;
708 case 'u':
709 ls.notrunc = 1;
710 break;
711 case 't':
712 {
713 int type = ns_name2type(optarg);
714 if (type < 0)
715 errx(EXIT_FAILURE, _("unknown namespace type: %s"), optarg);
716 ls.fltr_types[type] = 1;
717 ls.fltr_ntypes++;
718 break;
719 }
720 default:
721 errtryhelp(EXIT_FAILURE);
722 }
723 }
724
725 if (!ls.fltr_ntypes) {
726 size_t i;
727 for (i = 0; i < ARRAY_SIZE(ns_names); i++)
728 ls.fltr_types[i] = 1;
729 }
730
731 if (optind < argc) {
732 if (ls.fltr_pid)
733 errx(EXIT_FAILURE, _("--task is mutually exclusive with <namespace>"));
734 ls.fltr_ns = strtou64_or_err(argv[optind], _("invalid namespace argument"));
735 ls.tree = ls.list ? 0 : 1;
736
737 if (!ncolumns) {
738 columns[ncolumns++] = COL_PID;
739 columns[ncolumns++] = COL_PPID;
740 columns[ncolumns++] = COL_USER;
741 columns[ncolumns++] = COL_COMMAND;
742 }
743 }
744
745 if (!ncolumns) {
746 columns[ncolumns++] = COL_NS;
747 columns[ncolumns++] = COL_TYPE;
748 columns[ncolumns++] = COL_NPROCS;
749 columns[ncolumns++] = COL_PID;
750 columns[ncolumns++] = COL_USER;
751 columns[ncolumns++] = COL_COMMAND;
752 }
753
754 if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
755 &ncolumns, column_name_to_id) < 0)
756 return EXIT_FAILURE;
757
758 scols_init_debug(0);
759
760 uid_cache = new_idcache();
761 if (!uid_cache)
762 err(EXIT_FAILURE, _("failed to allocate UID cache"));
763
764 r = read_processes(&ls);
765 if (!r)
766 r = read_namespaces(&ls);
767 if (!r) {
768 if (ls.fltr_ns) {
769 struct lsns_namespace *ns = get_namespace(&ls, ls.fltr_ns);
770
771 if (!ns)
772 errx(EXIT_FAILURE, _("not found namespace: %ju"), (uintmax_t) ls.fltr_ns);
773 r = show_namespace_processes(&ls, ns);
774 } else
775 r = show_namespaces(&ls);
776 }
777
778 free_idcache(uid_cache);
779 return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
780 }