- if (arg_transport == TRANSPORT_NORMAL)
- bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
- else if (arg_transport == TRANSPORT_POLKIT)
- bus_connect_system_polkit(&bus, &error);
- else if (arg_transport == TRANSPORT_SSH)
- bus_connect_system_ssh(NULL, arg_host, &bus, &error);
- else
- assert_not_reached("Uh, invalid transport...");
-
- r = timedatectl_main(bus, argc, argv, &error);
- retval = r < 0 ? EXIT_FAILURE : r;
-
-finish:
- if (bus) {
- dbus_connection_flush(bus);
- dbus_connection_close(bus);
- dbus_connection_unref(bus);
+ r = bus_open_transport(arg_transport, arg_host, false, &bus);
+ if (r < 0) {
+ log_error("Failed to create bus connection: %s", strerror(-r));
+ ret = EXIT_FAILURE;
+ goto finish;