Skip to content

Commit

Permalink
system-upgrade: reboot: don't fail if D-Bus not available
Browse files Browse the repository at this point in the history
Don't fail if D-Bus is not available when verifying that
dnf5-offline-transaction.service is not wanted by system-update.target.
  • Loading branch information
evan-goode committed Mar 21, 2024
1 parent b2f5bbd commit 0b149ab
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions dnf5/commands/offline/offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,27 @@ void OfflineRebootCommand::run() {

#ifdef WITH_SYSTEMD
// Check that dnf5-offline-transaction.service is present and wanted by system-update.target
std::unique_ptr<sdbus::IConnection> connection;
std::unique_ptr<sdbus::IConnection> connection{nullptr};
try {
connection = sdbus::createSystemBusConnection();
} catch (const sdbus::Error & ex) {
const std::string error_message{ex.what()};
throw libdnf5::cli::CommandExitError(1, M_("Couldn't connect to D-Bus: {}"), error_message);
std::cerr << "Warning: couldn't connect to D-Bus: " << ex.what() << std::endl;
}
auto systemd_proxy = sdbus::createProxy(SYSTEMD_DESTINATION_NAME, SYSTEMD_OBJECT_PATH);
if (connection != nullptr) {
auto systemd_proxy = sdbus::createProxy(SYSTEMD_DESTINATION_NAME, SYSTEMD_OBJECT_PATH);

sdbus::ObjectPath unit_object_path;
systemd_proxy->callMethod("LoadUnit")
.onInterface(SYSTEMD_MANAGER_INTERFACE)
.withArguments("system-update.target")
.storeResultsTo(unit_object_path);
sdbus::ObjectPath unit_object_path;
systemd_proxy->callMethod("LoadUnit")
.onInterface(SYSTEMD_MANAGER_INTERFACE)
.withArguments("system-update.target")
.storeResultsTo(unit_object_path);

auto unit_proxy = sdbus::createProxy(SYSTEMD_DESTINATION_NAME, unit_object_path);
const std::vector<std::string> & wants = unit_proxy->getProperty("Wants").onInterface(SYSTEMD_UNIT_INTERFACE);
if (std::find(wants.begin(), wants.end(), SYSTEMD_SERVICE_NAME) == wants.end()) {
throw libdnf5::cli::CommandExitError(1, M_("{} is not wanted by system-update.target."), SYSTEMD_SERVICE_NAME);
auto unit_proxy = sdbus::createProxy(SYSTEMD_DESTINATION_NAME, unit_object_path);
const std::vector<std::string> & wants = unit_proxy->getProperty("Wants").onInterface(SYSTEMD_UNIT_INTERFACE);
if (std::find(wants.begin(), wants.end(), SYSTEMD_SERVICE_NAME) == wants.end()) {
throw libdnf5::cli::CommandExitError(
1, M_("{} is not wanted by system-update.target."), SYSTEMD_SERVICE_NAME);
}
}
#endif

Expand Down

0 comments on commit 0b149ab

Please sign in to comment.