From 266f3e269d173f104aa2a5e3ceac9b6979ea5039 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Sep 2015 13:30:10 +0200 Subject: bus-util: rename bus_open_transport() to bus_connect_transport() In sd-bus, the sd_bus_open_xyz() family of calls allocates a new bus, while sd_bus_default_xyz() family tries to reuse the thread's default bus. bus_open_transport() sometimes internally uses the former, sometimes the latter family, but suggests it only calls the former via its name. Hence, let's avoid this confusion, and generically rename the call to bus_connect_transport(). Similar for all related calls. And while we are at it, also change cgls + cgtop to do direct systemd connections where possible, since all they do is talk to systemd itself. --- src/update-utmp/update-utmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/update-utmp/update-utmp.c') diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index b2998dce43..8dbce27242 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) { if (c.audit_fd < 0 && errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT) log_error_errno(errno, "Failed to connect to audit log: %m"); #endif - r = bus_open_system_systemd(&c.bus); + r = bus_connect_system_systemd(&c.bus); if (r < 0) { log_error_errno(r, "Failed to get D-Bus connection: %m"); r = -EIO; -- cgit v1.2.3-54-g00ecf From f0960da0fa564c6cf762ba907040d15c9db1bdba Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Sep 2015 13:33:55 +0200 Subject: update-utmp: minor modernizations --- src/update-utmp/update-utmp.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/update-utmp/update-utmp.c') diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index 8dbce27242..22ef79165a 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -62,7 +62,7 @@ static usec_t get_startup_time(Context *c) { &error, 't', &t); if (r < 0) { - log_error("Failed to get timestamp: %s", bus_error_message(&error, -r)); + log_error_errno(r, "Failed to get timestamp: %s", bus_error_message(&error, r)); return 0; } @@ -105,10 +105,8 @@ static int get_current_runlevel(Context *c) { "ActiveState", &error, &state); - if (r < 0) { - log_warning("Failed to get state: %s", bus_error_message(&error, -r)); - return r; - } + if (r < 0) + return log_warning_errno(r, "Failed to get state: %s", bus_error_message(&error, r)); if (streq(state, "active") || streq(state, "reloading")) return table[i].runlevel; @@ -130,8 +128,7 @@ static int on_reboot(Context *c) { if (c->audit_fd >= 0) if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) { - r = log_error_errno(errno, - "Failed to send audit message: %m"); + r = log_error_errno(errno, "Failed to send audit message: %m"); } #endif @@ -160,8 +157,7 @@ static int on_shutdown(Context *c) { if (c->audit_fd >= 0) if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) { - r = log_error_errno(errno, - "Failed to send audit message: %m"); + r = log_error_errno(errno, "Failed to send audit message: %m"); } #endif @@ -211,8 +207,7 @@ static int on_runlevel(Context *c) { return log_oom(); if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && errno != EPERM) - r = log_error_errno(errno, - "Failed to send audit message: %m"); + r = log_error_errno(errno, "Failed to send audit message: %m"); } #endif -- cgit v1.2.3-54-g00ecf From f0792aae430562a59f95d8ec3d9773cbeb032f43 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Sep 2015 13:34:08 +0200 Subject: update-utmp: flush and close the bus used for connections after use --- src/update-utmp/update-utmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/update-utmp/update-utmp.c') diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index 22ef79165a..bcabf65a36 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -279,6 +279,6 @@ finish: audit_close(c.audit_fd); #endif - sd_bus_unref(c.bus); + sd_bus_flush_close_unref(c.bus); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf