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.
This commit is contained in:
Lennart Poettering 2015-09-24 13:30:10 +02:00
parent 65359589c2
commit 266f3e269d
17 changed files with 29 additions and 29 deletions

View File

@ -1432,7 +1432,7 @@ int main(int argc, char *argv[]) {
else {
_cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
r = bus_open_transport_systemd(arg_transport, arg_host, arg_user, &bus);
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View File

@ -145,7 +145,7 @@ static int get_cgroup_root(char **ret) {
if (!path)
return log_oom();
r = bus_open_transport(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
if (r < 0)
return log_error_errno(r, "Failed to create bus connection: %m");

View File

@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
* this to avoid an activation loop when we start dbus when we
* are called when the dbus service is shut down. */
r = bus_open_system_systemd(&bus);
r = bus_connect_system_systemd(&bus);
if (r < 0) {
/* If we couldn't connect we assume this was triggered
* while systemd got restarted/transitioned from

View File

@ -861,7 +861,7 @@ static int get_cgroup_root(char **ret) {
if (!path)
return log_oom();
r = bus_open_transport(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
if (r < 0)
return log_error_errno(r, "Failed to create bus connection: %m");

View File

@ -67,7 +67,7 @@ static void start_target(const char *target) {
assert(target);
r = bus_open_system_systemd(&bus);
r = bus_connect_system_systemd(&bus);
if (r < 0) {
log_error_errno(r, "Failed to get D-Bus connection: %m");
return;

View File

@ -517,7 +517,7 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View File

@ -318,7 +318,7 @@ static int server_init(Server *s, unsigned n_sockets) {
s->n_fifos ++;
}
r = bus_open_system_systemd(&s->bus);
r = bus_connect_system_systemd(&s->bus);
if (r < 0) {
log_error_errno(r, "Failed to get D-Bus connection: %m");
r = -EIO;

View File

@ -1722,7 +1722,7 @@ static int flush_to_var(void) {
/* OK, let's actually do the full logic, send SIGUSR1 to the
* daemon and set up inotify to wait for the flushed file to appear */
r = bus_open_system_systemd(&bus);
r = bus_connect_system_systemd(&bus);
if (r < 0)
return log_error_errno(r, "Failed to get D-Bus connection: %m");

View File

@ -676,7 +676,7 @@ int main(int argc, char*argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View File

@ -1542,7 +1542,7 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View File

@ -2745,7 +2745,7 @@ int main(int argc, char*argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View File

@ -1174,7 +1174,7 @@ int main(int argc, char* argv[]) {
arg_description = description;
}
r = bus_open_transport_systemd(arg_transport, arg_host, arg_user, &bus);
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View File

@ -574,14 +574,14 @@ int bus_check_peercred(sd_bus *c) {
return 1;
}
int bus_open_system_systemd(sd_bus **_bus) {
int bus_connect_system_systemd(sd_bus **_bus) {
_cleanup_bus_unref_ sd_bus *bus = NULL;
int r;
assert(_bus);
if (geteuid() != 0)
return sd_bus_open_system(_bus);
return sd_bus_default_system(_bus);
/* If we are root and kdbus is not available, then let's talk
* directly to the system instance, instead of going via the
@ -616,7 +616,7 @@ int bus_open_system_systemd(sd_bus **_bus) {
r = sd_bus_start(bus);
if (r < 0)
return sd_bus_open_system(_bus);
return sd_bus_default_system(_bus);
r = bus_check_peercred(bus);
if (r < 0)
@ -628,7 +628,7 @@ int bus_open_system_systemd(sd_bus **_bus) {
return 0;
}
int bus_open_user_systemd(sd_bus **_bus) {
int bus_connect_user_systemd(sd_bus **_bus) {
_cleanup_bus_unref_ sd_bus *bus = NULL;
_cleanup_free_ char *ee = NULL;
const char *e;
@ -658,7 +658,7 @@ int bus_open_user_systemd(sd_bus **_bus) {
e = secure_getenv("XDG_RUNTIME_DIR");
if (!e)
return sd_bus_open_user(_bus);
return sd_bus_default_user(_bus);
ee = bus_address_escape(e);
if (!ee)
@ -674,7 +674,7 @@ int bus_open_user_systemd(sd_bus **_bus) {
r = sd_bus_start(bus);
if (r < 0)
return sd_bus_open_user(_bus);
return sd_bus_default_user(_bus);
r = bus_check_peercred(bus);
if (r < 0)
@ -1209,7 +1209,7 @@ int bus_map_all_properties(
return bus_message_map_all_properties(m, map, userdata);
}
int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) {
int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) {
int r;
assert(transport >= 0);
@ -1244,7 +1244,7 @@ int bus_open_transport(BusTransport transport, const char *host, bool user, sd_b
return r;
}
int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus) {
int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus) {
int r;
assert(transport >= 0);
@ -1258,9 +1258,9 @@ int bus_open_transport_systemd(BusTransport transport, const char *host, bool us
case BUS_TRANSPORT_LOCAL:
if (user)
r = bus_open_user_systemd(bus);
r = bus_connect_user_systemd(bus);
else
r = bus_open_system_systemd(bus);
r = bus_connect_system_systemd(bus);
break;

View File

@ -65,11 +65,11 @@ int bus_test_polkit(sd_bus_message *call, int capability, const char *action, co
int bus_verify_polkit_async(sd_bus_message *call, int capability, const char *action, const char **details, bool interactive, uid_t good_user, Hashmap **registry, sd_bus_error *error);
void bus_verify_polkit_async_registry_free(Hashmap *registry);
int bus_open_system_systemd(sd_bus **_bus);
int bus_open_user_systemd(sd_bus **_bus);
int bus_connect_system_systemd(sd_bus **_bus);
int bus_connect_user_systemd(sd_bus **_bus);
int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_print_property(const char *name, sd_bus_message *property, bool all);
int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all);

View File

@ -7590,7 +7590,7 @@ int main(int argc, char*argv[]) {
}
if (!avoid_bus())
r = bus_open_transport_systemd(arg_transport, arg_host, arg_scope != UNIT_FILE_SYSTEM, &bus);
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_scope != UNIT_FILE_SYSTEM, &bus);
if (bus)
sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);

View File

@ -500,7 +500,7 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
r = bus_open_transport(arg_transport, arg_host, false, &bus);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;

View File

@ -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;