]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/lsns.c
lsns: missing ns/<name> is not error
[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 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 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 };
105
106 static char *ns_names[] = {
107 [LSNS_ID_MNT] = "mnt",
108 [LSNS_ID_NET] = "net",
109 [LSNS_ID_PID] = "pid",
110 [LSNS_ID_UTS] = "uts",
111 [LSNS_ID_IPC] = "ipc",
112 [LSNS_ID_USER] = "user"
113 };
114
115 struct lsns_namespace {
116 ino_t id;
117 int type; /* LSNS_* */
118 int nprocs;
119
120 struct lsns_process *proc;
121
122 struct list_head namespaces; /* lsns->processes member */
123 struct list_head processes; /* head of lsns_process *siblings */
124 };
125
126 struct lsns_process {
127 pid_t pid; /* process PID */
128 pid_t ppid; /* parent's PID */
129 pid_t tpid; /* thread group */
130 char state;
131 uid_t uid;
132
133 ino_t ns_ids[ARRAY_SIZE(ns_names)];
134 struct list_head ns_siblings[ARRAY_SIZE(ns_names)];
135
136 struct list_head processes; /* list of processes */
137
138 struct libscols_line *outline;
139 struct lsns_process *parent;
140 };
141
142 struct lsns {
143 struct list_head processes;
144 struct list_head namespaces;
145
146 pid_t fltr_pid; /* filter out by PID */
147 ino_t fltr_ns; /* filter out by namespace */
148 int fltr_types[ARRAY_SIZE(ns_names)];
149 int fltr_ntypes;
150
151 unsigned int raw : 1,
152 json : 1,
153 tree : 1,
154 list : 1,
155 notrunc : 1,
156 no_headings: 1;
157 };
158
159 static void lsns_init_debug(void)
160 {
161 __UL_INIT_DEBUG(lsns, LSNS_DEBUG_, 0, LSNS_DEBUG);
162 }
163
164 static int ns_name2type(const char *name)
165 {
166 size_t i;
167
168 for (i = 0; i < ARRAY_SIZE(ns_names); i++) {
169 if (strcmp(ns_names[i], name) == 0)
170 return i;
171 }
172 return -1;
173 }
174
175 static int column_name_to_id(const char *name, size_t namesz)
176 {
177 size_t i;
178
179 assert(name);
180
181 for (i = 0; i < ARRAY_SIZE(infos); i++) {
182 const char *cn = infos[i].name;
183
184 if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
185 return i;
186 }
187 warnx(_("unknown column: %s"), name);
188 return -1;
189 }
190
191 static inline int get_column_id(int num)
192 {
193 assert(num >= 0);
194 assert((size_t) num < ncolumns);
195 assert(columns[num] < (int) ARRAY_SIZE(infos));
196
197 return columns[num];
198 }
199
200 static inline const struct colinfo *get_column_info(unsigned num)
201 {
202 return &infos[ get_column_id(num) ];
203 }
204
205 static int get_ns_ino(int dir, const char *nsname, ino_t *ino)
206 {
207 struct stat st;
208 char path[16];
209
210 snprintf(path, sizeof(path), "ns/%s", nsname);
211
212 if (fstatat(dir, path, &st, 0) != 0)
213 return -errno;
214 *ino = st.st_ino;
215 return 0;
216 }
217
218
219 static int read_process(struct lsns *ls, pid_t pid)
220 {
221 struct lsns_process *p = NULL;
222 char buf[BUFSIZ];
223 DIR *dir;
224 int rc = 0, fd;
225 FILE *f = NULL;
226 size_t i;
227 struct stat st;
228
229 DBG(PROC, ul_debug("reading %d", (int) pid));
230
231 snprintf(buf, sizeof(buf), "/proc/%d", pid);
232 dir = opendir(buf);
233 if (!dir)
234 return -errno;
235
236 p = xcalloc(1, sizeof(*p));
237 if (!p) {
238 rc = -ENOMEM;
239 goto done;
240 }
241
242 if (fstat(dirfd(dir), &st) == 0) {
243 p->uid = st.st_uid;
244 add_uid(uid_cache, st.st_uid);
245 }
246
247 fd = openat(dirfd(dir), "stat", O_RDONLY);
248 if (fd < 0) {
249 rc = -errno;
250 goto done;
251 }
252 if (!(f = fdopen(fd, "r"))) {
253 rc = -errno;
254 goto done;
255 }
256 rc = fscanf(f, "%d %*s %c %d*[^\n]", &p->pid, &p->state, &p->ppid);
257 if (rc != 3) {
258 rc = rc < 0 ? -errno : -EINVAL;
259 goto done;
260 }
261 rc = 0;
262
263 for (i = 0; i < ARRAY_SIZE(p->ns_ids); i++) {
264 INIT_LIST_HEAD(&p->ns_siblings[i]);
265
266 if (!ls->fltr_types[i])
267 continue;
268
269 rc = get_ns_ino(dirfd(dir), ns_names[i], &p->ns_ids[i]);
270 if (rc && rc != -EACCES && rc != -ENOENT)
271 goto done;
272 rc = 0;
273 }
274
275 INIT_LIST_HEAD(&p->processes);
276
277 DBG(PROC, ul_debugobj(p, "new pid=%d", p->pid));
278 list_add_tail(&p->processes, &ls->processes);
279 done:
280 if (f)
281 fclose(f);
282 closedir(dir);
283 if (rc)
284 free(p);
285 return rc;
286 }
287
288 static int read_processes(struct lsns *ls)
289 {
290 struct proc_processes *proc = NULL;
291 pid_t pid;
292 int rc = 0;
293
294 DBG(PROC, ul_debug("opening /proc"));
295
296 if (!(proc = proc_open_processes())) {
297 rc = -errno;
298 goto done;
299 }
300
301 while (proc_next_pid(proc, &pid) == 0) {
302 rc = read_process(ls, pid);
303 if (rc && rc != -EACCES && rc != -ENOENT)
304 break;
305 rc = 0;
306 }
307 done:
308 DBG(PROC, ul_debug("closing /proc"));
309 proc_close_processes(proc);
310 return rc;
311 }
312
313 static struct lsns_namespace *get_namespace(struct lsns *ls, ino_t ino)
314 {
315 struct list_head *p;
316
317 list_for_each(p, &ls->namespaces) {
318 struct lsns_namespace *ns = list_entry(p, struct lsns_namespace, namespaces);
319
320 if (ns->id == ino)
321 return ns;
322 }
323 return NULL;
324 }
325
326 static int namespace_has_process(struct lsns_namespace *ns, pid_t pid)
327 {
328 struct list_head *p;
329
330 list_for_each(p, &ns->processes) {
331 struct lsns_process *proc = list_entry(p, struct lsns_process, ns_siblings[ns->type]);
332
333 if (proc->pid == pid)
334 return 1;
335 }
336 return 0;
337 }
338
339 static struct lsns_namespace *add_namespace(struct lsns *ls, int type, ino_t ino)
340 {
341 struct lsns_namespace *ns = xcalloc(1, sizeof(*ns));
342
343 if (!ns)
344 return NULL;
345
346 DBG(NS, ul_debugobj(ns, "new %s[%ju]", ns_names[type], (uintmax_t)ino));
347
348 INIT_LIST_HEAD(&ns->processes);
349 INIT_LIST_HEAD(&ns->namespaces);
350
351 ns->type = type;
352 ns->id = ino;
353
354 list_add_tail(&ns->namespaces, &ls->namespaces);
355 return ns;
356 }
357
358 static int add_process_to_namespace(struct lsns *ls, struct lsns_namespace *ns, struct lsns_process *proc)
359 {
360 struct list_head *p;
361
362 DBG(NS, ul_debugobj(ns, "add process [%p] pid=%d to %s[%ju]",
363 proc, proc->pid, ns_names[ns->type], (uintmax_t)ns->id));
364
365 list_for_each(p, &ls->processes) {
366 struct lsns_process *xproc = list_entry(p, struct lsns_process, processes);
367
368 if (xproc->pid == proc->ppid) /* my parent */
369 proc->parent = xproc;
370 else if (xproc->ppid == proc->pid) /* my child */
371 xproc->parent = proc;
372 }
373
374 list_add_tail(&proc->ns_siblings[ns->type], &ns->processes);
375 ns->nprocs++;
376
377 if (!ns->proc || ns->proc->pid > proc->pid)
378 ns->proc = proc;
379
380 return 0;
381 }
382
383 static int cmp_namespaces(struct list_head *a, struct list_head *b,
384 __attribute__((__unused__)) void *data)
385 {
386 struct lsns_namespace *xa = list_entry(a, struct lsns_namespace, namespaces),
387 *xb = list_entry(b, struct lsns_namespace, namespaces);
388
389 return cmp_numbers(xa->id, xb->id);
390 }
391
392 static int read_namespaces(struct lsns *ls)
393 {
394 struct list_head *p;
395
396 DBG(NS, ul_debug("reading namespace"));
397
398 list_for_each(p, &ls->processes) {
399 size_t i;
400 struct lsns_namespace *ns;
401 struct lsns_process *proc = list_entry(p, struct lsns_process, processes);
402
403 for (i = 0; i < ARRAY_SIZE(proc->ns_ids); i++) {
404 if (proc->ns_ids[i] == 0)
405 continue;
406 if (!(ns = get_namespace(ls, proc->ns_ids[i]))) {
407 ns = add_namespace(ls, i, proc->ns_ids[i]);
408 if (!ns)
409 return -ENOMEM;
410 }
411 add_process_to_namespace(ls, ns, proc);
412 }
413 }
414
415 list_sort(&ls->namespaces, cmp_namespaces, NULL);
416
417 return 0;
418 }
419
420 static void add_scols_line(struct lsns *ls, struct libscols_table *table,
421 struct lsns_namespace *ns, struct lsns_process *proc)
422 {
423 size_t i;
424 struct libscols_line *line;
425
426 assert(ns);
427 assert(table);
428
429 line = scols_table_new_line(table,
430 ls->tree && proc->parent ? proc->parent->outline : NULL);
431 if (!line) {
432 warn(_("failed to add line to output"));
433 return;
434 }
435
436 for (i = 0; i < ncolumns; i++) {
437 char *str = NULL;
438
439 switch (get_column_id(i)) {
440 case COL_NS:
441 xasprintf(&str, "%ju", (uintmax_t)ns->id);
442 break;
443 case COL_PID:
444 xasprintf(&str, "%d", (int) proc->pid);
445 break;
446 case COL_PPID:
447 xasprintf(&str, "%d", (int) proc->ppid);
448 break;
449 case COL_TYPE:
450 xasprintf(&str, "%s", ns_names[ns->type]);
451 break;
452 case COL_NPROCS:
453 xasprintf(&str, "%d", ns->nprocs);
454 break;
455 case COL_COMMAND:
456 str = proc_get_command(proc->pid);
457 if (!str)
458 str = proc_get_command_name(proc->pid);
459 break;
460 case COL_PATH:
461 xasprintf(&str, "/proc/%d/ns/%s", (int) proc->pid, ns_names[ns->type]);
462 break;
463 case COL_UID:
464 xasprintf(&str, "%d", (int) proc->uid);
465 break;
466 case COL_USER:
467 xasprintf(&str, "%s", get_id(uid_cache, proc->uid)->name);
468 break;
469 default:
470 break;
471 }
472
473 if (str && scols_line_set_data(line, i, str) != 0)
474 err_oom();
475 }
476
477 proc->outline = line;
478 }
479
480 static struct libscols_table *init_scols_table(struct lsns *ls)
481 {
482 struct libscols_table *tab;
483 size_t i;
484
485 tab = scols_new_table();
486 if (!tab) {
487 warn(_("failed to initialize output table"));
488 return NULL;
489 }
490
491 scols_table_enable_raw(tab, ls->raw);
492 scols_table_enable_json(tab, ls->json);
493 scols_table_enable_noheadings(tab, ls->no_headings);
494
495 if (ls->json)
496 scols_table_set_name(tab, "namespaces");
497
498 for (i = 0; i < ncolumns; i++) {
499 const struct colinfo *col = get_column_info(i);
500 int flags = col->flags;
501
502 if (ls->notrunc)
503 flags &= ~SCOLS_FL_TRUNC;
504 if (ls->tree && get_column_id(i) == COL_COMMAND)
505 flags |= SCOLS_FL_TREE;
506
507 if (!scols_table_new_column(tab, col->name, col->whint, flags)) {
508 warnx(_("failed to initialize output column"));
509 goto err;
510 }
511 }
512
513 return tab;
514 err:
515 scols_unref_table(tab);
516 return NULL;
517 }
518
519 static int show_namespaces(struct lsns *ls)
520 {
521 struct libscols_table *tab;
522 struct list_head *p;
523 int rc = 0;
524
525 tab = init_scols_table(ls);
526 if (!tab)
527 return -ENOMEM;
528
529 list_for_each(p, &ls->namespaces) {
530 struct lsns_namespace *ns = list_entry(p, struct lsns_namespace, namespaces);
531
532 if (ls->fltr_pid != 0 && !namespace_has_process(ns, ls->fltr_pid))
533 continue;
534
535 add_scols_line(ls, tab, ns, ns->proc);
536 }
537
538 scols_print_table(tab);
539 scols_unref_table(tab);
540 return rc;
541 }
542
543 static void show_process(struct lsns *ls, struct libscols_table *tab,
544 struct lsns_process *proc, struct lsns_namespace *ns)
545 {
546 /*
547 * create a tree from parent->child relation, but only if the parent is
548 * within the same namespace
549 */
550 if (ls->tree
551 && proc->parent
552 && !proc->parent->outline
553 && proc->parent->ns_ids[ns->type] == proc->ns_ids[ns->type])
554 show_process(ls, tab, proc->parent, ns);
555
556 add_scols_line(ls, tab, ns, proc);
557 }
558
559
560 static int show_namespace_processes(struct lsns *ls, struct lsns_namespace *ns)
561 {
562 struct libscols_table *tab;
563 struct list_head *p;
564
565 tab = init_scols_table(ls);
566 if (!tab)
567 return -ENOMEM;
568
569 list_for_each(p, &ns->processes) {
570 struct lsns_process *proc = list_entry(p, struct lsns_process, ns_siblings[ns->type]);
571
572 if (!proc->outline)
573 show_process(ls, tab, proc, ns);
574 }
575
576
577 scols_print_table(tab);
578 scols_unref_table(tab);
579 return 0;
580 }
581
582 static void __attribute__ ((__noreturn__)) usage(FILE * out)
583 {
584 size_t i;
585
586 fputs(USAGE_HEADER, out);
587
588 fprintf(out,
589 _(" %s [options] [<namespace>]\n"), program_invocation_short_name);
590
591 fputs(USAGE_SEPARATOR, out);
592 fputs(_("List system namespaces.\n"), out);
593
594 fputs(USAGE_OPTIONS, out);
595 fputs(_(" -J, --json use JSON output format\n"), out);
596 fputs(_(" -l, --list use list format output\n"), out);
597 fputs(_(" -n, --noheadings don't print headings\n"), out);
598 fputs(_(" -o, --output <list> define which output columns to use\n"), out);
599 fputs(_(" -p, --task <pid> print process namespaces\n"), out);
600 fputs(_(" -r, --raw use the raw output format\n"), out);
601 fputs(_(" -u, --notruncate don't truncate text in columns\n"), out);
602 fputs(_(" -t, --type <name> namespace type (mnt, net, ipc, user, pid, uts)\n"), out);
603
604 fputs(USAGE_SEPARATOR, out);
605 fputs(USAGE_HELP, out);
606 fputs(USAGE_VERSION, out);
607
608 fputs(_("\nAvailable columns (for --output):\n"), out);
609
610 for (i = 0; i < ARRAY_SIZE(infos); i++)
611 fprintf(out, " %11s %s\n", infos[i].name, _(infos[i].help));
612
613 fprintf(out, USAGE_MAN_TAIL("lsns(8)"));
614
615 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
616 }
617
618
619 int main(int argc, char *argv[])
620 {
621 struct lsns ls;
622 int c;
623 int r = 0;
624 char *outarg = NULL;
625 static const struct option long_opts[] = {
626 { "json", no_argument, NULL, 'J' },
627 { "task", required_argument, NULL, 'p' },
628 { "help", no_argument, NULL, 'h' },
629 { "output", required_argument, NULL, 'o' },
630 { "notruncate", no_argument, NULL, 'u' },
631 { "version", no_argument, NULL, 'V' },
632 { "noheadings", no_argument, NULL, 'n' },
633 { "list", no_argument, NULL, 'l' },
634 { "raw", no_argument, NULL, 'r' },
635 { "type", required_argument, NULL, 't' },
636 { NULL, 0, NULL, 0 }
637 };
638
639 static const ul_excl_t excl[] = { /* rows and cols in ASCII order */
640 { 'J','r' },
641 { 0 }
642 };
643 int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
644
645 setlocale(LC_ALL, "");
646 bindtextdomain(PACKAGE, LOCALEDIR);
647 textdomain(PACKAGE);
648 atexit(close_stdout);
649
650 lsns_init_debug();
651 memset(&ls, 0, sizeof(ls));
652
653 INIT_LIST_HEAD(&ls.processes);
654 INIT_LIST_HEAD(&ls.namespaces);
655
656 while ((c = getopt_long(argc, argv,
657 "Jlp:o:nruhVt:", long_opts, NULL)) != -1) {
658
659 err_exclusive_options(c, long_opts, excl, excl_st);
660
661 switch(c) {
662 case 'J':
663 ls.json = 1;
664 break;
665 case 'l':
666 ls.list = 1;
667 break;
668 case 'o':
669 outarg = optarg;
670 break;
671 case 'V':
672 printf(UTIL_LINUX_VERSION);
673 return EXIT_SUCCESS;
674 case 'p':
675 ls.fltr_pid = strtos32_or_err(optarg, _("invalid PID argument"));
676 break;
677 case 'h':
678 usage(stdout);
679 case 'n':
680 ls.no_headings = 1;
681 break;
682 case 'r':
683 ls.raw = 1;
684 break;
685 case 'u':
686 ls.notrunc = 1;
687 break;
688 case 't':
689 {
690 int type = ns_name2type(optarg);
691 if (type < 0)
692 errx(EXIT_FAILURE, _("unknown namespace type: %s"), optarg);
693 ls.fltr_types[type] = 1;
694 ls.fltr_ntypes++;
695 break;
696 }
697 case '?':
698 default:
699 usage(stderr);
700 }
701 }
702
703 if (!ls.fltr_ntypes) {
704 size_t i;
705 for (i = 0; i < ARRAY_SIZE(ns_names); i++)
706 ls.fltr_types[i] = 1;
707 }
708
709 if (optind < argc) {
710 if (ls.fltr_pid)
711 errx(EXIT_FAILURE, _("--task is mutually exclusive with <namespace>"));
712 ls.fltr_ns = strtou64_or_err(argv[optind], _("invalid namespace argument"));
713 ls.tree = ls.list ? 0 : 1;
714
715 if (!ncolumns) {
716 columns[ncolumns++] = COL_PID;
717 columns[ncolumns++] = COL_PPID;
718 columns[ncolumns++] = COL_USER;
719 columns[ncolumns++] = COL_COMMAND;
720 }
721 }
722
723 if (!ncolumns) {
724 columns[ncolumns++] = COL_NS;
725 columns[ncolumns++] = COL_TYPE;
726 columns[ncolumns++] = COL_NPROCS;
727 columns[ncolumns++] = COL_PID;
728 columns[ncolumns++] = COL_USER;
729 columns[ncolumns++] = COL_COMMAND;
730 }
731
732 if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
733 &ncolumns, column_name_to_id) < 0)
734 return EXIT_FAILURE;
735
736 scols_init_debug(0);
737
738 uid_cache = new_idcache();
739 if (!uid_cache)
740 err(EXIT_FAILURE, _("failed to allocate UID cache"));
741
742 r = read_processes(&ls);
743 if (!r)
744 r = read_namespaces(&ls);
745 if (!r) {
746 if (ls.fltr_ns) {
747 struct lsns_namespace *ns = get_namespace(&ls, ls.fltr_ns);
748
749 if (!ns)
750 errx(EXIT_FAILURE, _("not found namespace: %ju"), (uintmax_t) ls.fltr_ns);
751 r = show_namespace_processes(&ls, ns);
752 } else
753 r = show_namespaces(&ls);
754 }
755
756 free_idcache(uid_cache);
757 return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
758 }