diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-08-04 16:22:09 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-08-04 16:25:24 +0200 |
commit | 249968612f16a71df909d6e73785c18a9ff36a65 (patch) | |
tree | 858e6d966f4da7ef38c011fb1e1c4acd477219a8 /src | |
parent | ef392da6c56cdfff35265403192f051af257b3f8 (diff) |
bus: always explicitly close bus from main programs
Since b5eca3a2059f9399d1dc52cbcf9698674c4b1cf0 we don't attempt to GC
busses anymore when unsent messages remain that keep their reference,
when they otherwise are not referenced anymore. This means that if we
explicitly want connections to go away, we need to close them.
With this change we will no do so explicitly wherver we connect to the
bus from a main program (and thus know when the bus connection should go
away), or when we create a private bus connection, that really should go
away after our use.
This fixes connection leaks in the NSS and PAM modules.
Diffstat (limited to 'src')
-rw-r--r-- | src/analyze/analyze.c | 2 | ||||
-rw-r--r-- | src/bus-proxyd/bus-proxyd.c | 7 | ||||
-rw-r--r-- | src/cgls/cgls.c | 2 | ||||
-rw-r--r-- | src/cgroups-agent/cgroups-agent.c | 4 | ||||
-rw-r--r-- | src/fsck/fsck.c | 2 | ||||
-rw-r--r-- | src/hostname/hostnamectl.c | 2 | ||||
-rw-r--r-- | src/hostname/hostnamed.c | 5 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-util.h | 9 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/busctl.c | 2 | ||||
-rw-r--r-- | src/locale/localectl.c | 2 | ||||
-rw-r--r-- | src/locale/localed.c | 4 | ||||
-rw-r--r-- | src/login/inhibit.c | 2 | ||||
-rw-r--r-- | src/login/loginctl.c | 2 | ||||
-rw-r--r-- | src/login/pam_systemd.c | 4 | ||||
-rw-r--r-- | src/machine/machinectl.c | 4 | ||||
-rw-r--r-- | src/nspawn/nspawn.c | 4 | ||||
-rw-r--r-- | src/nss-mymachines/nss-mymachines.c | 4 | ||||
-rw-r--r-- | src/nss-resolve/nss-resolve.c | 6 | ||||
-rw-r--r-- | src/resolve-host/resolve-host.c | 2 | ||||
-rw-r--r-- | src/run/run.c | 2 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 6 | ||||
-rw-r--r-- | src/timedate/timedatectl.c | 2 | ||||
-rw-r--r-- | src/timedate/timedated.c | 4 |
23 files changed, 42 insertions, 41 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index d0bf01468a..fdbce7cda8 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1346,7 +1346,7 @@ int main(int argc, char *argv[]) { arg_user ? SYSTEMD_USER : SYSTEMD_SYSTEM, arg_man); else { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; r = bus_open_transport_systemd(arg_transport, arg_host, arg_user, &bus); if (r < 0) { diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c index e5713d6af9..4f24e331ec 100644 --- a/src/bus-proxyd/bus-proxyd.c +++ b/src/bus-proxyd/bus-proxyd.c @@ -1090,7 +1090,7 @@ static int patch_sender(sd_bus *a, sd_bus_message *m) { int main(int argc, char *argv[]) { - _cleanup_bus_unref_ sd_bus *a = NULL, *b = NULL; + _cleanup_bus_close_unref_ sd_bus *a = NULL, *b = NULL; sd_id128_t server_id; int r, in_fd, out_fd; bool got_hello = false; @@ -1474,11 +1474,6 @@ int main(int argc, char *argv[]) { } finish: - sd_bus_flush(a); - sd_bus_flush(b); - sd_bus_close(a); - sd_bus_close(b); - policy_free(&policy); strv_free(arg_configuration); free(arg_address); diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c index 6e9bd232a9..7070503d68 100644 --- a/src/cgls/cgls.c +++ b/src/cgls/cgls.c @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) { int r = 0, retval = EXIT_FAILURE; int output_flags; _cleanup_free_ char *root = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; log_parse_environment(); log_open(); diff --git a/src/cgroups-agent/cgroups-agent.c b/src/cgroups-agent/cgroups-agent.c index d1d843bda7..e581fbc9b6 100644 --- a/src/cgroups-agent/cgroups-agent.c +++ b/src/cgroups-agent/cgroups-agent.c @@ -26,7 +26,7 @@ #include "bus-util.h" int main(int argc, char *argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; if (argc != 2) { @@ -62,7 +62,5 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - sd_bus_flush(bus); - return EXIT_SUCCESS; } diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index e8596d90f8..dfe97bc260 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -47,7 +47,7 @@ static const char *arg_repair = "-a"; static void start_target(const char *target) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; assert(target); diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 69da54f1f3..f8e1a811f8 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -497,7 +497,7 @@ static int hostnamectl_main(sd_bus *bus, int argc, char *argv[]) { } int main(int argc, char *argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 74d9dab073..4acdb72b12 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -634,7 +634,7 @@ static const sd_bus_vtable hostname_vtable[] = { }; static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; assert(c); @@ -673,9 +673,8 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { int main(int argc, char *argv[]) { Context context = {}; - _cleanup_event_unref_ sd_event *event = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; log_set_target(LOG_TARGET_AUTO); diff --git a/src/libsystemd/sd-bus/bus-util.h b/src/libsystemd/sd-bus/bus-util.h index 0a3d5dd567..af50553926 100644 --- a/src/libsystemd/sd-bus/bus-util.h +++ b/src/libsystemd/sd-bus/bus-util.h @@ -137,6 +137,14 @@ typedef struct UnitInfo { int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u); +static inline void sd_bus_close_unrefp(sd_bus **bus) { + if (*bus) { + sd_bus_flush(*bus); + sd_bus_close(*bus); + sd_bus_unref(*bus); + } +} + DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_slot*, sd_bus_slot_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref); @@ -144,6 +152,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_creds*, sd_bus_creds_unref); DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_track*, sd_bus_track_unref); #define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp) +#define _cleanup_bus_close_unref_ _cleanup_(sd_bus_close_unrefp) #define _cleanup_bus_slot_unref_ _cleanup_(sd_bus_slot_unrefp) #define _cleanup_bus_message_unref_ _cleanup_(sd_bus_message_unrefp) #define _cleanup_bus_creds_unref_ _cleanup_(sd_bus_creds_unrefp) diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c index b6839c13e7..af71804410 100644 --- a/src/libsystemd/sd-bus/busctl.c +++ b/src/libsystemd/sd-bus/busctl.c @@ -482,7 +482,7 @@ static int busctl_main(sd_bus *bus, int argc, char *argv[]) { } int main(int argc, char *argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; log_parse_environment(); diff --git a/src/locale/localectl.c b/src/locale/localectl.c index 69d50076aa..2bb0d3b6be 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -621,7 +621,7 @@ static int localectl_main(sd_bus *bus, int argc, char *argv[]) { } int main(int argc, char*argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); diff --git a/src/locale/localed.c b/src/locale/localed.c index bce99b8cba..3cfc2ea4d3 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -1079,7 +1079,7 @@ static const sd_bus_vtable locale_vtable[] = { }; static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; assert(c); @@ -1119,7 +1119,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { int main(int argc, char *argv[]) { Context context = {}; _cleanup_event_unref_ sd_event *event = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; log_set_target(LOG_TARGET_AUTO); diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 02b6b25751..d5ea1d913c 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -218,7 +218,7 @@ static int parse_argv(int argc, char *argv[]) { int main(int argc, char *argv[]) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; log_parse_environment(); diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 1773276b95..fcdf6275e9 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -1295,7 +1295,7 @@ static int loginctl_main(sd_bus *bus, int argc, char *argv[]) { } int main(int argc, char *argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index f522d6ec4f..0c71177deb 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -213,7 +213,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( *seat = NULL, *type = NULL, *class = NULL, *class_pam = NULL, *type_pam = NULL, *cvtnr = NULL, *desktop = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int session_fd = -1, existing, r; bool debug = false, remote; struct passwd *pw; @@ -496,7 +496,7 @@ _public_ PAM_EXTERN int pam_sm_close_session( int argc, const char **argv) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; const void *existing = NULL; const char *id; int r; diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 02d5d301c0..7491d69c8b 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -661,7 +661,7 @@ static int openpt_in_namespace(pid_t pid, int flags) { static int login_machine(sd_bus *bus, char **args, unsigned n) { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *reply2 = NULL, *reply3 = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_unref_ sd_bus *container_bus = NULL; + _cleanup_bus_close_unref_ sd_bus *container_bus = NULL; _cleanup_close_ int master = -1; _cleanup_free_ char *getty = NULL; const char *path, *pty, *p; @@ -989,7 +989,7 @@ static int machinectl_main(sd_bus *bus, int argc, char *argv[]) { } int main(int argc, char*argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 76e86b7e05..ae09f936f5 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -1386,7 +1386,7 @@ static int drop_capabilities(void) { static int register_machine(pid_t pid, int local_ifindex) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; if (!arg_register) @@ -1521,7 +1521,7 @@ static int register_machine(pid_t pid, int local_ifindex) { static int terminate_machine(pid_t pid) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; const char *path; int r; diff --git a/src/nss-mymachines/nss-mymachines.c b/src/nss-mymachines/nss-mymachines.c index cc185b0c3d..c87f436aea 100644 --- a/src/nss-mymachines/nss-mymachines.c +++ b/src/nss-mymachines/nss-mymachines.c @@ -79,7 +79,7 @@ enum nss_status _nss_mymachines_gethostbyname4_r( struct gaih_addrtuple *r_tuple, *r_tuple_first = NULL; _cleanup_bus_message_unref_ sd_bus_message* reply = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; _cleanup_free_ int *ifindices = NULL; _cleanup_free_ char *class = NULL; size_t l, ms, idx; @@ -228,7 +228,7 @@ enum nss_status _nss_mymachines_gethostbyname3_r( char **canonp) { _cleanup_bus_message_unref_ sd_bus_message* reply = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; _cleanup_free_ char *class = NULL; unsigned c = 0, i = 0; char *r_name, *r_aliases, *r_addr, *r_addr_list; diff --git a/src/nss-resolve/nss-resolve.c b/src/nss-resolve/nss-resolve.c index 555800c10a..ccbc7317f6 100644 --- a/src/nss-resolve/nss-resolve.c +++ b/src/nss-resolve/nss-resolve.c @@ -123,7 +123,7 @@ enum nss_status _nss_resolve_gethostbyname4_r( _cleanup_bus_message_unref_ sd_bus_message *req = NULL, *reply = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; struct gaih_addrtuple *r_tuple, *r_tuple_first = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; const char *canonical = NULL; size_t l, ms, idx; char *r_name; @@ -306,7 +306,7 @@ enum nss_status _nss_resolve_gethostbyname3_r( _cleanup_bus_message_unref_ sd_bus_message *req = NULL, *reply = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; char *r_name, *r_aliases, *r_addr, *r_addr_list; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; size_t l, idx, ms, alen; const char *canonical; int c, r, i = 0; @@ -517,7 +517,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r( _cleanup_bus_message_unref_ sd_bus_message *req = NULL, *reply = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; char *r_name, *r_aliases, *r_addr, *r_addr_list; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; unsigned c = 0, i = 0; size_t ms = 0, idx; const char *n; diff --git a/src/resolve-host/resolve-host.c b/src/resolve-host/resolve-host.c index 43c8a229eb..3641923e1c 100644 --- a/src/resolve-host/resolve-host.c +++ b/src/resolve-host/resolve-host.c @@ -529,7 +529,7 @@ static int parse_argv(int argc, char *argv[]) { } int main(int argc, char **argv) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; log_parse_environment(); diff --git a/src/run/run.c b/src/run/run.c index f8f0ea2832..e3b62939c7 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -562,7 +562,7 @@ static int start_transient_scope( int main(int argc, char* argv[]) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; _cleanup_free_ char *description = NULL, *command = NULL; int r; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index daf7e31de9..540b4a64c1 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -617,7 +617,7 @@ static int get_unit_list_recursive( return r; STRV_FOREACH(i, machines) { - _cleanup_bus_unref_ sd_bus *container = NULL; + _cleanup_bus_close_unref_ sd_bus *container = NULL; int k; r = sd_bus_open_system_container(&container, *i); @@ -1688,7 +1688,7 @@ static int compare_machine_info(const void *a, const void *b) { } static int get_machine_properties(sd_bus *bus, struct machine_info *mi) { - _cleanup_bus_unref_ sd_bus *container = NULL; + _cleanup_bus_close_unref_ sd_bus *container = NULL; int r; assert(mi); @@ -6828,7 +6828,7 @@ static int runlevel_main(void) { } int main(int argc, char*argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c index 36c3f3cfcd..0ba32d31c4 100644 --- a/src/timedate/timedatectl.c +++ b/src/timedate/timedatectl.c @@ -545,7 +545,7 @@ static int timedatectl_main(sd_bus *bus, int argc, char *argv[]) { } int main(int argc, char *argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 936a902be6..791e2b436f 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -641,7 +641,7 @@ static const sd_bus_vtable timedate_vtable[] = { }; static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; assert(c); @@ -681,7 +681,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { int main(int argc, char *argv[]) { Context context = {}; _cleanup_event_unref_ sd_event *event = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; log_set_target(LOG_TARGET_AUTO); |