Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/dbus-unit: disable service activation while dbus-broker.service … #27570

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/basic/special.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
/* Services systemd relies on */
#define SPECIAL_DBUS_SERVICE "dbus.service"
#define SPECIAL_DBUS_SOCKET "dbus.socket"
#define SPECIAL_DBUS_BROKER_SERVICE "dbus-broker.service"
#define SPECIAL_JOURNALD_SOCKET "systemd-journald.socket"
#define SPECIAL_JOURNALD_SERVICE "systemd-journald.service"
#define SPECIAL_TMPFILES_SETUP_SERVICE "systemd-tmpfiles-setup.service"
Expand Down
9 changes: 9 additions & 0 deletions src/core/dbus-unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "path-util.h"
#include "process-util.h"
#include "selinux-access.h"
#include "service.h"
#include "signal-util.h"
#include "special.h"
#include "string-table.h"
Expand Down Expand Up @@ -1858,6 +1859,14 @@ int bus_unit_queue_job(
(type == JOB_RELOAD_OR_START && job_type_collapse(type, u) == JOB_START && u->refuse_manual_start))
return sd_bus_error_setf(error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only (it is configured to refuse manual start/stop).", u->id);

if (u->manager && type == JOB_START && u->type == UNIT_SERVICE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition u->manager is mostly redundant. If you want, then please add assert(u->manager); at the beginning of the function.

Manager *m = u->manager;
Service *s = SERVICE(u);
if (manager_unit_deactivating_or_pending(m, SPECIAL_DBUS_BROKER_SERVICE) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dbus-broker.service is checked instead of dbus.service? Even if dbus-broker.service is used, IIRC, we assume dbus.service is an alias of dbus-broker.service.

Also, in signal_activation_request(), we checked with manager_unit_inactive_or_pending(). Why not to also use that here?

Copy link
Member

@YHNdnzj YHNdnzj May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to export and use manager_dbus_is_running?

s != NULL && s->type == SERVICE_DBUS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s != NULL is mostly redundant. If you want to check that, please use ASSERT_PTR().

assert(u->manager);
...
if (type == JOB_START && u->type == UNIT_SERVICE &&
    ASSERT_PTR(SERVICE(u))->type == SERVICE_DBUS &&
    manager_unit_deactivating_or_pending(u->manager, SPECIAL_DBUS_BROKER_SERVICE))
        return sd_bus_error_set(...);

return sd_bus_error_set(error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is shutting down.");
}

r = sd_bus_message_new_method_return(message, &reply);
if (r < 0)
return r;
Expand Down
20 changes: 20 additions & 0 deletions src/core/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -3445,6 +3445,26 @@ bool manager_unit_inactive_or_pending(Manager *m, const char *name) {
return unit_inactive_or_pending(u);
}

bool manager_unit_deactivating_or_pending(Manager *m, const char *name) {
Unit *u;

assert(m);
assert(name);

/* Returns true if the unit is deactivating or going down */
u = manager_get_unit(m, name);
if (!u)
return false;

if (unit_active_state(u) == UNIT_DEACTIVATING)
return true;

if (unit_stop_pending(u))
return true;

return false;
}

static void log_taint_string(Manager *m) {
_cleanup_free_ char *taint = NULL;

Expand Down
1 change: 1 addition & 0 deletions src/core/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success);
void manager_send_unit_plymouth(Manager *m, Unit *u);

bool manager_unit_inactive_or_pending(Manager *m, const char *name);
bool manager_unit_deactivating_or_pending(Manager *m, const char *name);

void manager_check_finished(Manager *m);
void manager_send_reloading(Manager *m);
Expand Down