]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-bus/busctl.c
do not create /dev/rtc symlink, let systemd search for it if needed
[thirdparty/systemd.git] / src / libsystemd-bus / busctl.c
CommitLineData
de1c301e
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
89ffcd2a
LP
22#include "strv.h"
23#include "util.h"
24#include "log.h"
25
de1c301e 26#include "sd-bus.h"
89ffcd2a
LP
27#include "bus-message.h"
28#include "bus-internal.h"
de1c301e
LP
29
30int main(int argc, char *argv[]) {
31 _cleanup_bus_unref_ sd_bus *bus = NULL;
32 _cleanup_strv_free_ char **l = NULL;
33 char **i;
34 int r;
89ffcd2a 35 size_t max_i = 0;
de1c301e 36
89ffcd2a 37 r = sd_bus_open_user(&bus);
de1c301e
LP
38 if (r < 0) {
39 log_error("Failed to connect to bus: %s", strerror(-r));
40 goto fail;
41 }
42
43 r = sd_bus_list_names(bus, &l);
44 if (r < 0) {
45 log_error("Failed to list names: %s", strerror(-r));
46 goto fail;
47 }
48
89ffcd2a
LP
49 strv_sort(l);
50
51 STRV_FOREACH(i, l)
52 max_i = MAX(max_i, strlen(*i));
53
54 printf("%-*s %*s %-*s %-*s CONNECTION\n",
55 (int) max_i, "NAME", 10, "PID", 15, "PROCESS", 16, "USER");
56
de1c301e
LP
57 STRV_FOREACH(i, l) {
58 _cleanup_free_ char *owner = NULL;
89ffcd2a 59 pid_t pid;
de1c301e 60 uid_t uid;
de1c301e 61
89ffcd2a
LP
62 /* if ((*i)[0] == ':') */
63 /* continue; */
64
65 printf("%-*s", (int) max_i, *i);
de1c301e 66
89ffcd2a
LP
67 r = sd_bus_get_owner_pid(bus, *i, &pid);
68 if (r >= 0) {
69 _cleanup_free_ char *comm = NULL;
de1c301e 70
89ffcd2a 71 printf(" %10lu", (unsigned long) pid);
de1c301e 72
89ffcd2a
LP
73 get_process_comm(pid, &comm);
74 printf(" %-15s", strna(comm));
75 } else
76 printf(" - - ");
77
78 r = sd_bus_get_owner_uid(bus, *i, &uid);
79 if (r >= 0) {
80 _cleanup_free_ char *u = NULL;
81
82 u = uid_to_name(uid);
83 if (!u) {
84 log_oom();
85 goto fail;
86 }
87
88 if (strlen(u) > 16)
89 u[16] = 0;
90
91 printf(" %-16s", u);
92 } else
93 printf(" - ");
94
95 r = sd_bus_get_owner(bus, *i, &owner);
96 if (r >= 0)
97 printf(" %s\n", owner);
98 else
99 printf(" -\n");
de1c301e
LP
100 }
101
102 r = 0;
103
104fail:
105 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
106}