diff options
Diffstat (limited to 'src/libsystemd-bus/busctl.c')
-rw-r--r-- | src/libsystemd-bus/busctl.c | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c index 88446fcc7c..7348894c5b 100644 --- a/src/libsystemd-bus/busctl.c +++ b/src/libsystemd-bus/busctl.c @@ -19,15 +19,22 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "strv.h" +#include "util.h" +#include "log.h" + #include "sd-bus.h" +#include "bus-message.h" +#include "bus-internal.h" int main(int argc, char *argv[]) { _cleanup_bus_unref_ sd_bus *bus = NULL; _cleanup_strv_free_ char **l = NULL; char **i; int r; + size_t max_i = 0; - r = bus_open_system(&bus); + r = sd_bus_open_user(&bus); if (r < 0) { log_error("Failed to connect to bus: %s", strerror(-r)); goto fail; @@ -39,26 +46,57 @@ int main(int argc, char *argv[]) { goto fail; } + strv_sort(l); + + STRV_FOREACH(i, l) + max_i = MAX(max_i, strlen(*i)); + + printf("%-*s %*s %-*s %-*s CONNECTION\n", + (int) max_i, "NAME", 10, "PID", 15, "PROCESS", 16, "USER"); + STRV_FOREACH(i, l) { _cleanup_free_ char *owner = NULL; - pid_t pid = 0; + pid_t pid; uid_t uid; - bool uid_valid; - r = sd_bus_get_owner(bus, *i, &owner); - if (r == -ENXIO) - continue; + /* if ((*i)[0] == ':') */ + /* continue; */ + + printf("%-*s", (int) max_i, *i); - r = sd_get_owner_pid(bus, *i, &pid); - if (r == -ENXIO) - continue; + r = sd_bus_get_owner_pid(bus, *i, &pid); + if (r >= 0) { + _cleanup_free_ char *comm = NULL; - r = sd_get_owner_uid(bus, *i, &pid); - if (r == -ENXIO) - continue; - uid_valid = r >= 0; + printf(" %10lu", (unsigned long) pid); - printf("%s (%s) %llu %llu\n", *i, owner, (unsigned long long) pid, (unsigned long long) uid); + get_process_comm(pid, &comm); + printf(" %-15s", strna(comm)); + } else + printf(" - - "); + + r = sd_bus_get_owner_uid(bus, *i, &uid); + if (r >= 0) { + _cleanup_free_ char *u = NULL; + + u = uid_to_name(uid); + if (!u) { + log_oom(); + goto fail; + } + + if (strlen(u) > 16) + u[16] = 0; + + printf(" %-16s", u); + } else + printf(" - "); + + r = sd_bus_get_owner(bus, *i, &owner); + if (r >= 0) + printf(" %s\n", owner); + else + printf(" -\n"); } r = 0; |