| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <linux/capability.h> |
| 4 |
#include <sys/prctl.h> |
| 5 |
#include <unistd.h> |
| 6 |
|
| 7 |
#include "alloc-util.h" |
| 8 |
#include "architecture.h" |
| 9 |
#include "bitfield.h" |
| 10 |
#include "build.h" |
| 11 |
#include "bus-common-errors.h" |
| 12 |
#include "bus-get-properties.h" |
| 13 |
#include "bus-log-control-api.h" |
| 14 |
#include "bus-message-util.h" |
| 15 |
#include "bus-util.h" |
| 16 |
#include "chase.h" |
| 17 |
#include "confidential-virt.h" |
| 18 |
#include "dbus-cgroup.h" |
| 19 |
#include "dbus-execute.h" |
| 20 |
#include "dbus.h" |
| 21 |
#include "dbus-job.h" |
| 22 |
#include "dbus-manager.h" |
| 23 |
#include "dbus-scope.h" |
| 24 |
#include "dbus-service.h" |
| 25 |
#include "dbus-unit.h" |
| 26 |
#include "dbus-util.h" |
| 27 |
#include "dynamic-user.h" |
| 28 |
#include "env-util.h" |
| 29 |
#include "errno-util.h" |
| 30 |
#include "fd-util.h" |
| 31 |
#include "format-util.h" |
| 32 |
#include "glyph-util.h" |
| 33 |
#include "hashmap.h" |
| 34 |
#include "initrd-util.h" |
| 35 |
#include "install.h" |
| 36 |
#include "locale-util.h" |
| 37 |
#include "log.h" |
| 38 |
#include "manager-dump.h" |
| 39 |
#include "manager.h" |
| 40 |
#include "memfd-util.h" |
| 41 |
#include "os-util.h" |
| 42 |
#include "path-util.h" |
| 43 |
#include "pidref.h" |
| 44 |
#include "process-util.h" |
| 45 |
#include "selinux-access.h" |
| 46 |
#include "set.h" |
| 47 |
#include "string-util.h" |
| 48 |
#include "strv.h" |
| 49 |
#include "syslog-util.h" |
| 50 |
#include "taint.h" |
| 51 |
#include "unit-name.h" |
| 52 |
#include "user-util.h" |
| 53 |
#include "version.h" |
| 54 |
#include "virt.h" |
| 55 |
#include "watchdog.h" |
| 56 |
|
| 57 |
static UnitFileFlags unit_file_bools_to_flags(bool runtime, bool force) { |
| 58 |
return (runtime ? UNIT_FILE_RUNTIME : 0) | |
| 59 |
(force ? UNIT_FILE_FORCE : 0); |
| 60 |
} |
| 61 |
|
| 62 |
BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_oom_policy, oom_policy, OOMPolicy); |
| 63 |
BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_emergency_action, emergency_action, EmergencyAction); |
| 64 |
|
| 65 |
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version, "s", GIT_VERSION); |
| 66 |
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features, "s", systemd_features); |
| 67 |
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture, "s", architecture_to_string(uname_architecture())); |
| 68 |
static BUS_DEFINE_PROPERTY_GET2(property_get_system_state, "s", Manager, manager_state, manager_state_to_string); |
| 69 |
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_timer_slack_nsec, "t", (uint64_t) prctl(PR_GET_TIMERSLACK)); |
| 70 |
static BUS_DEFINE_PROPERTY_GET_REF(property_get_hashmap_size, "u", Hashmap *, hashmap_size); |
| 71 |
static BUS_DEFINE_PROPERTY_GET_REF(property_get_set_size, "u", Set *, set_size); |
| 72 |
static BUS_DEFINE_PROPERTY_GET(property_get_default_timeout_abort_usec, "t", Manager, manager_default_timeout_abort_usec); |
| 73 |
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_device, "s", watchdog_get_device()); |
| 74 |
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_last_ping_realtime, "t", watchdog_get_last_ping(CLOCK_REALTIME)); |
| 75 |
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_last_ping_monotonic, "t", watchdog_get_last_ping(CLOCK_MONOTONIC)); |
| 76 |
static BUS_DEFINE_PROPERTY_GET(property_get_progress, "d", Manager, manager_get_progress); |
| 77 |
|
| 78 |
static int property_get_virtualization( |
| 79 |
sd_bus *bus, |
| 80 |
const char *path, |
| 81 |
const char *interface, |
| 82 |
const char *property, |
| 83 |
sd_bus_message *reply, |
| 84 |
void *userdata, |
| 85 |
sd_bus_error *reterr_error) { |
| 86 |
|
| 87 |
Virtualization v; |
| 88 |
|
| 89 |
assert(bus); |
| 90 |
assert(reply); |
| 91 |
|
| 92 |
v = detect_virtualization(); |
| 93 |
|
| 94 |
/* Make sure to return the empty string when we detect no virtualization, as that is the API. |
| 95 |
* |
| 96 |
* https://github.com/systemd/systemd/issues/1423 |
| 97 |
*/ |
| 98 |
|
| 99 |
return sd_bus_message_append( |
| 100 |
reply, "s", |
| 101 |
v == VIRTUALIZATION_NONE ? NULL : virtualization_to_string(v)); |
| 102 |
} |
| 103 |
|
| 104 |
static int property_get_confidential_virtualization( |
| 105 |
sd_bus *bus, |
| 106 |
const char *path, |
| 107 |
const char *interface, |
| 108 |
const char *property, |
| 109 |
sd_bus_message *reply, |
| 110 |
void *userdata, |
| 111 |
sd_bus_error *reterr_error) { |
| 112 |
|
| 113 |
ConfidentialVirtualization v; |
| 114 |
|
| 115 |
assert(bus); |
| 116 |
assert(reply); |
| 117 |
|
| 118 |
v = detect_confidential_virtualization(); |
| 119 |
|
| 120 |
return sd_bus_message_append( |
| 121 |
reply, "s", |
| 122 |
v <= 0 ? NULL : confidential_virtualization_to_string(v)); |
| 123 |
} |
| 124 |
|
| 125 |
static int property_get_tainted( |
| 126 |
sd_bus *bus, |
| 127 |
const char *path, |
| 128 |
const char *interface, |
| 129 |
const char *property, |
| 130 |
sd_bus_message *reply, |
| 131 |
void *userdata, |
| 132 |
sd_bus_error *reterr_error) { |
| 133 |
|
| 134 |
assert(bus); |
| 135 |
assert(reply); |
| 136 |
|
| 137 |
_cleanup_free_ char *s = taint_string(); |
| 138 |
if (!s) |
| 139 |
return log_oom(); |
| 140 |
|
| 141 |
return sd_bus_message_append(reply, "s", s); |
| 142 |
} |
| 143 |
|
| 144 |
static int property_set_log_target( |
| 145 |
sd_bus *bus, |
| 146 |
const char *path, |
| 147 |
const char *interface, |
| 148 |
const char *property, |
| 149 |
sd_bus_message *value, |
| 150 |
void *userdata, |
| 151 |
sd_bus_error *reterr_error) { |
| 152 |
|
| 153 |
Manager *m = userdata; |
| 154 |
const char *t; |
| 155 |
int r; |
| 156 |
|
| 157 |
assert(bus); |
| 158 |
assert(value); |
| 159 |
|
| 160 |
r = sd_bus_message_read(value, "s", &t); |
| 161 |
if (r < 0) |
| 162 |
return r; |
| 163 |
|
| 164 |
if (isempty(t)) |
| 165 |
manager_restore_original_log_target(m); |
| 166 |
else { |
| 167 |
LogTarget target; |
| 168 |
|
| 169 |
target = log_target_from_string(t); |
| 170 |
if (target < 0) |
| 171 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log target '%s'", t); |
| 172 |
|
| 173 |
manager_override_log_target(m, target); |
| 174 |
} |
| 175 |
|
| 176 |
return 0; |
| 177 |
} |
| 178 |
|
| 179 |
static int property_set_log_level( |
| 180 |
sd_bus *bus, |
| 181 |
const char *path, |
| 182 |
const char *interface, |
| 183 |
const char *property, |
| 184 |
sd_bus_message *value, |
| 185 |
void *userdata, |
| 186 |
sd_bus_error *reterr_error) { |
| 187 |
|
| 188 |
Manager *m = userdata; |
| 189 |
const char *t; |
| 190 |
int r; |
| 191 |
|
| 192 |
assert(bus); |
| 193 |
assert(value); |
| 194 |
|
| 195 |
r = sd_bus_message_read(value, "s", &t); |
| 196 |
if (r < 0) |
| 197 |
return r; |
| 198 |
|
| 199 |
if (isempty(t)) |
| 200 |
manager_restore_original_log_level(m); |
| 201 |
else { |
| 202 |
int level; |
| 203 |
|
| 204 |
level = log_level_from_string(t); |
| 205 |
if (level < 0) |
| 206 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log level '%s'", t); |
| 207 |
|
| 208 |
manager_override_log_level(m, level); |
| 209 |
} |
| 210 |
|
| 211 |
return 0; |
| 212 |
} |
| 213 |
|
| 214 |
static int property_get_environment( |
| 215 |
sd_bus *bus, |
| 216 |
const char *path, |
| 217 |
const char *interface, |
| 218 |
const char *property, |
| 219 |
sd_bus_message *reply, |
| 220 |
void *userdata, |
| 221 |
sd_bus_error *reterr_error) { |
| 222 |
|
| 223 |
_cleanup_strv_free_ char **l = NULL; |
| 224 |
Manager *m = ASSERT_PTR(userdata); |
| 225 |
int r; |
| 226 |
|
| 227 |
assert(bus); |
| 228 |
assert(reply); |
| 229 |
|
| 230 |
r = manager_get_effective_environment(m, &l); |
| 231 |
if (r < 0) |
| 232 |
return r; |
| 233 |
|
| 234 |
return sd_bus_message_append_strv(reply, l); |
| 235 |
} |
| 236 |
|
| 237 |
static int property_get_show_status( |
| 238 |
sd_bus *bus, |
| 239 |
const char *path, |
| 240 |
const char *interface, |
| 241 |
const char *property, |
| 242 |
sd_bus_message *reply, |
| 243 |
void *userdata, |
| 244 |
sd_bus_error *reterr_error) { |
| 245 |
|
| 246 |
Manager *m = ASSERT_PTR(userdata); |
| 247 |
|
| 248 |
assert(bus); |
| 249 |
assert(reply); |
| 250 |
|
| 251 |
return sd_bus_message_append(reply, "b", manager_get_show_status_on(m)); |
| 252 |
} |
| 253 |
|
| 254 |
static int property_get_runtime_watchdog( |
| 255 |
sd_bus *bus, |
| 256 |
const char *path, |
| 257 |
const char *interface, |
| 258 |
const char *property, |
| 259 |
sd_bus_message *reply, |
| 260 |
void *userdata, |
| 261 |
sd_bus_error *reterr_error) { |
| 262 |
|
| 263 |
Manager *m = ASSERT_PTR(userdata); |
| 264 |
|
| 265 |
assert(bus); |
| 266 |
assert(reply); |
| 267 |
|
| 268 |
return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_RUNTIME)); |
| 269 |
} |
| 270 |
|
| 271 |
static int property_get_pretimeout_watchdog( |
| 272 |
sd_bus *bus, |
| 273 |
const char *path, |
| 274 |
const char *interface, |
| 275 |
const char *property, |
| 276 |
sd_bus_message *reply, |
| 277 |
void *userdata, |
| 278 |
sd_bus_error *reterr_error) { |
| 279 |
|
| 280 |
Manager *m = ASSERT_PTR(userdata); |
| 281 |
|
| 282 |
assert(bus); |
| 283 |
assert(reply); |
| 284 |
|
| 285 |
return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_PRETIMEOUT)); |
| 286 |
} |
| 287 |
|
| 288 |
static int property_get_pretimeout_watchdog_governor( |
| 289 |
sd_bus *bus, |
| 290 |
const char *path, |
| 291 |
const char *interface, |
| 292 |
const char *property, |
| 293 |
sd_bus_message *reply, |
| 294 |
void *userdata, |
| 295 |
sd_bus_error *reterr_error) { |
| 296 |
|
| 297 |
Manager *m = ASSERT_PTR(userdata); |
| 298 |
|
| 299 |
assert(bus); |
| 300 |
assert(reply); |
| 301 |
|
| 302 |
return sd_bus_message_append(reply, "s", m->watchdog_pretimeout_governor); |
| 303 |
} |
| 304 |
|
| 305 |
static int property_get_reboot_watchdog( |
| 306 |
sd_bus *bus, |
| 307 |
const char *path, |
| 308 |
const char *interface, |
| 309 |
const char *property, |
| 310 |
sd_bus_message *reply, |
| 311 |
void *userdata, |
| 312 |
sd_bus_error *reterr_error) { |
| 313 |
|
| 314 |
Manager *m = ASSERT_PTR(userdata); |
| 315 |
|
| 316 |
assert(bus); |
| 317 |
assert(reply); |
| 318 |
|
| 319 |
return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_REBOOT)); |
| 320 |
} |
| 321 |
|
| 322 |
static int property_get_kexec_watchdog( |
| 323 |
sd_bus *bus, |
| 324 |
const char *path, |
| 325 |
const char *interface, |
| 326 |
const char *property, |
| 327 |
sd_bus_message *reply, |
| 328 |
void *userdata, |
| 329 |
sd_bus_error *reterr_error) { |
| 330 |
|
| 331 |
Manager *m = ASSERT_PTR(userdata); |
| 332 |
|
| 333 |
assert(bus); |
| 334 |
assert(reply); |
| 335 |
|
| 336 |
return sd_bus_message_append(reply, "t", manager_get_watchdog(m, WATCHDOG_KEXEC)); |
| 337 |
} |
| 338 |
|
| 339 |
static int property_set_watchdog(Manager *m, WatchdogType type, sd_bus_message *value) { |
| 340 |
usec_t timeout; |
| 341 |
int r; |
| 342 |
|
| 343 |
assert(m); |
| 344 |
assert(value); |
| 345 |
|
| 346 |
assert_cc(sizeof(usec_t) == sizeof(uint64_t)); |
| 347 |
|
| 348 |
r = sd_bus_message_read(value, "t", &timeout); |
| 349 |
if (r < 0) |
| 350 |
return r; |
| 351 |
|
| 352 |
manager_override_watchdog(m, type, timeout); |
| 353 |
return 0; |
| 354 |
} |
| 355 |
|
| 356 |
static int property_set_runtime_watchdog( |
| 357 |
sd_bus *bus, |
| 358 |
const char *path, |
| 359 |
const char *interface, |
| 360 |
const char *property, |
| 361 |
sd_bus_message *value, |
| 362 |
void *userdata, |
| 363 |
sd_bus_error *reterr_error) { |
| 364 |
|
| 365 |
return property_set_watchdog(userdata, WATCHDOG_RUNTIME, value); |
| 366 |
} |
| 367 |
|
| 368 |
static int property_set_pretimeout_watchdog( |
| 369 |
sd_bus *bus, |
| 370 |
const char *path, |
| 371 |
const char *interface, |
| 372 |
const char *property, |
| 373 |
sd_bus_message *value, |
| 374 |
void *userdata, |
| 375 |
sd_bus_error *reterr_error) { |
| 376 |
|
| 377 |
return property_set_watchdog(userdata, WATCHDOG_PRETIMEOUT, value); |
| 378 |
} |
| 379 |
|
| 380 |
static int property_set_pretimeout_watchdog_governor( |
| 381 |
sd_bus *bus, |
| 382 |
const char *path, |
| 383 |
const char *interface, |
| 384 |
const char *property, |
| 385 |
sd_bus_message *value, |
| 386 |
void *userdata, |
| 387 |
sd_bus_error *reterr_error) { |
| 388 |
|
| 389 |
Manager *m = ASSERT_PTR(userdata); |
| 390 |
const char *governor; |
| 391 |
int r; |
| 392 |
|
| 393 |
r = sd_bus_message_read(value, "s", &governor); |
| 394 |
if (r < 0) |
| 395 |
return r; |
| 396 |
|
| 397 |
if (isempty(governor)) |
| 398 |
governor = NULL; |
| 399 |
else if (!string_is_safe(governor, /* flags= */ 0)) |
| 400 |
return -EINVAL; |
| 401 |
|
| 402 |
return manager_override_watchdog_pretimeout_governor(m, governor); |
| 403 |
} |
| 404 |
|
| 405 |
static int property_set_reboot_watchdog( |
| 406 |
sd_bus *bus, |
| 407 |
const char *path, |
| 408 |
const char *interface, |
| 409 |
const char *property, |
| 410 |
sd_bus_message *value, |
| 411 |
void *userdata, |
| 412 |
sd_bus_error *reterr_error) { |
| 413 |
|
| 414 |
return property_set_watchdog(userdata, WATCHDOG_REBOOT, value); |
| 415 |
} |
| 416 |
|
| 417 |
static int property_set_kexec_watchdog( |
| 418 |
sd_bus *bus, |
| 419 |
const char *path, |
| 420 |
const char *interface, |
| 421 |
const char *property, |
| 422 |
sd_bus_message *value, |
| 423 |
void *userdata, |
| 424 |
sd_bus_error *reterr_error) { |
| 425 |
|
| 426 |
_unused_ Manager *m = ASSERT_PTR(userdata); |
| 427 |
|
| 428 |
assert(bus); |
| 429 |
assert(value); |
| 430 |
|
| 431 |
return property_set_watchdog(userdata, WATCHDOG_KEXEC, value); |
| 432 |
} |
| 433 |
|
| 434 |
static int property_get_oom_score_adjust( |
| 435 |
sd_bus *bus, |
| 436 |
const char *path, |
| 437 |
const char *interface, |
| 438 |
const char *property, |
| 439 |
sd_bus_message *reply, |
| 440 |
void *userdata, |
| 441 |
sd_bus_error *reterr_error) { |
| 442 |
|
| 443 |
Manager *m = ASSERT_PTR(userdata); |
| 444 |
int r, n; |
| 445 |
|
| 446 |
assert(bus); |
| 447 |
assert(reply); |
| 448 |
|
| 449 |
if (m->defaults.oom_score_adjust_set) |
| 450 |
n = m->defaults.oom_score_adjust; |
| 451 |
else { |
| 452 |
n = 0; |
| 453 |
r = get_oom_score_adjust(&n); |
| 454 |
if (r < 0) |
| 455 |
log_debug_errno(r, "Failed to read current OOM score adjustment value, ignoring: %m"); |
| 456 |
} |
| 457 |
|
| 458 |
return sd_bus_message_append(reply, "i", n); |
| 459 |
} |
| 460 |
|
| 461 |
static int property_get_transactions_with_cycle( |
| 462 |
sd_bus *bus, |
| 463 |
const char *path, |
| 464 |
const char *interface, |
| 465 |
const char *property, |
| 466 |
sd_bus_message *reply, |
| 467 |
void *userdata, |
| 468 |
sd_bus_error *reterr_error) { |
| 469 |
|
| 470 |
Manager *m = ASSERT_PTR(userdata); |
| 471 |
int r; |
| 472 |
|
| 473 |
assert(bus); |
| 474 |
assert(reply); |
| 475 |
|
| 476 |
r = sd_bus_message_open_container(reply, 'a', "t"); |
| 477 |
if (r < 0) |
| 478 |
return r; |
| 479 |
|
| 480 |
uint64_t *id; |
| 481 |
SET_FOREACH(id, m->transactions_with_cycle) { |
| 482 |
r = sd_bus_message_append_basic(reply, 't', id); |
| 483 |
if (r < 0) |
| 484 |
return r; |
| 485 |
} |
| 486 |
|
| 487 |
return sd_bus_message_close_container(reply); |
| 488 |
} |
| 489 |
|
| 490 |
static int bus_get_unit_by_name(Manager *m, sd_bus_message *message, const char *name, Unit **ret_unit, sd_bus_error *reterr_error) { |
| 491 |
Unit *u; |
| 492 |
int r; |
| 493 |
|
| 494 |
assert(m); |
| 495 |
assert(message); |
| 496 |
assert(ret_unit); |
| 497 |
|
| 498 |
/* More or less a wrapper around manager_get_unit() that generates nice errors and has one trick up |
| 499 |
* its sleeve: if the name is specified empty we use the client's unit. */ |
| 500 |
|
| 501 |
if (isempty(name)) { |
| 502 |
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
| 503 |
|
| 504 |
r = bus_query_sender_pidref(message, &pidref); |
| 505 |
if (r < 0) |
| 506 |
return r; |
| 507 |
|
| 508 |
u = manager_get_unit_by_pidref(m, &pidref); |
| 509 |
if (!u) |
| 510 |
return sd_bus_error_set(reterr_error, BUS_ERROR_NO_SUCH_UNIT, "Client not member of any unit."); |
| 511 |
} else { |
| 512 |
u = manager_get_unit(m, name); |
| 513 |
if (!u) |
| 514 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name); |
| 515 |
} |
| 516 |
|
| 517 |
*ret_unit = u; |
| 518 |
return 0; |
| 519 |
} |
| 520 |
|
| 521 |
static int bus_load_unit_by_name(Manager *m, sd_bus_message *message, const char *name, Unit **ret_unit, sd_bus_error *reterr_error) { |
| 522 |
assert(m); |
| 523 |
assert(message); |
| 524 |
assert(ret_unit); |
| 525 |
|
| 526 |
/* Pretty much the same as bus_get_unit_by_name(), but we also load the unit if necessary. */ |
| 527 |
|
| 528 |
if (isempty(name)) |
| 529 |
return bus_get_unit_by_name(m, message, name, ret_unit, reterr_error); |
| 530 |
|
| 531 |
return manager_load_unit(m, name, NULL, reterr_error, ret_unit); |
| 532 |
} |
| 533 |
|
| 534 |
static int reply_unit_path(Unit *u, sd_bus_message *message, sd_bus_error *reterr_error) { |
| 535 |
_cleanup_free_ char *path = NULL; |
| 536 |
int r; |
| 537 |
|
| 538 |
assert(u); |
| 539 |
assert(message); |
| 540 |
|
| 541 |
r = mac_selinux_unit_access_check(u, message, "status", reterr_error); |
| 542 |
if (r < 0) |
| 543 |
return r; |
| 544 |
|
| 545 |
path = unit_dbus_path(u); |
| 546 |
if (!path) |
| 547 |
return log_oom(); |
| 548 |
|
| 549 |
return sd_bus_reply_method_return(message, "o", path); |
| 550 |
} |
| 551 |
|
| 552 |
static int method_get_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 553 |
Manager *m = ASSERT_PTR(userdata); |
| 554 |
const char *name; |
| 555 |
Unit *u; |
| 556 |
int r; |
| 557 |
|
| 558 |
assert(message); |
| 559 |
|
| 560 |
/* Anyone can call this method */ |
| 561 |
|
| 562 |
r = sd_bus_message_read(message, "s", &name); |
| 563 |
if (r < 0) |
| 564 |
return r; |
| 565 |
|
| 566 |
r = bus_get_unit_by_name(m, message, name, &u, reterr_error); |
| 567 |
if (r < 0) |
| 568 |
return r; |
| 569 |
|
| 570 |
return reply_unit_path(u, message, reterr_error); |
| 571 |
} |
| 572 |
|
| 573 |
static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 574 |
Manager *m = ASSERT_PTR(userdata); |
| 575 |
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
| 576 |
Unit *u; |
| 577 |
int r; |
| 578 |
|
| 579 |
assert(message); |
| 580 |
|
| 581 |
assert_cc(sizeof(pid_t) == sizeof(uint32_t)); |
| 582 |
|
| 583 |
/* Anyone can call this method */ |
| 584 |
|
| 585 |
r = sd_bus_message_read(message, "u", &pidref.pid); |
| 586 |
if (r < 0) |
| 587 |
return r; |
| 588 |
if (pidref.pid < 0) |
| 589 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pidref.pid); |
| 590 |
if (pidref.pid == 0) { |
| 591 |
r = bus_query_sender_pidref(message, &pidref); |
| 592 |
if (r < 0) |
| 593 |
return r; |
| 594 |
} |
| 595 |
|
| 596 |
u = manager_get_unit_by_pidref(m, &pidref); |
| 597 |
if (!u) |
| 598 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_UNIT_FOR_PID, "PID "PID_FMT" does not belong to any loaded unit.", pidref.pid); |
| 599 |
|
| 600 |
return reply_unit_path(u, message, reterr_error); |
| 601 |
} |
| 602 |
|
| 603 |
static int method_get_unit_by_invocation_id(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 604 |
_cleanup_free_ char *path = NULL; |
| 605 |
Manager *m = ASSERT_PTR(userdata); |
| 606 |
sd_id128_t id; |
| 607 |
Unit *u; |
| 608 |
int r; |
| 609 |
|
| 610 |
assert(message); |
| 611 |
|
| 612 |
/* Anyone can call this method */ |
| 613 |
|
| 614 |
if (bus_message_read_id128(message, &id) < 0) |
| 615 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid invocation ID"); |
| 616 |
|
| 617 |
if (sd_id128_is_null(id)) { |
| 618 |
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
| 619 |
|
| 620 |
r = bus_query_sender_pidref(message, &pidref); |
| 621 |
if (r < 0) |
| 622 |
return r; |
| 623 |
|
| 624 |
u = manager_get_unit_by_pidref(m, &pidref); |
| 625 |
if (!u) |
| 626 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_UNIT, |
| 627 |
"Client " PID_FMT " not member of any unit.", pidref.pid); |
| 628 |
} else { |
| 629 |
u = hashmap_get(m->units_by_invocation_id, &id); |
| 630 |
if (!u) |
| 631 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_UNIT_FOR_INVOCATION_ID, "No unit with the specified invocation ID " SD_ID128_FORMAT_STR " known.", SD_ID128_FORMAT_VAL(id)); |
| 632 |
} |
| 633 |
|
| 634 |
r = mac_selinux_unit_access_check(u, message, "status", reterr_error); |
| 635 |
if (r < 0) |
| 636 |
return r; |
| 637 |
|
| 638 |
/* So here's a special trick: the bus path we return actually references the unit by its invocation |
| 639 |
* ID instead of the unit name. This means it stays valid only as long as the invocation ID stays the |
| 640 |
* same. */ |
| 641 |
path = unit_dbus_path_invocation_id(u); |
| 642 |
if (!path) |
| 643 |
return -ENOMEM; |
| 644 |
|
| 645 |
return sd_bus_reply_method_return(message, "o", path); |
| 646 |
} |
| 647 |
|
| 648 |
static int method_get_unit_by_control_group(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 649 |
Manager *m = userdata; |
| 650 |
const char *cgroup; |
| 651 |
Unit *u; |
| 652 |
int r; |
| 653 |
|
| 654 |
r = sd_bus_message_read(message, "s", &cgroup); |
| 655 |
if (r < 0) |
| 656 |
return r; |
| 657 |
|
| 658 |
if (!path_is_absolute(cgroup)) |
| 659 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Control group path is not absolute: %s", cgroup); |
| 660 |
|
| 661 |
if (!path_is_normalized(cgroup)) |
| 662 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Control group path is not normalized: %s", cgroup); |
| 663 |
|
| 664 |
u = manager_get_unit_by_cgroup(m, cgroup); |
| 665 |
if (!u) |
| 666 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_UNIT, |
| 667 |
"Control group '%s' is not valid or not managed by this instance", |
| 668 |
cgroup); |
| 669 |
|
| 670 |
return reply_unit_path(u, message, reterr_error); |
| 671 |
} |
| 672 |
|
| 673 |
static int method_get_unit_by_pidfd(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 674 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 675 |
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
| 676 |
Manager *m = ASSERT_PTR(userdata); |
| 677 |
_cleanup_free_ char *path = NULL; |
| 678 |
int r, pidfd; |
| 679 |
Unit *u; |
| 680 |
|
| 681 |
assert(message); |
| 682 |
|
| 683 |
r = sd_bus_message_read(message, "h", &pidfd); |
| 684 |
if (r < 0) |
| 685 |
return r; |
| 686 |
|
| 687 |
r = pidref_set_pidfd(&pidref, pidfd); |
| 688 |
if (r < 0) |
| 689 |
return sd_bus_error_set_errnof(reterr_error, r, "Failed to get PID from PIDFD: %m"); |
| 690 |
|
| 691 |
u = manager_get_unit_by_pidref(m, &pidref); |
| 692 |
if (!u) |
| 693 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_UNIT_FOR_PID, "PID "PID_FMT" does not belong to any loaded unit.", pidref.pid); |
| 694 |
|
| 695 |
r = mac_selinux_unit_access_check(u, message, "status", reterr_error); |
| 696 |
if (r < 0) |
| 697 |
return r; |
| 698 |
|
| 699 |
path = unit_dbus_path(u); |
| 700 |
if (!path) |
| 701 |
return log_oom(); |
| 702 |
|
| 703 |
r = sd_bus_message_new_method_return(message, &reply); |
| 704 |
if (r < 0) |
| 705 |
return r; |
| 706 |
|
| 707 |
r = sd_bus_message_append(reply, "os", path, u->id); |
| 708 |
if (r < 0) |
| 709 |
return r; |
| 710 |
|
| 711 |
r = sd_bus_message_append_array(reply, 'y', u->invocation_id.bytes, sizeof(u->invocation_id.bytes)); |
| 712 |
if (r < 0) |
| 713 |
return r; |
| 714 |
|
| 715 |
/* Double-check that the process is still alive and that the PID did not change before returning the |
| 716 |
* answer. */ |
| 717 |
r = pidref_verify(&pidref); |
| 718 |
if (r == -ESRCH) |
| 719 |
return sd_bus_error_setf(reterr_error, |
| 720 |
BUS_ERROR_NO_SUCH_PROCESS, |
| 721 |
"The PIDFD's PID "PID_FMT" changed during the lookup operation.", |
| 722 |
pidref.pid); |
| 723 |
if (r < 0) |
| 724 |
return sd_bus_error_set_errnof(reterr_error, r, "Failed to get PID from PIDFD: %m"); |
| 725 |
|
| 726 |
return sd_bus_message_send(reply); |
| 727 |
} |
| 728 |
|
| 729 |
static int method_load_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 730 |
Manager *m = ASSERT_PTR(userdata); |
| 731 |
const char *name; |
| 732 |
Unit *u; |
| 733 |
int r; |
| 734 |
|
| 735 |
assert(message); |
| 736 |
|
| 737 |
/* Anyone can call this method */ |
| 738 |
|
| 739 |
r = sd_bus_message_read(message, "s", &name); |
| 740 |
if (r < 0) |
| 741 |
return r; |
| 742 |
|
| 743 |
r = bus_load_unit_by_name(m, message, name, &u, reterr_error); |
| 744 |
if (r < 0) |
| 745 |
return r; |
| 746 |
|
| 747 |
return reply_unit_path(u, message, reterr_error); |
| 748 |
} |
| 749 |
|
| 750 |
static int method_start_unit_generic(sd_bus_message *message, Manager *m, JobType job_type, bool reload_if_possible, sd_bus_error *reterr_error) { |
| 751 |
const char *name; |
| 752 |
Unit *u; |
| 753 |
int r; |
| 754 |
|
| 755 |
assert(message); |
| 756 |
assert(m); |
| 757 |
|
| 758 |
r = sd_bus_message_read(message, "s", &name); |
| 759 |
if (r < 0) |
| 760 |
return r; |
| 761 |
|
| 762 |
r = manager_load_unit(m, name, NULL, reterr_error, &u); |
| 763 |
if (r < 0) |
| 764 |
return r; |
| 765 |
|
| 766 |
return bus_unit_method_start_generic(message, u, job_type, reload_if_possible, reterr_error); |
| 767 |
} |
| 768 |
|
| 769 |
static int method_start_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 770 |
return method_start_unit_generic(message, userdata, JOB_START, /* reload_if_possible= */ false, reterr_error); |
| 771 |
} |
| 772 |
|
| 773 |
static int method_stop_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 774 |
return method_start_unit_generic(message, userdata, JOB_STOP, /* reload_if_possible= */ false, reterr_error); |
| 775 |
} |
| 776 |
|
| 777 |
static int method_reload_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 778 |
return method_start_unit_generic(message, userdata, JOB_RELOAD, /* reload_if_possible= */ false, reterr_error); |
| 779 |
} |
| 780 |
|
| 781 |
static int method_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 782 |
return method_start_unit_generic(message, userdata, JOB_RESTART, /* reload_if_possible= */ false, reterr_error); |
| 783 |
} |
| 784 |
|
| 785 |
static int method_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 786 |
return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, /* reload_if_possible= */ false, reterr_error); |
| 787 |
} |
| 788 |
|
| 789 |
static int method_reload_or_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 790 |
return method_start_unit_generic(message, userdata, JOB_RESTART, /* reload_if_possible= */ true, reterr_error); |
| 791 |
} |
| 792 |
|
| 793 |
static int method_reload_or_try_restart_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 794 |
return method_start_unit_generic(message, userdata, JOB_TRY_RESTART, /* reload_if_possible= */ true, reterr_error); |
| 795 |
} |
| 796 |
|
| 797 |
typedef enum GenericUnitOperationFlags { |
| 798 |
GENERIC_UNIT_LOAD = 1 << 0, /* Load if the unit is not loaded yet */ |
| 799 |
GENERIC_UNIT_VALIDATE_LOADED = 1 << 1, /* Verify unit is properly loaded before forwarding call */ |
| 800 |
} GenericUnitOperationFlags; |
| 801 |
|
| 802 |
static int method_generic_unit_operation( |
| 803 |
sd_bus_message *message, |
| 804 |
Manager *m, |
| 805 |
sd_bus_error *reterr_error, |
| 806 |
UnitType type, |
| 807 |
sd_bus_message_handler_t handler, |
| 808 |
GenericUnitOperationFlags flags) { |
| 809 |
|
| 810 |
const char *name; |
| 811 |
Unit *u; |
| 812 |
int r; |
| 813 |
|
| 814 |
assert(message); |
| 815 |
assert(m); |
| 816 |
assert(handler); |
| 817 |
|
| 818 |
/* Read the first argument from the command and pass the operation to the specified per-unit |
| 819 |
* method. */ |
| 820 |
|
| 821 |
r = sd_bus_message_read(message, "s", &name); |
| 822 |
if (r < 0) |
| 823 |
return r; |
| 824 |
|
| 825 |
if (!isempty(name) && FLAGS_SET(flags, GENERIC_UNIT_LOAD)) |
| 826 |
r = manager_load_unit(m, name, NULL, reterr_error, &u); |
| 827 |
else |
| 828 |
r = bus_get_unit_by_name(m, message, name, &u, reterr_error); |
| 829 |
if (r < 0) |
| 830 |
return r; |
| 831 |
|
| 832 |
if (type != _UNIT_TYPE_INVALID && u->type != type) |
| 833 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 834 |
"%s operation is not supported for unit type '%s'", |
| 835 |
sd_bus_message_get_member(message), unit_type_to_string(u->type)); |
| 836 |
|
| 837 |
if (FLAGS_SET(flags, GENERIC_UNIT_VALIDATE_LOADED)) { |
| 838 |
r = bus_unit_validate_load_state(u, reterr_error); |
| 839 |
if (r < 0) |
| 840 |
return r; |
| 841 |
} |
| 842 |
|
| 843 |
return handler(message, u, reterr_error); |
| 844 |
} |
| 845 |
|
| 846 |
static int method_enqueue_unit_job(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 847 |
/* We don't bother with GENERIC_UNIT_VALIDATE_LOADED here, as the job logic validates that anyway */ |
| 848 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_enqueue_job, GENERIC_UNIT_LOAD); |
| 849 |
} |
| 850 |
|
| 851 |
static int method_start_unit_replace(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 852 |
Manager *m = ASSERT_PTR(userdata); |
| 853 |
const char *old_name; |
| 854 |
Unit *u; |
| 855 |
int r; |
| 856 |
|
| 857 |
assert(message); |
| 858 |
|
| 859 |
r = sd_bus_message_read(message, "s", &old_name); |
| 860 |
if (r < 0) |
| 861 |
return r; |
| 862 |
|
| 863 |
r = bus_get_unit_by_name(m, message, old_name, &u, reterr_error); |
| 864 |
if (r < 0) |
| 865 |
return r; |
| 866 |
if (!u->job || u->job->type != JOB_START) |
| 867 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name); |
| 868 |
|
| 869 |
return method_start_unit_generic(message, m, JOB_START, /* reload_if_possible= */ false, reterr_error); |
| 870 |
} |
| 871 |
|
| 872 |
static int method_kill_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 873 |
/* We don't bother with GENERIC_UNIT_LOAD or GENERIC_UNIT_VALIDATE_LOADED here, as it shouldn't |
| 874 |
* matter whether a unit is loaded for killing any processes in the unit's cgroup. */ |
| 875 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_kill, /* flags= */ 0); |
| 876 |
} |
| 877 |
|
| 878 |
static int method_kill_unit_subgroup(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 879 |
/* We don't bother with GENERIC_UNIT_LOAD or GENERIC_UNIT_VALIDATE_LOADED here, as it shouldn't |
| 880 |
* matter whether a unit is loaded for killing any processes in the unit's cgroup. */ |
| 881 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_kill_subgroup, /* flags= */ 0); |
| 882 |
} |
| 883 |
|
| 884 |
static int method_clean_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 885 |
/* Load the unit if necessary, in order to load it, and insist on the unit being loaded to be |
| 886 |
* cleaned */ |
| 887 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_clean, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); |
| 888 |
} |
| 889 |
|
| 890 |
static int method_freeze_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 891 |
/* Only active units can be frozen, which must be properly loaded already */ |
| 892 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_freeze, GENERIC_UNIT_VALIDATE_LOADED); |
| 893 |
} |
| 894 |
|
| 895 |
static int method_thaw_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 896 |
/* Same as freeze above */ |
| 897 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_thaw, GENERIC_UNIT_VALIDATE_LOADED); |
| 898 |
} |
| 899 |
|
| 900 |
static int method_reset_failed_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 901 |
/* Don't load the unit (because unloaded units can't be in failed state), and don't insist on the |
| 902 |
* unit to be loaded properly (since a failed unit might have its unit file disappeared) */ |
| 903 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_reset_failed, /* flags= */ 0); |
| 904 |
} |
| 905 |
|
| 906 |
static int method_set_unit_properties(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 907 |
/* Only change properties on fully loaded units, and load them in order to set properties */ |
| 908 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_set_properties, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); |
| 909 |
} |
| 910 |
|
| 911 |
static int method_bind_mount_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 912 |
/* Only add mounts on fully loaded units */ |
| 913 |
return method_generic_unit_operation(message, userdata, reterr_error, UNIT_SERVICE, bus_service_method_bind_mount, GENERIC_UNIT_VALIDATE_LOADED); |
| 914 |
} |
| 915 |
|
| 916 |
static int method_mount_image_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 917 |
/* Only add mounts on fully loaded units */ |
| 918 |
return method_generic_unit_operation(message, userdata, reterr_error, UNIT_SERVICE, bus_service_method_mount_image, GENERIC_UNIT_VALIDATE_LOADED); |
| 919 |
} |
| 920 |
|
| 921 |
static int method_ref_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 922 |
/* Only allow reffing of fully loaded units, and make sure reffing a unit loads it. */ |
| 923 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_ref, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); |
| 924 |
} |
| 925 |
|
| 926 |
static int method_unref_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 927 |
/* Dropping a ref OTOH should not require the unit to still be loaded. And since a reffed unit is a |
| 928 |
* loaded unit there's no need to load the unit for unreffing it. */ |
| 929 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_unref, /* flags= */ 0); |
| 930 |
} |
| 931 |
|
| 932 |
static int reply_unit_info(sd_bus_message *reply, Unit *u) { |
| 933 |
_cleanup_free_ char *unit_path = NULL, *job_path = NULL; |
| 934 |
Unit *following; |
| 935 |
|
| 936 |
following = unit_following(u); |
| 937 |
|
| 938 |
unit_path = unit_dbus_path(u); |
| 939 |
if (!unit_path) |
| 940 |
return -ENOMEM; |
| 941 |
|
| 942 |
if (u->job) { |
| 943 |
job_path = job_dbus_path(u->job); |
| 944 |
if (!job_path) |
| 945 |
return -ENOMEM; |
| 946 |
} |
| 947 |
|
| 948 |
return sd_bus_message_append( |
| 949 |
reply, "(ssssssouso)", |
| 950 |
u->id, |
| 951 |
unit_description(u), |
| 952 |
unit_load_state_to_string(u->load_state), |
| 953 |
unit_active_state_to_string(unit_active_state(u)), |
| 954 |
unit_sub_state_to_string(u), |
| 955 |
following ? following->id : "", |
| 956 |
unit_path, |
| 957 |
u->job ? u->job->id : 0, |
| 958 |
u->job ? job_type_to_string(u->job->type) : "", |
| 959 |
empty_to_root(job_path)); |
| 960 |
} |
| 961 |
|
| 962 |
static int method_list_units_by_names(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 963 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 964 |
Manager *m = ASSERT_PTR(userdata); |
| 965 |
int r; |
| 966 |
_cleanup_strv_free_ char **units = NULL; |
| 967 |
|
| 968 |
assert(message); |
| 969 |
|
| 970 |
r = sd_bus_message_read_strv(message, &units); |
| 971 |
if (r < 0) |
| 972 |
return r; |
| 973 |
|
| 974 |
if (strv_length(units) > MAX(hashmap_size(m->units), (unsigned) MANAGER_MAX_NAMES / 2)) |
| 975 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 976 |
"Too many unit names requested."); |
| 977 |
|
| 978 |
r = sd_bus_message_new_method_return(message, &reply); |
| 979 |
if (r < 0) |
| 980 |
return r; |
| 981 |
|
| 982 |
r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); |
| 983 |
if (r < 0) |
| 984 |
return r; |
| 985 |
|
| 986 |
STRV_FOREACH(unit, units) { |
| 987 |
Unit *u; |
| 988 |
|
| 989 |
if (!unit_name_is_valid(*unit, UNIT_NAME_ANY)) |
| 990 |
continue; |
| 991 |
|
| 992 |
r = bus_load_unit_by_name(m, message, *unit, &u, reterr_error); |
| 993 |
if (r < 0) |
| 994 |
return r; |
| 995 |
|
| 996 |
r = reply_unit_info(reply, u); |
| 997 |
if (r < 0) |
| 998 |
return r; |
| 999 |
} |
| 1000 |
|
| 1001 |
r = sd_bus_message_close_container(reply); |
| 1002 |
if (r < 0) |
| 1003 |
return r; |
| 1004 |
|
| 1005 |
return sd_bus_message_send(reply); |
| 1006 |
} |
| 1007 |
|
| 1008 |
static int method_get_unit_processes(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1009 |
/* Don't load a unit actively (since it won't have any processes if it's not loaded), but don't |
| 1010 |
* insist on the unit being loaded either (because even improperly loaded units might still have |
| 1011 |
* processes around). */ |
| 1012 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_get_processes, /* flags= */ 0); |
| 1013 |
} |
| 1014 |
|
| 1015 |
static int method_attach_processes_to_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1016 |
/* Don't allow attaching new processes to units that aren't loaded. Don't bother with loading a unit |
| 1017 |
* for this purpose though, as an unloaded unit is a stopped unit, and we don't allow attaching |
| 1018 |
* processes to stopped units anyway. */ |
| 1019 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_attach_processes, GENERIC_UNIT_VALIDATE_LOADED); |
| 1020 |
} |
| 1021 |
|
| 1022 |
static int method_remove_subgroup_from_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1023 |
/* Don't allow removal of subgroups from units that aren't loaded. But allow loading the unit, since |
| 1024 |
* this is clean-up work, that is OK to do when the unit is stopped already. */ |
| 1025 |
return method_generic_unit_operation(message, userdata, reterr_error, _UNIT_TYPE_INVALID, bus_unit_method_remove_subgroup, GENERIC_UNIT_LOAD|GENERIC_UNIT_VALIDATE_LOADED); |
| 1026 |
} |
| 1027 |
|
| 1028 |
static int transient_unit_from_message( |
| 1029 |
Manager *m, |
| 1030 |
sd_bus_message *message, |
| 1031 |
const char *name, |
| 1032 |
Unit **ret_unit, |
| 1033 |
sd_bus_error *reterr_error) { |
| 1034 |
|
| 1035 |
Unit *u; |
| 1036 |
int r; |
| 1037 |
|
| 1038 |
assert(m); |
| 1039 |
assert(message); |
| 1040 |
assert(name); |
| 1041 |
|
| 1042 |
r = manager_setup_transient_unit(m, name, &u, reterr_error); |
| 1043 |
if (r < 0) |
| 1044 |
return r; |
| 1045 |
|
| 1046 |
/* Set our properties */ |
| 1047 |
r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, reterr_error); |
| 1048 |
if (r < 0) |
| 1049 |
return r; |
| 1050 |
|
| 1051 |
/* If the client asked for it, automatically add a reference to this unit. */ |
| 1052 |
if (u->bus_track_add) { |
| 1053 |
r = bus_unit_track_add_sender(u, message); |
| 1054 |
if (r < 0) |
| 1055 |
return log_error_errno(r, "Failed to watch sender: %m"); |
| 1056 |
} |
| 1057 |
|
| 1058 |
/* Now load the missing bits of the unit we just created */ |
| 1059 |
unit_add_to_load_queue(u); |
| 1060 |
manager_dispatch_load_queue(m); |
| 1061 |
|
| 1062 |
if (ret_unit) |
| 1063 |
*ret_unit = u; |
| 1064 |
|
| 1065 |
return 0; |
| 1066 |
} |
| 1067 |
|
| 1068 |
static int transient_aux_units_from_message( |
| 1069 |
Manager *m, |
| 1070 |
sd_bus_message *message, |
| 1071 |
sd_bus_error *reterr_error) { |
| 1072 |
|
| 1073 |
int r; |
| 1074 |
|
| 1075 |
assert(m); |
| 1076 |
assert(message); |
| 1077 |
|
| 1078 |
r = sd_bus_message_enter_container(message, 'a', "(sa(sv))"); |
| 1079 |
if (r < 0) |
| 1080 |
return r; |
| 1081 |
|
| 1082 |
while ((r = sd_bus_message_enter_container(message, 'r', "sa(sv)")) > 0) { |
| 1083 |
const char *name; |
| 1084 |
|
| 1085 |
r = sd_bus_message_read(message, "s", &name); |
| 1086 |
if (r < 0) |
| 1087 |
return r; |
| 1088 |
|
| 1089 |
r = transient_unit_from_message(m, message, name, /* ret_unit= */ NULL, reterr_error); |
| 1090 |
if (r < 0) |
| 1091 |
return r; |
| 1092 |
|
| 1093 |
r = sd_bus_message_exit_container(message); |
| 1094 |
if (r < 0) |
| 1095 |
return r; |
| 1096 |
} |
| 1097 |
if (r < 0) |
| 1098 |
return r; |
| 1099 |
|
| 1100 |
r = sd_bus_message_exit_container(message); |
| 1101 |
if (r < 0) |
| 1102 |
return r; |
| 1103 |
|
| 1104 |
return 0; |
| 1105 |
} |
| 1106 |
|
| 1107 |
static int method_start_transient_unit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1108 |
const char *name, *smode; |
| 1109 |
Manager *m = ASSERT_PTR(userdata); |
| 1110 |
JobMode mode; |
| 1111 |
Unit *u; |
| 1112 |
int r; |
| 1113 |
|
| 1114 |
assert(message); |
| 1115 |
|
| 1116 |
r = mac_selinux_access_check(message, "start", reterr_error); |
| 1117 |
if (r < 0) |
| 1118 |
return r; |
| 1119 |
|
| 1120 |
r = sd_bus_message_read(message, "ss", &name, &smode); |
| 1121 |
if (r < 0) |
| 1122 |
return r; |
| 1123 |
|
| 1124 |
mode = job_mode_from_string(smode); |
| 1125 |
if (mode < 0) |
| 1126 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s is invalid.", smode); |
| 1127 |
|
| 1128 |
r = bus_verify_manage_units_async_impl( |
| 1129 |
m, |
| 1130 |
name, |
| 1131 |
"start", |
| 1132 |
N_("Authentication is required to start transient unit '$(unit)'."), |
| 1133 |
message, |
| 1134 |
reterr_error); |
| 1135 |
if (r < 0) |
| 1136 |
return r; |
| 1137 |
if (r == 0) |
| 1138 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 1139 |
|
| 1140 |
r = transient_unit_from_message(m, message, name, &u, reterr_error); |
| 1141 |
if (r < 0) |
| 1142 |
return r; |
| 1143 |
|
| 1144 |
r = transient_aux_units_from_message(m, message, reterr_error); |
| 1145 |
if (r < 0) |
| 1146 |
return r; |
| 1147 |
|
| 1148 |
/* Finally, start it */ |
| 1149 |
return bus_unit_queue_job(message, u, JOB_START, mode, 0, reterr_error); |
| 1150 |
} |
| 1151 |
|
| 1152 |
static int method_get_job(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1153 |
_cleanup_free_ char *path = NULL; |
| 1154 |
Manager *m = ASSERT_PTR(userdata); |
| 1155 |
uint32_t id; |
| 1156 |
Job *j; |
| 1157 |
int r; |
| 1158 |
|
| 1159 |
assert(message); |
| 1160 |
|
| 1161 |
/* Anyone can call this method */ |
| 1162 |
|
| 1163 |
r = sd_bus_message_read(message, "u", &id); |
| 1164 |
if (r < 0) |
| 1165 |
return r; |
| 1166 |
|
| 1167 |
j = manager_get_job(m, id); |
| 1168 |
if (!j) |
| 1169 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
| 1170 |
|
| 1171 |
r = mac_selinux_unit_access_check(j->unit, message, "status", reterr_error); |
| 1172 |
if (r < 0) |
| 1173 |
return r; |
| 1174 |
|
| 1175 |
path = job_dbus_path(j); |
| 1176 |
if (!path) |
| 1177 |
return -ENOMEM; |
| 1178 |
|
| 1179 |
return sd_bus_reply_method_return(message, "o", path); |
| 1180 |
} |
| 1181 |
|
| 1182 |
static int method_cancel_job(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1183 |
Manager *m = ASSERT_PTR(userdata); |
| 1184 |
uint32_t id; |
| 1185 |
Job *j; |
| 1186 |
int r; |
| 1187 |
|
| 1188 |
assert(message); |
| 1189 |
|
| 1190 |
r = sd_bus_message_read(message, "u", &id); |
| 1191 |
if (r < 0) |
| 1192 |
return r; |
| 1193 |
|
| 1194 |
j = manager_get_job(m, id); |
| 1195 |
if (!j) |
| 1196 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
| 1197 |
|
| 1198 |
return bus_job_method_cancel(message, j, reterr_error); |
| 1199 |
} |
| 1200 |
|
| 1201 |
static int method_clear_jobs(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1202 |
Manager *m = ASSERT_PTR(userdata); |
| 1203 |
int r; |
| 1204 |
|
| 1205 |
assert(message); |
| 1206 |
|
| 1207 |
r = mac_selinux_access_check(message, "reload", reterr_error); |
| 1208 |
if (r < 0) |
| 1209 |
return r; |
| 1210 |
|
| 1211 |
r = bus_verify_manage_units_async(m, message, reterr_error); |
| 1212 |
if (r < 0) |
| 1213 |
return r; |
| 1214 |
if (r == 0) |
| 1215 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 1216 |
|
| 1217 |
manager_clear_jobs(m); |
| 1218 |
|
| 1219 |
return sd_bus_reply_method_return(message, NULL); |
| 1220 |
} |
| 1221 |
|
| 1222 |
static int method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1223 |
Manager *m = ASSERT_PTR(userdata); |
| 1224 |
int r; |
| 1225 |
|
| 1226 |
assert(message); |
| 1227 |
|
| 1228 |
r = mac_selinux_access_check(message, "reload", reterr_error); |
| 1229 |
if (r < 0) |
| 1230 |
return r; |
| 1231 |
|
| 1232 |
r = bus_verify_manage_units_async(m, message, reterr_error); |
| 1233 |
if (r < 0) |
| 1234 |
return r; |
| 1235 |
if (r == 0) |
| 1236 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 1237 |
|
| 1238 |
manager_reset_failed(m); |
| 1239 |
|
| 1240 |
return sd_bus_reply_method_return(message, NULL); |
| 1241 |
} |
| 1242 |
|
| 1243 |
static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error, char **states, char **patterns) { |
| 1244 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 1245 |
Manager *m = ASSERT_PTR(userdata); |
| 1246 |
const char *k; |
| 1247 |
Unit *u; |
| 1248 |
int r; |
| 1249 |
|
| 1250 |
assert(message); |
| 1251 |
|
| 1252 |
/* Anyone can call this method */ |
| 1253 |
|
| 1254 |
if (strv_length(states) > MANAGER_MAX_STATES_PER_CALL) |
| 1255 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1256 |
"Too many states in a single query."); |
| 1257 |
|
| 1258 |
if (strv_length(patterns) > MANAGER_MAX_PATTERNS_PER_CALL) |
| 1259 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1260 |
"Too many patterns in a single query."); |
| 1261 |
|
| 1262 |
r = sd_bus_message_new_method_return(message, &reply); |
| 1263 |
if (r < 0) |
| 1264 |
return r; |
| 1265 |
|
| 1266 |
r = sd_bus_message_open_container(reply, 'a', "(ssssssouso)"); |
| 1267 |
if (r < 0) |
| 1268 |
return r; |
| 1269 |
|
| 1270 |
HASHMAP_FOREACH_KEY(u, k, m->units) { |
| 1271 |
if (k != u->id) |
| 1272 |
continue; |
| 1273 |
|
| 1274 |
r = mac_selinux_unit_access_check(u, message, "status", /* reterr_error= */ NULL); |
| 1275 |
if (r < 0) |
| 1276 |
continue; /* silently skip units the caller is not allowed to see */ |
| 1277 |
|
| 1278 |
if (!unit_passes_filter(u, states, patterns)) |
| 1279 |
continue; |
| 1280 |
|
| 1281 |
r = reply_unit_info(reply, u); |
| 1282 |
if (r < 0) |
| 1283 |
return r; |
| 1284 |
} |
| 1285 |
|
| 1286 |
r = sd_bus_message_close_container(reply); |
| 1287 |
if (r < 0) |
| 1288 |
return r; |
| 1289 |
|
| 1290 |
return sd_bus_message_send(reply); |
| 1291 |
} |
| 1292 |
|
| 1293 |
static int method_list_units(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1294 |
return list_units_filtered(message, userdata, reterr_error, NULL, NULL); |
| 1295 |
} |
| 1296 |
|
| 1297 |
static int method_list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1298 |
_cleanup_strv_free_ char **states = NULL; |
| 1299 |
int r; |
| 1300 |
|
| 1301 |
r = sd_bus_message_read_strv(message, &states); |
| 1302 |
if (r < 0) |
| 1303 |
return r; |
| 1304 |
|
| 1305 |
return list_units_filtered(message, userdata, reterr_error, states, NULL); |
| 1306 |
} |
| 1307 |
|
| 1308 |
static int method_list_units_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1309 |
_cleanup_strv_free_ char **states = NULL; |
| 1310 |
_cleanup_strv_free_ char **patterns = NULL; |
| 1311 |
int r; |
| 1312 |
|
| 1313 |
r = sd_bus_message_read_strv(message, &states); |
| 1314 |
if (r < 0) |
| 1315 |
return r; |
| 1316 |
|
| 1317 |
r = sd_bus_message_read_strv(message, &patterns); |
| 1318 |
if (r < 0) |
| 1319 |
return r; |
| 1320 |
|
| 1321 |
return list_units_filtered(message, userdata, reterr_error, states, patterns); |
| 1322 |
} |
| 1323 |
|
| 1324 |
static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1325 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 1326 |
Manager *m = ASSERT_PTR(userdata); |
| 1327 |
Job *j; |
| 1328 |
int r; |
| 1329 |
|
| 1330 |
assert(message); |
| 1331 |
|
| 1332 |
/* Anyone can call this method */ |
| 1333 |
|
| 1334 |
r = mac_selinux_access_check(message, "status", reterr_error); |
| 1335 |
if (r < 0) |
| 1336 |
return r; |
| 1337 |
|
| 1338 |
r = sd_bus_message_new_method_return(message, &reply); |
| 1339 |
if (r < 0) |
| 1340 |
return r; |
| 1341 |
|
| 1342 |
r = sd_bus_message_open_container(reply, 'a', "(usssoo)"); |
| 1343 |
if (r < 0) |
| 1344 |
return r; |
| 1345 |
|
| 1346 |
HASHMAP_FOREACH(j, m->jobs) { |
| 1347 |
_cleanup_free_ char *unit_path = NULL, *job_path = NULL; |
| 1348 |
|
| 1349 |
job_path = job_dbus_path(j); |
| 1350 |
if (!job_path) |
| 1351 |
return -ENOMEM; |
| 1352 |
|
| 1353 |
unit_path = unit_dbus_path(j->unit); |
| 1354 |
if (!unit_path) |
| 1355 |
return -ENOMEM; |
| 1356 |
|
| 1357 |
r = sd_bus_message_append( |
| 1358 |
reply, "(usssoo)", |
| 1359 |
j->id, |
| 1360 |
j->unit->id, |
| 1361 |
job_type_to_string(j->type), |
| 1362 |
job_state_to_string(j->state), |
| 1363 |
job_path, |
| 1364 |
unit_path); |
| 1365 |
if (r < 0) |
| 1366 |
return r; |
| 1367 |
} |
| 1368 |
|
| 1369 |
r = sd_bus_message_close_container(reply); |
| 1370 |
if (r < 0) |
| 1371 |
return r; |
| 1372 |
|
| 1373 |
return sd_bus_message_send(reply); |
| 1374 |
} |
| 1375 |
|
| 1376 |
static int method_subscribe(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1377 |
Manager *m = ASSERT_PTR(userdata); |
| 1378 |
int r; |
| 1379 |
|
| 1380 |
assert(message); |
| 1381 |
|
| 1382 |
/* Anyone can call this method */ |
| 1383 |
|
| 1384 |
r = mac_selinux_access_check(message, "status", reterr_error); |
| 1385 |
if (r < 0) |
| 1386 |
return r; |
| 1387 |
|
| 1388 |
if (sd_bus_message_get_bus(message) == m->api_bus) { |
| 1389 |
|
| 1390 |
/* Note that direct bus connection subscribe by |
| 1391 |
* default, we only track peers on the API bus here */ |
| 1392 |
|
| 1393 |
if (!m->subscribed) { |
| 1394 |
r = sd_bus_track_new(sd_bus_message_get_bus(message), &m->subscribed, NULL, NULL); |
| 1395 |
if (r < 0) |
| 1396 |
return r; |
| 1397 |
} |
| 1398 |
|
| 1399 |
r = sd_bus_track_add_sender(m->subscribed, message); |
| 1400 |
if (r < 0) |
| 1401 |
return r; |
| 1402 |
if (r == 0) |
| 1403 |
return sd_bus_error_set(reterr_error, BUS_ERROR_ALREADY_SUBSCRIBED, "Client is already subscribed."); |
| 1404 |
} |
| 1405 |
|
| 1406 |
return sd_bus_reply_method_return(message, NULL); |
| 1407 |
} |
| 1408 |
|
| 1409 |
static int method_unsubscribe(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1410 |
Manager *m = ASSERT_PTR(userdata); |
| 1411 |
int r; |
| 1412 |
|
| 1413 |
assert(message); |
| 1414 |
|
| 1415 |
/* Anyone can call this method */ |
| 1416 |
|
| 1417 |
r = mac_selinux_access_check(message, "status", reterr_error); |
| 1418 |
if (r < 0) |
| 1419 |
return r; |
| 1420 |
|
| 1421 |
if (sd_bus_message_get_bus(message) == m->api_bus) { |
| 1422 |
r = sd_bus_track_remove_sender(m->subscribed, message); |
| 1423 |
if (r < 0) |
| 1424 |
return r; |
| 1425 |
if (r == 0) |
| 1426 |
return sd_bus_error_set(reterr_error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed."); |
| 1427 |
} |
| 1428 |
|
| 1429 |
return sd_bus_reply_method_return(message, NULL); |
| 1430 |
} |
| 1431 |
|
| 1432 |
static int dump_impl( |
| 1433 |
sd_bus_message *message, |
| 1434 |
void *userdata, |
| 1435 |
sd_bus_error *reterr_error, |
| 1436 |
char **patterns, |
| 1437 |
int (*reply)(sd_bus_message *, char *)) { |
| 1438 |
|
| 1439 |
_cleanup_free_ char *dump = NULL; |
| 1440 |
Manager *m = ASSERT_PTR(userdata); |
| 1441 |
int r; |
| 1442 |
|
| 1443 |
assert(message); |
| 1444 |
|
| 1445 |
if (strv_length(patterns) > MANAGER_MAX_PATTERNS_PER_CALL) |
| 1446 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1447 |
"Too many patterns in a single query."); |
| 1448 |
|
| 1449 |
/* 'status' access is the bare minimum always needed for this, as the policy might straight out |
| 1450 |
* forbid a client from querying any information from systemd, regardless of any rate limiting. */ |
| 1451 |
r = mac_selinux_access_check(message, "status", reterr_error); |
| 1452 |
if (r < 0) |
| 1453 |
return r; |
| 1454 |
|
| 1455 |
/* Rate limit reached? Check if the caller is privileged/allowed by policy to bypass this. We |
| 1456 |
* check the rate limit first to avoid the expensive roundtrip to polkit when not needed. */ |
| 1457 |
if (!ratelimit_below(&m->dump_ratelimit)) { |
| 1458 |
/* We need a way for SELinux to constrain the operation when the rate limit is active, even |
| 1459 |
* if polkit would allow it, but we cannot easily add new named permissions, so we need to |
| 1460 |
* use an existing one. Reload/reexec are also slow but non-destructive/modifying |
| 1461 |
* operations, and can cause PID1 to stall. So it seems similar enough in terms of security |
| 1462 |
* considerations and impact, and thus use the same access check for dumps which, given the |
| 1463 |
* large amount of data to fetch, can stall PID1 for quite some time. */ |
| 1464 |
r = mac_selinux_access_check(message, "reload", /* error= */ NULL); |
| 1465 |
if (r < 0) |
| 1466 |
goto ratelimited; |
| 1467 |
|
| 1468 |
r = bus_verify_bypass_dump_ratelimit_async(m, message, /* reterr_error= */ NULL); |
| 1469 |
if (r < 0) |
| 1470 |
goto ratelimited; |
| 1471 |
if (r == 0) |
| 1472 |
/* No authorization for now, but the async polkit stuff will call us again when it |
| 1473 |
* has it */ |
| 1474 |
return 1; |
| 1475 |
} |
| 1476 |
|
| 1477 |
r = manager_get_dump_string(m, patterns, &dump); |
| 1478 |
if (r < 0) |
| 1479 |
return r; |
| 1480 |
|
| 1481 |
return reply(message, dump); |
| 1482 |
|
| 1483 |
ratelimited: |
| 1484 |
log_warning("Dump request rejected due to rate limit on unprivileged callers, blocked for %s.", |
| 1485 |
FORMAT_TIMESPAN(ratelimit_left(&m->dump_ratelimit), USEC_PER_SEC)); |
| 1486 |
return sd_bus_error_setf(reterr_error, |
| 1487 |
SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1488 |
"Dump request rejected due to rate limit on unprivileged callers, blocked for %s.", |
| 1489 |
FORMAT_TIMESPAN(ratelimit_left(&m->dump_ratelimit), USEC_PER_SEC)); |
| 1490 |
} |
| 1491 |
|
| 1492 |
static int reply_dump(sd_bus_message *message, char *dump) { |
| 1493 |
return sd_bus_reply_method_return(message, "s", dump); |
| 1494 |
} |
| 1495 |
|
| 1496 |
static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1497 |
return dump_impl(message, userdata, reterr_error, NULL, reply_dump); |
| 1498 |
} |
| 1499 |
|
| 1500 |
static int reply_dump_by_fd(sd_bus_message *message, char *dump) { |
| 1501 |
_cleanup_close_ int fd = -EBADF; |
| 1502 |
|
| 1503 |
fd = memfd_new_and_seal_string("dump", dump); |
| 1504 |
if (fd < 0) |
| 1505 |
return fd; |
| 1506 |
|
| 1507 |
return sd_bus_reply_method_return(message, "h", fd); |
| 1508 |
} |
| 1509 |
|
| 1510 |
static int method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1511 |
return dump_impl(message, userdata, reterr_error, NULL, reply_dump_by_fd); |
| 1512 |
} |
| 1513 |
|
| 1514 |
static int dump_units_matching_patterns( |
| 1515 |
sd_bus_message *message, |
| 1516 |
void *userdata, |
| 1517 |
sd_bus_error *reterr_error, |
| 1518 |
int (*reply)(sd_bus_message *, char *)) { |
| 1519 |
_cleanup_strv_free_ char **patterns = NULL; |
| 1520 |
int r; |
| 1521 |
|
| 1522 |
r = sd_bus_message_read_strv(message, &patterns); |
| 1523 |
if (r < 0) |
| 1524 |
return r; |
| 1525 |
|
| 1526 |
return dump_impl(message, userdata, reterr_error, patterns, reply); |
| 1527 |
} |
| 1528 |
|
| 1529 |
static int method_dump_units_matching_patterns(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1530 |
return dump_units_matching_patterns(message, userdata, reterr_error, reply_dump); |
| 1531 |
} |
| 1532 |
|
| 1533 |
static int method_dump_units_matching_patterns_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1534 |
return dump_units_matching_patterns(message, userdata, reterr_error, reply_dump_by_fd); |
| 1535 |
} |
| 1536 |
|
| 1537 |
static int method_refuse_snapshot(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1538 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for snapshots has been removed."); |
| 1539 |
} |
| 1540 |
|
| 1541 |
static void log_caller(sd_bus_message *message, Manager *manager, const char *method) { |
| 1542 |
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
| 1543 |
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
| 1544 |
int r; |
| 1545 |
|
| 1546 |
assert(message); |
| 1547 |
assert(manager); |
| 1548 |
assert(method); |
| 1549 |
|
| 1550 |
r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID|SD_BUS_CREDS_PIDFD|SD_BUS_CREDS_AUGMENT, &creds); |
| 1551 |
if (r < 0) |
| 1552 |
log_debug_errno(r, "Failed to get dbus sender creds, ignoring: %m"); |
| 1553 |
else { |
| 1554 |
r = bus_creds_get_pidref(creds, &pidref); |
| 1555 |
if (r < 0) |
| 1556 |
log_debug_errno(r, "Failed to get peer pidref, ignoring: %m"); |
| 1557 |
} |
| 1558 |
|
| 1559 |
manager_log_caller(manager, &pidref, method); |
| 1560 |
} |
| 1561 |
|
| 1562 |
static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1563 |
Manager *m = ASSERT_PTR(userdata); |
| 1564 |
int r; |
| 1565 |
|
| 1566 |
assert(message); |
| 1567 |
|
| 1568 |
r = mac_selinux_access_check(message, "reload", reterr_error); |
| 1569 |
if (r < 0) |
| 1570 |
return r; |
| 1571 |
|
| 1572 |
r = bus_verify_reload_daemon_async(m, message, reterr_error); |
| 1573 |
if (r < 0) |
| 1574 |
return r; |
| 1575 |
if (r == 0) |
| 1576 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 1577 |
|
| 1578 |
/* Write a log message noting the unit or process who requested the Reload() */ |
| 1579 |
log_caller(message, m, "Reload"); |
| 1580 |
|
| 1581 |
/* Check the rate limit after the authorization succeeds, to avoid denial-of-service issues. */ |
| 1582 |
if (!ratelimit_below(&m->reload_reexec_ratelimit)) { |
| 1583 |
log_warning("Reloading request rejected due to rate limit."); |
| 1584 |
return sd_bus_error_set(reterr_error, |
| 1585 |
SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1586 |
"Reload() request rejected due to rate limit."); |
| 1587 |
} |
| 1588 |
|
| 1589 |
/* Instead of sending the reply back right away, we just |
| 1590 |
* remember that we need to and then send it after the reload |
| 1591 |
* is finished. That way the caller knows when the reload |
| 1592 |
* finished. */ |
| 1593 |
|
| 1594 |
assert(!m->pending_reload_message_dbus); |
| 1595 |
assert(!m->pending_reload_message_vl); |
| 1596 |
r = sd_bus_message_new_method_return(message, &m->pending_reload_message_dbus); |
| 1597 |
if (r < 0) |
| 1598 |
return r; |
| 1599 |
|
| 1600 |
m->objective = MANAGER_RELOAD; |
| 1601 |
|
| 1602 |
return 1; |
| 1603 |
} |
| 1604 |
|
| 1605 |
static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1606 |
Manager *m = ASSERT_PTR(userdata); |
| 1607 |
int r; |
| 1608 |
|
| 1609 |
assert(message); |
| 1610 |
|
| 1611 |
r = mac_selinux_access_check(message, "reload", reterr_error); |
| 1612 |
if (r < 0) |
| 1613 |
return r; |
| 1614 |
|
| 1615 |
r = bus_verify_reload_daemon_async(m, message, reterr_error); |
| 1616 |
if (r < 0) |
| 1617 |
return r; |
| 1618 |
if (r == 0) |
| 1619 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 1620 |
|
| 1621 |
/* Write a log message noting the unit or process who requested the Reexecute() */ |
| 1622 |
log_caller(message, m, "Reexecution"); |
| 1623 |
|
| 1624 |
/* Check the rate limit after the authorization succeeds, to avoid denial-of-service issues. */ |
| 1625 |
if (!ratelimit_below(&m->reload_reexec_ratelimit)) { |
| 1626 |
log_warning("Reexecution request rejected due to rate limit."); |
| 1627 |
return sd_bus_error_set(reterr_error, |
| 1628 |
SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1629 |
"Reexecute() request rejected due to rate limit."); |
| 1630 |
} |
| 1631 |
|
| 1632 |
/* We don't send a reply back here, the client should |
| 1633 |
* just wait for us disconnecting. */ |
| 1634 |
|
| 1635 |
m->objective = MANAGER_REEXECUTE; |
| 1636 |
return 1; |
| 1637 |
} |
| 1638 |
|
| 1639 |
static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1640 |
Manager *m = ASSERT_PTR(userdata); |
| 1641 |
int r; |
| 1642 |
|
| 1643 |
assert(message); |
| 1644 |
|
| 1645 |
r = mac_selinux_access_check(message, "halt", reterr_error); |
| 1646 |
if (r < 0) |
| 1647 |
return r; |
| 1648 |
|
| 1649 |
log_caller(message, m, "Exit"); |
| 1650 |
|
| 1651 |
/* Exit() (in contrast to SetExitCode()) is actually allowed even if |
| 1652 |
* we are running on the host. It will fall back on reboot() in |
| 1653 |
* systemd-shutdown if it cannot do the exit() because it isn't a |
| 1654 |
* container. */ |
| 1655 |
|
| 1656 |
m->objective = MANAGER_EXIT; |
| 1657 |
|
| 1658 |
return sd_bus_reply_method_return(message, NULL); |
| 1659 |
} |
| 1660 |
|
| 1661 |
static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1662 |
Manager *m = ASSERT_PTR(userdata); |
| 1663 |
int r; |
| 1664 |
|
| 1665 |
assert(message); |
| 1666 |
|
| 1667 |
if (!MANAGER_IS_SYSTEM(m)) |
| 1668 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 1669 |
"Reboot is only supported by system manager."); |
| 1670 |
|
| 1671 |
r = mac_selinux_access_check(message, "reboot", reterr_error); |
| 1672 |
if (r < 0) |
| 1673 |
return r; |
| 1674 |
|
| 1675 |
log_caller(message, m, "Reboot"); |
| 1676 |
|
| 1677 |
m->objective = MANAGER_REBOOT; |
| 1678 |
|
| 1679 |
return sd_bus_reply_method_return(message, NULL); |
| 1680 |
} |
| 1681 |
|
| 1682 |
static int method_soft_reboot(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1683 |
Manager *m = ASSERT_PTR(userdata); |
| 1684 |
_cleanup_free_ char *rt = NULL; |
| 1685 |
const char *root; |
| 1686 |
int r; |
| 1687 |
|
| 1688 |
assert(message); |
| 1689 |
|
| 1690 |
if (!MANAGER_IS_SYSTEM(m)) |
| 1691 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 1692 |
"Soft reboot is only supported by system manager."); |
| 1693 |
|
| 1694 |
/* Keep the checks in sync with varlink-manager.c:vl_method_soft_reboot_manager() */ |
| 1695 |
r = mac_selinux_access_check(message, "reboot", reterr_error); |
| 1696 |
if (r < 0) |
| 1697 |
return r; |
| 1698 |
|
| 1699 |
r = sd_bus_message_read(message, "s", &root); |
| 1700 |
if (r < 0) |
| 1701 |
return r; |
| 1702 |
|
| 1703 |
if (!isempty(root)) { |
| 1704 |
if (!path_is_valid(root)) |
| 1705 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1706 |
"New root directory '%s' must be a valid path.", root); |
| 1707 |
if (!path_is_absolute(root)) |
| 1708 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1709 |
"New root directory path '%s' is not absolute.", root); |
| 1710 |
|
| 1711 |
r = path_simplify_alloc(root, &rt); |
| 1712 |
if (r < 0) |
| 1713 |
return r; |
| 1714 |
} |
| 1715 |
|
| 1716 |
log_caller(message, m, "Soft reboot"); |
| 1717 |
|
| 1718 |
free_and_replace(m->switch_root, rt); |
| 1719 |
m->objective = MANAGER_SOFT_REBOOT; |
| 1720 |
|
| 1721 |
return sd_bus_reply_method_return(message, NULL); |
| 1722 |
} |
| 1723 |
|
| 1724 |
static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1725 |
Manager *m = ASSERT_PTR(userdata); |
| 1726 |
int r; |
| 1727 |
|
| 1728 |
assert(message); |
| 1729 |
|
| 1730 |
if (!MANAGER_IS_SYSTEM(m)) |
| 1731 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 1732 |
"Powering off is only supported by system manager."); |
| 1733 |
|
| 1734 |
r = mac_selinux_access_check(message, "halt", reterr_error); |
| 1735 |
if (r < 0) |
| 1736 |
return r; |
| 1737 |
|
| 1738 |
log_caller(message, m, "Poweroff"); |
| 1739 |
|
| 1740 |
m->objective = MANAGER_POWEROFF; |
| 1741 |
|
| 1742 |
return sd_bus_reply_method_return(message, NULL); |
| 1743 |
} |
| 1744 |
|
| 1745 |
static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1746 |
Manager *m = ASSERT_PTR(userdata); |
| 1747 |
int r; |
| 1748 |
|
| 1749 |
assert(message); |
| 1750 |
|
| 1751 |
if (!MANAGER_IS_SYSTEM(m)) |
| 1752 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 1753 |
"Halt is only supported by system manager."); |
| 1754 |
|
| 1755 |
r = mac_selinux_access_check(message, "halt", reterr_error); |
| 1756 |
if (r < 0) |
| 1757 |
return r; |
| 1758 |
|
| 1759 |
log_caller(message, m, "Halt"); |
| 1760 |
|
| 1761 |
m->objective = MANAGER_HALT; |
| 1762 |
|
| 1763 |
return sd_bus_reply_method_return(message, NULL); |
| 1764 |
} |
| 1765 |
|
| 1766 |
static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1767 |
Manager *m = ASSERT_PTR(userdata); |
| 1768 |
int r; |
| 1769 |
|
| 1770 |
assert(message); |
| 1771 |
|
| 1772 |
if (!MANAGER_IS_SYSTEM(m)) |
| 1773 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 1774 |
"KExec is only supported by system manager."); |
| 1775 |
|
| 1776 |
r = mac_selinux_access_check(message, "reboot", reterr_error); |
| 1777 |
if (r < 0) |
| 1778 |
return r; |
| 1779 |
|
| 1780 |
log_caller(message, m, "Kexec"); |
| 1781 |
|
| 1782 |
m->objective = MANAGER_KEXEC; |
| 1783 |
|
| 1784 |
return sd_bus_reply_method_return(message, NULL); |
| 1785 |
} |
| 1786 |
|
| 1787 |
static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1788 |
Manager *m = ASSERT_PTR(userdata); |
| 1789 |
_cleanup_free_ char *ri = NULL, *rt = NULL; |
| 1790 |
const char *root, *init; |
| 1791 |
int r; |
| 1792 |
|
| 1793 |
assert(message); |
| 1794 |
|
| 1795 |
if (!MANAGER_IS_SYSTEM(m)) |
| 1796 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 1797 |
"Root switching is only supported by system manager."); |
| 1798 |
|
| 1799 |
r = mac_selinux_access_check(message, "reboot", reterr_error); |
| 1800 |
if (r < 0) |
| 1801 |
return r; |
| 1802 |
|
| 1803 |
r = sd_bus_message_read(message, "ss", &root, &init); |
| 1804 |
if (r < 0) |
| 1805 |
return r; |
| 1806 |
|
| 1807 |
if (isempty(root)) |
| 1808 |
/* If path is not specified, default to "/sysroot" which is what we generally expect initrds |
| 1809 |
* to use */ |
| 1810 |
root = "/sysroot"; |
| 1811 |
else { |
| 1812 |
if (!path_is_valid(root)) |
| 1813 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1814 |
"New root directory must be a valid path."); |
| 1815 |
|
| 1816 |
if (!path_is_absolute(root)) |
| 1817 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1818 |
"New root path '%s' is not absolute.", root); |
| 1819 |
|
| 1820 |
r = path_is_root(root); |
| 1821 |
if (r < 0) |
| 1822 |
return sd_bus_error_set_errnof(reterr_error, r, |
| 1823 |
"Failed to check if new root directory '%s' is the same as old root: %m", |
| 1824 |
root); |
| 1825 |
if (r > 0) |
| 1826 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1827 |
"New root directory cannot be the old root directory."); |
| 1828 |
} |
| 1829 |
|
| 1830 |
/* Safety check */ |
| 1831 |
if (!in_initrd()) |
| 1832 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1833 |
"Not in initrd, refusing switch-root operation."); |
| 1834 |
|
| 1835 |
r = path_is_os_tree(root); |
| 1836 |
if (r < 0) |
| 1837 |
return sd_bus_error_set_errnof(reterr_error, r, |
| 1838 |
"Failed to determine whether root path '%s' contains an OS tree: %m", |
| 1839 |
root); |
| 1840 |
if (r == 0) |
| 1841 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1842 |
"Specified switch root path '%s' does not seem to be an OS tree. os-release file is missing.", |
| 1843 |
root); |
| 1844 |
|
| 1845 |
if (!isempty(init)) { |
| 1846 |
if (!path_is_valid(init)) |
| 1847 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1848 |
"Path to init binary '%s' is not a valid path.", init); |
| 1849 |
|
| 1850 |
if (!path_is_absolute(init)) |
| 1851 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1852 |
"Path to init binary '%s' not absolute.", init); |
| 1853 |
|
| 1854 |
r = chase_and_access(init, root, CHASE_PREFIX_ROOT, X_OK, NULL); |
| 1855 |
if (r == -EACCES) |
| 1856 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1857 |
"Init binary %s is not executable.", init); |
| 1858 |
if (r < 0) |
| 1859 |
return sd_bus_error_set_errnof(reterr_error, r, |
| 1860 |
"Could not resolve init executable %s: %m", init); |
| 1861 |
} |
| 1862 |
|
| 1863 |
r = path_simplify_alloc(root, &rt); |
| 1864 |
if (r < 0) |
| 1865 |
return r; |
| 1866 |
|
| 1867 |
if (!isempty(init)) { |
| 1868 |
r = path_simplify_alloc(init, &ri); |
| 1869 |
if (r < 0) |
| 1870 |
return r; |
| 1871 |
} |
| 1872 |
|
| 1873 |
free_and_replace(m->switch_root, rt); |
| 1874 |
free_and_replace(m->switch_root_init, ri); |
| 1875 |
|
| 1876 |
m->objective = MANAGER_SWITCH_ROOT; |
| 1877 |
|
| 1878 |
return sd_bus_reply_method_return(message, NULL); |
| 1879 |
} |
| 1880 |
|
| 1881 |
static int method_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1882 |
_cleanup_strv_free_ char **plus = NULL; |
| 1883 |
Manager *m = ASSERT_PTR(userdata); |
| 1884 |
int r; |
| 1885 |
|
| 1886 |
assert(message); |
| 1887 |
|
| 1888 |
r = mac_selinux_access_check(message, "reload", reterr_error); |
| 1889 |
if (r < 0) |
| 1890 |
return r; |
| 1891 |
|
| 1892 |
r = sd_bus_message_read_strv(message, &plus); |
| 1893 |
if (r < 0) |
| 1894 |
return r; |
| 1895 |
|
| 1896 |
if (strv_length(plus) > ENVIRONMENT_ASSIGNMENTS_MAX) |
| 1897 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1898 |
"Too many environment assignments in a single query."); |
| 1899 |
if (!strv_env_is_valid(plus)) |
| 1900 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment assignments"); |
| 1901 |
|
| 1902 |
r = bus_verify_set_environment_async(m, message, reterr_error); |
| 1903 |
if (r < 0) |
| 1904 |
return r; |
| 1905 |
if (r == 0) |
| 1906 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 1907 |
|
| 1908 |
r = manager_client_environment_modify(m, NULL, plus); |
| 1909 |
if (r < 0) |
| 1910 |
return r; |
| 1911 |
|
| 1912 |
return sd_bus_reply_method_return(message, NULL); |
| 1913 |
} |
| 1914 |
|
| 1915 |
static int method_unset_environment(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1916 |
_cleanup_strv_free_ char **minus = NULL; |
| 1917 |
Manager *m = ASSERT_PTR(userdata); |
| 1918 |
int r; |
| 1919 |
|
| 1920 |
assert(message); |
| 1921 |
|
| 1922 |
r = mac_selinux_access_check(message, "reload", reterr_error); |
| 1923 |
if (r < 0) |
| 1924 |
return r; |
| 1925 |
|
| 1926 |
r = sd_bus_message_read_strv(message, &minus); |
| 1927 |
if (r < 0) |
| 1928 |
return r; |
| 1929 |
|
| 1930 |
if (strv_length(minus) > ENVIRONMENT_ASSIGNMENTS_MAX) |
| 1931 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1932 |
"Too many environment variable names in a single query."); |
| 1933 |
if (!strv_env_name_or_assignment_is_valid(minus)) |
| 1934 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1935 |
"Invalid environment variable names or assignments"); |
| 1936 |
|
| 1937 |
r = bus_verify_set_environment_async(m, message, reterr_error); |
| 1938 |
if (r < 0) |
| 1939 |
return r; |
| 1940 |
if (r == 0) |
| 1941 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 1942 |
|
| 1943 |
r = manager_client_environment_modify(m, minus, NULL); |
| 1944 |
if (r < 0) |
| 1945 |
return r; |
| 1946 |
|
| 1947 |
return sd_bus_reply_method_return(message, NULL); |
| 1948 |
} |
| 1949 |
|
| 1950 |
static int method_unset_and_set_environment(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1951 |
_cleanup_strv_free_ char **minus = NULL, **plus = NULL; |
| 1952 |
Manager *m = ASSERT_PTR(userdata); |
| 1953 |
int r; |
| 1954 |
|
| 1955 |
assert(message); |
| 1956 |
|
| 1957 |
r = mac_selinux_access_check(message, "reload", reterr_error); |
| 1958 |
if (r < 0) |
| 1959 |
return r; |
| 1960 |
|
| 1961 |
r = sd_bus_message_read_strv(message, &minus); |
| 1962 |
if (r < 0) |
| 1963 |
return r; |
| 1964 |
|
| 1965 |
r = sd_bus_message_read_strv(message, &plus); |
| 1966 |
if (r < 0) |
| 1967 |
return r; |
| 1968 |
|
| 1969 |
if (strv_length(plus) > ENVIRONMENT_ASSIGNMENTS_MAX || strv_length(minus) > ENVIRONMENT_ASSIGNMENTS_MAX) |
| 1970 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 1971 |
"Too many environment variable names or assignments in a single query."); |
| 1972 |
if (!strv_env_name_or_assignment_is_valid(minus)) |
| 1973 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1974 |
"Invalid environment variable names or assignments"); |
| 1975 |
if (!strv_env_is_valid(plus)) |
| 1976 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 1977 |
"Invalid environment assignments"); |
| 1978 |
|
| 1979 |
r = bus_verify_set_environment_async(m, message, reterr_error); |
| 1980 |
if (r < 0) |
| 1981 |
return r; |
| 1982 |
if (r == 0) |
| 1983 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 1984 |
|
| 1985 |
r = manager_client_environment_modify(m, minus, plus); |
| 1986 |
if (r < 0) |
| 1987 |
return r; |
| 1988 |
|
| 1989 |
return sd_bus_reply_method_return(message, NULL); |
| 1990 |
} |
| 1991 |
|
| 1992 |
static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 1993 |
Manager *m = ASSERT_PTR(userdata); |
| 1994 |
uint8_t code; |
| 1995 |
int r; |
| 1996 |
|
| 1997 |
assert(message); |
| 1998 |
|
| 1999 |
r = mac_selinux_access_check(message, "exit", reterr_error); |
| 2000 |
if (r < 0) |
| 2001 |
return r; |
| 2002 |
|
| 2003 |
r = sd_bus_message_read_basic(message, 'y', &code); |
| 2004 |
if (r < 0) |
| 2005 |
return r; |
| 2006 |
|
| 2007 |
m->return_value = code; |
| 2008 |
|
| 2009 |
return sd_bus_reply_method_return(message, NULL); |
| 2010 |
} |
| 2011 |
|
| 2012 |
static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2013 |
Manager *m = ASSERT_PTR(userdata); |
| 2014 |
const char *name; |
| 2015 |
uid_t uid; |
| 2016 |
int r; |
| 2017 |
|
| 2018 |
assert(message); |
| 2019 |
|
| 2020 |
r = sd_bus_message_read_basic(message, 's', &name); |
| 2021 |
if (r < 0) |
| 2022 |
return r; |
| 2023 |
|
| 2024 |
if (!MANAGER_IS_SYSTEM(m)) |
| 2025 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 2026 |
"Dynamic users are only supported in the system instance."); |
| 2027 |
if (!valid_user_group_name(name, VALID_USER_RELAX)) |
| 2028 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 2029 |
"User name invalid: %s", name); |
| 2030 |
|
| 2031 |
r = dynamic_user_lookup_name(m, name, &uid); |
| 2032 |
if (r == -ESRCH) |
| 2033 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, |
| 2034 |
"Dynamic user %s does not exist.", name); |
| 2035 |
if (r < 0) |
| 2036 |
return r; |
| 2037 |
|
| 2038 |
return sd_bus_reply_method_return(message, "u", (uint32_t) uid); |
| 2039 |
} |
| 2040 |
|
| 2041 |
static int method_lookup_dynamic_user_by_uid(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2042 |
_cleanup_free_ char *name = NULL; |
| 2043 |
Manager *m = ASSERT_PTR(userdata); |
| 2044 |
uid_t uid; |
| 2045 |
int r; |
| 2046 |
|
| 2047 |
assert(message); |
| 2048 |
|
| 2049 |
assert_cc(sizeof(uid_t) == sizeof(uint32_t)); |
| 2050 |
r = sd_bus_message_read_basic(message, 'u', &uid); |
| 2051 |
if (r < 0) |
| 2052 |
return r; |
| 2053 |
|
| 2054 |
if (!MANAGER_IS_SYSTEM(m)) |
| 2055 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 2056 |
"Dynamic users are only supported in the system instance."); |
| 2057 |
if (!uid_is_valid(uid)) |
| 2058 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 2059 |
"User ID invalid: " UID_FMT, uid); |
| 2060 |
|
| 2061 |
r = dynamic_user_lookup_uid(m, uid, &name); |
| 2062 |
if (r == -ESRCH) |
| 2063 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_DYNAMIC_USER, |
| 2064 |
"Dynamic user ID " UID_FMT " does not exist.", uid); |
| 2065 |
if (r < 0) |
| 2066 |
return r; |
| 2067 |
|
| 2068 |
return sd_bus_reply_method_return(message, "s", name); |
| 2069 |
} |
| 2070 |
|
| 2071 |
static int method_get_dynamic_users(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2072 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 2073 |
Manager *m = ASSERT_PTR(userdata); |
| 2074 |
DynamicUser *d; |
| 2075 |
int r; |
| 2076 |
|
| 2077 |
assert(message); |
| 2078 |
|
| 2079 |
assert_cc(sizeof(uid_t) == sizeof(uint32_t)); |
| 2080 |
|
| 2081 |
if (!MANAGER_IS_SYSTEM(m)) |
| 2082 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, |
| 2083 |
"Dynamic users are only supported in the system instance."); |
| 2084 |
|
| 2085 |
r = sd_bus_message_new_method_return(message, &reply); |
| 2086 |
if (r < 0) |
| 2087 |
return r; |
| 2088 |
|
| 2089 |
r = sd_bus_message_open_container(reply, 'a', "(us)"); |
| 2090 |
if (r < 0) |
| 2091 |
return r; |
| 2092 |
|
| 2093 |
HASHMAP_FOREACH(d, m->dynamic_users) { |
| 2094 |
uid_t uid; |
| 2095 |
|
| 2096 |
r = dynamic_user_current(d, &uid); |
| 2097 |
if (r == -EAGAIN) /* not realized yet? */ |
| 2098 |
continue; |
| 2099 |
if (r < 0) |
| 2100 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_FAILED, |
| 2101 |
"Failed to look up a dynamic user."); |
| 2102 |
|
| 2103 |
r = sd_bus_message_append(reply, "(us)", uid, d->name); |
| 2104 |
if (r < 0) |
| 2105 |
return r; |
| 2106 |
} |
| 2107 |
|
| 2108 |
r = sd_bus_message_close_container(reply); |
| 2109 |
if (r < 0) |
| 2110 |
return r; |
| 2111 |
|
| 2112 |
return sd_bus_message_send(reply); |
| 2113 |
} |
| 2114 |
|
| 2115 |
static int method_enqueue_marked_jobs(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2116 |
Manager *m = ASSERT_PTR(userdata); |
| 2117 |
int r; |
| 2118 |
|
| 2119 |
assert(message); |
| 2120 |
|
| 2121 |
r = mac_selinux_access_check(message, "start", reterr_error); |
| 2122 |
if (r < 0) |
| 2123 |
return r; |
| 2124 |
|
| 2125 |
r = bus_verify_manage_units_async(m, message, reterr_error); |
| 2126 |
if (r < 0) |
| 2127 |
return r; |
| 2128 |
if (r == 0) |
| 2129 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2130 |
|
| 2131 |
log_info("Queuing reload/restart jobs for marked units%s", glyph(GLYPH_ELLIPSIS)); |
| 2132 |
|
| 2133 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 2134 |
r = sd_bus_message_new_method_return(message, &reply); |
| 2135 |
if (r < 0) |
| 2136 |
return r; |
| 2137 |
|
| 2138 |
r = sd_bus_message_open_container(reply, 'a', "o"); |
| 2139 |
if (r < 0) |
| 2140 |
return r; |
| 2141 |
|
| 2142 |
Unit *u; |
| 2143 |
char *k; |
| 2144 |
int ret = 0; |
| 2145 |
HASHMAP_FOREACH_KEY(u, k, m->units) { |
| 2146 |
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
| 2147 |
|
| 2148 |
/* ignore aliases */ |
| 2149 |
if (u->id != k) |
| 2150 |
continue; |
| 2151 |
|
| 2152 |
BusUnitQueueFlags flags; |
| 2153 |
JobType job; |
| 2154 |
if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_RESTART)) { |
| 2155 |
flags = 0; |
| 2156 |
job = JOB_TRY_RESTART; |
| 2157 |
} else if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_RELOAD)) { |
| 2158 |
flags = BUS_UNIT_QUEUE_RELOAD_IF_POSSIBLE; |
| 2159 |
job = JOB_TRY_RESTART; |
| 2160 |
} else if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_STOP)) { |
| 2161 |
flags = 0; |
| 2162 |
job = JOB_STOP; |
| 2163 |
} else if (BIT_SET(u->markers, UNIT_MARKER_NEEDS_START)) { |
| 2164 |
flags = 0; |
| 2165 |
job = JOB_START; |
| 2166 |
} else |
| 2167 |
continue; |
| 2168 |
|
| 2169 |
r = mac_selinux_unit_access_check(u, message, job_type_to_access_method(job), &error); |
| 2170 |
if (r >= 0) |
| 2171 |
r = bus_unit_queue_job_one(message, u, |
| 2172 |
job, JOB_FAIL, flags, |
| 2173 |
reply, &error); |
| 2174 |
if (ERRNO_IS_NEG_RESOURCE(r)) |
| 2175 |
return r; |
| 2176 |
if (r < 0) |
| 2177 |
RET_GATHER(ret, log_unit_warning_errno(u, r, "Failed to enqueue marked job: %s", |
| 2178 |
bus_error_message(&error, r))); |
| 2179 |
} |
| 2180 |
|
| 2181 |
if (ret < 0) |
| 2182 |
return sd_bus_error_set_errnof(reterr_error, ret, |
| 2183 |
"Failed to enqueue some jobs, see logs for details: %m"); |
| 2184 |
|
| 2185 |
r = sd_bus_message_close_container(reply); |
| 2186 |
if (r < 0) |
| 2187 |
return r; |
| 2188 |
|
| 2189 |
return sd_bus_message_send(reply); |
| 2190 |
} |
| 2191 |
|
| 2192 |
static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error, char **states, char **patterns) { |
| 2193 |
Manager *m = ASSERT_PTR(userdata); |
| 2194 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 2195 |
_cleanup_hashmap_free_ Hashmap *h = NULL; |
| 2196 |
int r; |
| 2197 |
|
| 2198 |
assert(message); |
| 2199 |
|
| 2200 |
/* Anyone can call this method */ |
| 2201 |
|
| 2202 |
if (strv_length(states) > MANAGER_MAX_STATES_PER_CALL) |
| 2203 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 2204 |
"Too many states in a single query."); |
| 2205 |
|
| 2206 |
if (strv_length(patterns) > MANAGER_MAX_PATTERNS_PER_CALL) |
| 2207 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, |
| 2208 |
"Too many patterns in a single query."); |
| 2209 |
|
| 2210 |
r = mac_selinux_access_check(message, "status", reterr_error); |
| 2211 |
if (r < 0) |
| 2212 |
return r; |
| 2213 |
|
| 2214 |
r = sd_bus_message_new_method_return(message, &reply); |
| 2215 |
if (r < 0) |
| 2216 |
return r; |
| 2217 |
|
| 2218 |
r = unit_file_get_list(m->runtime_scope, /* root_dir= */ NULL, states, patterns, &h); |
| 2219 |
if (r < 0) |
| 2220 |
return r; |
| 2221 |
|
| 2222 |
r = sd_bus_message_open_container(reply, 'a', "(ss)"); |
| 2223 |
if (r < 0) |
| 2224 |
return r; |
| 2225 |
|
| 2226 |
UnitFileList *item; |
| 2227 |
HASHMAP_FOREACH(item, h) { |
| 2228 |
r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state)); |
| 2229 |
if (r < 0) |
| 2230 |
return r; |
| 2231 |
} |
| 2232 |
|
| 2233 |
r = sd_bus_message_close_container(reply); |
| 2234 |
if (r < 0) |
| 2235 |
return r; |
| 2236 |
|
| 2237 |
return sd_bus_message_send(reply); |
| 2238 |
} |
| 2239 |
|
| 2240 |
static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2241 |
return list_unit_files_by_patterns(message, userdata, reterr_error, NULL, NULL); |
| 2242 |
} |
| 2243 |
|
| 2244 |
static int method_list_unit_files_by_patterns(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2245 |
_cleanup_strv_free_ char **states = NULL; |
| 2246 |
_cleanup_strv_free_ char **patterns = NULL; |
| 2247 |
int r; |
| 2248 |
|
| 2249 |
r = sd_bus_message_read_strv(message, &states); |
| 2250 |
if (r < 0) |
| 2251 |
return r; |
| 2252 |
|
| 2253 |
r = sd_bus_message_read_strv(message, &patterns); |
| 2254 |
if (r < 0) |
| 2255 |
return r; |
| 2256 |
|
| 2257 |
return list_unit_files_by_patterns(message, userdata, reterr_error, states, patterns); |
| 2258 |
} |
| 2259 |
|
| 2260 |
static int method_get_unit_file_state(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2261 |
Manager *m = ASSERT_PTR(userdata); |
| 2262 |
const char *name; |
| 2263 |
UnitFileState state; |
| 2264 |
int r; |
| 2265 |
|
| 2266 |
assert(message); |
| 2267 |
|
| 2268 |
/* Anyone can call this method */ |
| 2269 |
|
| 2270 |
r = mac_selinux_access_check(message, "status", reterr_error); |
| 2271 |
if (r < 0) |
| 2272 |
return r; |
| 2273 |
|
| 2274 |
r = sd_bus_message_read(message, "s", &name); |
| 2275 |
if (r < 0) |
| 2276 |
return r; |
| 2277 |
|
| 2278 |
r = unit_file_get_state(m->runtime_scope, NULL, name, &state); |
| 2279 |
if (r < 0) |
| 2280 |
return r; |
| 2281 |
|
| 2282 |
return sd_bus_reply_method_return(message, "s", unit_file_state_to_string(state)); |
| 2283 |
} |
| 2284 |
|
| 2285 |
static int method_get_default_target(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2286 |
_cleanup_free_ char *default_target = NULL; |
| 2287 |
Manager *m = ASSERT_PTR(userdata); |
| 2288 |
int r; |
| 2289 |
|
| 2290 |
assert(message); |
| 2291 |
|
| 2292 |
/* Anyone can call this method */ |
| 2293 |
|
| 2294 |
r = mac_selinux_access_check(message, "status", reterr_error); |
| 2295 |
if (r < 0) |
| 2296 |
return r; |
| 2297 |
|
| 2298 |
r = unit_file_get_default(m->runtime_scope, NULL, &default_target); |
| 2299 |
if (r == -ERFKILL) |
| 2300 |
return sd_bus_error_set(reterr_error, BUS_ERROR_UNIT_MASKED, "Default target unit file is masked."); |
| 2301 |
if (r < 0) |
| 2302 |
return r; |
| 2303 |
|
| 2304 |
return sd_bus_reply_method_return(message, "s", default_target); |
| 2305 |
} |
| 2306 |
|
| 2307 |
static int send_unit_files_changed(sd_bus *bus, void *userdata) { |
| 2308 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
| 2309 |
int r; |
| 2310 |
|
| 2311 |
assert(bus); |
| 2312 |
|
| 2313 |
r = sd_bus_message_new_signal(bus, &message, |
| 2314 |
"/org/freedesktop/systemd1", |
| 2315 |
"org.freedesktop.systemd1.Manager", |
| 2316 |
"UnitFilesChanged"); |
| 2317 |
if (r < 0) |
| 2318 |
return r; |
| 2319 |
|
| 2320 |
return sd_bus_send(bus, message, NULL); |
| 2321 |
} |
| 2322 |
|
| 2323 |
static void manager_unit_files_changed(Manager *m, const InstallChange *changes, size_t n_changes) { |
| 2324 |
int r; |
| 2325 |
|
| 2326 |
assert(m); |
| 2327 |
assert(changes || n_changes == 0); |
| 2328 |
|
| 2329 |
if (!install_changes_have_modification(changes, n_changes)) |
| 2330 |
return; |
| 2331 |
|
| 2332 |
/* See comments for this variable in manager.h */ |
| 2333 |
m->unit_file_state_outdated = true; |
| 2334 |
|
| 2335 |
r = bus_foreach_bus(m, NULL, send_unit_files_changed, NULL); |
| 2336 |
if (r < 0) |
| 2337 |
log_debug_errno(r, "Failed to send UnitFilesChanged signal, ignoring: %m"); |
| 2338 |
} |
| 2339 |
|
| 2340 |
static int install_error( |
| 2341 |
sd_bus_error *reterr_error, |
| 2342 |
int c, |
| 2343 |
InstallChange *changes, |
| 2344 |
size_t n_changes) { |
| 2345 |
|
| 2346 |
int r; |
| 2347 |
|
| 2348 |
/* Create an error reply, using the error information from changes[] if possible, and fall back to |
| 2349 |
* generating an error from error code c. The error message only describes the first error. */ |
| 2350 |
|
| 2351 |
assert(changes || n_changes == 0); |
| 2352 |
|
| 2353 |
CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
| 2354 |
|
| 2355 |
FOREACH_ARRAY(i, changes, n_changes) { |
| 2356 |
_cleanup_free_ char *err_message = NULL; |
| 2357 |
const char *bus_error; |
| 2358 |
|
| 2359 |
if (i->type >= 0) |
| 2360 |
continue; |
| 2361 |
|
| 2362 |
r = install_change_dump_error(i, &err_message, &bus_error); |
| 2363 |
if (r == -ENOMEM) |
| 2364 |
return r; |
| 2365 |
if (r < 0) |
| 2366 |
return sd_bus_error_set_errnof(reterr_error, r, "File %s: %m", i->path); |
| 2367 |
|
| 2368 |
return sd_bus_error_set(reterr_error, bus_error, err_message); |
| 2369 |
} |
| 2370 |
|
| 2371 |
return c < 0 ? c : -EINVAL; |
| 2372 |
} |
| 2373 |
|
| 2374 |
static int reply_install_changes_and_free( |
| 2375 |
Manager *m, |
| 2376 |
sd_bus_message *message, |
| 2377 |
int carries_install_info, |
| 2378 |
InstallChange *changes, |
| 2379 |
size_t n_changes, |
| 2380 |
sd_bus_error *reterr_error) { |
| 2381 |
|
| 2382 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 2383 |
bool bad = false, good = false; |
| 2384 |
int r; |
| 2385 |
|
| 2386 |
CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
| 2387 |
|
| 2388 |
r = sd_bus_message_new_method_return(message, &reply); |
| 2389 |
if (r < 0) |
| 2390 |
return r; |
| 2391 |
|
| 2392 |
if (carries_install_info >= 0) { |
| 2393 |
r = sd_bus_message_append(reply, "b", carries_install_info); |
| 2394 |
if (r < 0) |
| 2395 |
return r; |
| 2396 |
} |
| 2397 |
|
| 2398 |
r = sd_bus_message_open_container(reply, 'a', "(sss)"); |
| 2399 |
if (r < 0) |
| 2400 |
return r; |
| 2401 |
|
| 2402 |
FOREACH_ARRAY(i, changes, n_changes) { |
| 2403 |
if (i->type < 0) { |
| 2404 |
bad = true; |
| 2405 |
continue; |
| 2406 |
} |
| 2407 |
|
| 2408 |
r = sd_bus_message_append( |
| 2409 |
reply, "(sss)", |
| 2410 |
install_change_type_to_string(i->type), |
| 2411 |
i->path, |
| 2412 |
i->source); |
| 2413 |
if (r < 0) |
| 2414 |
return r; |
| 2415 |
|
| 2416 |
good = true; |
| 2417 |
} |
| 2418 |
|
| 2419 |
/* If there was a failed change, and no successful change, then return the first failure as proper |
| 2420 |
* method call error. */ |
| 2421 |
if (bad && !good) |
| 2422 |
return install_error(reterr_error, 0, TAKE_PTR(changes), n_changes); |
| 2423 |
|
| 2424 |
r = sd_bus_message_close_container(reply); |
| 2425 |
if (r < 0) |
| 2426 |
return r; |
| 2427 |
|
| 2428 |
return sd_bus_message_send(reply); |
| 2429 |
} |
| 2430 |
|
| 2431 |
static int method_enable_unit_files_generic( |
| 2432 |
sd_bus_message *message, |
| 2433 |
Manager *m, |
| 2434 |
int (*call)(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char * const *files, InstallChange **changes, size_t *n_changes), |
| 2435 |
bool carries_install_info, |
| 2436 |
sd_bus_error *reterr_error) { |
| 2437 |
|
| 2438 |
_cleanup_strv_free_ char **l = NULL; |
| 2439 |
InstallChange *changes = NULL; |
| 2440 |
size_t n_changes = 0; |
| 2441 |
UnitFileFlags flags; |
| 2442 |
int r; |
| 2443 |
|
| 2444 |
assert(message); |
| 2445 |
assert(m); |
| 2446 |
|
| 2447 |
r = sd_bus_message_read_strv(message, &l); |
| 2448 |
if (r < 0) |
| 2449 |
return r; |
| 2450 |
|
| 2451 |
if (sd_bus_message_is_method_call(message, NULL, "EnableUnitFilesWithFlags")) { |
| 2452 |
uint64_t raw_flags; |
| 2453 |
|
| 2454 |
r = sd_bus_message_read(message, "t", &raw_flags); |
| 2455 |
if (r < 0) |
| 2456 |
return r; |
| 2457 |
if ((raw_flags & ~_UNIT_FILE_FLAGS_MASK_PUBLIC) != 0) |
| 2458 |
return -EINVAL; |
| 2459 |
flags = raw_flags; |
| 2460 |
} else { |
| 2461 |
int runtime, force; |
| 2462 |
|
| 2463 |
r = sd_bus_message_read(message, "bb", &runtime, &force); |
| 2464 |
if (r < 0) |
| 2465 |
return r; |
| 2466 |
flags = unit_file_bools_to_flags(runtime, force); |
| 2467 |
} |
| 2468 |
|
| 2469 |
r = bus_verify_manage_unit_files_async(m, message, reterr_error); |
| 2470 |
if (r < 0) |
| 2471 |
return r; |
| 2472 |
if (r == 0) |
| 2473 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2474 |
|
| 2475 |
r = call(m->runtime_scope, flags, NULL, l, &changes, &n_changes); |
| 2476 |
manager_unit_files_changed(m, changes, n_changes); |
| 2477 |
if (r < 0) |
| 2478 |
return install_error(reterr_error, r, changes, n_changes); |
| 2479 |
|
| 2480 |
return reply_install_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, reterr_error); |
| 2481 |
} |
| 2482 |
|
| 2483 |
static int method_enable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2484 |
return method_enable_unit_files_generic(message, userdata, unit_file_enable, /* carries_install_info= */ true, reterr_error); |
| 2485 |
} |
| 2486 |
|
| 2487 |
static int method_enable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2488 |
return method_enable_unit_files_generic(message, userdata, unit_file_enable, /* carries_install_info= */ true, reterr_error); |
| 2489 |
} |
| 2490 |
|
| 2491 |
static int method_reenable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2492 |
return method_enable_unit_files_generic(message, userdata, unit_file_reenable, /* carries_install_info= */ true, reterr_error); |
| 2493 |
} |
| 2494 |
|
| 2495 |
static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2496 |
return method_enable_unit_files_generic(message, userdata, unit_file_link, /* carries_install_info= */ false, reterr_error); |
| 2497 |
} |
| 2498 |
|
| 2499 |
static int unit_file_preset_without_mode(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char * const *files, InstallChange **changes, size_t *n_changes) { |
| 2500 |
return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes); |
| 2501 |
} |
| 2502 |
|
| 2503 |
static int method_preset_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2504 |
return method_enable_unit_files_generic(message, userdata, unit_file_preset_without_mode, /* carries_install_info= */ true, reterr_error); |
| 2505 |
} |
| 2506 |
|
| 2507 |
static int method_mask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2508 |
return method_enable_unit_files_generic(message, userdata, unit_file_mask, /* carries_install_info= */ false, reterr_error); |
| 2509 |
} |
| 2510 |
|
| 2511 |
static int method_preset_unit_files_with_mode(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2512 |
|
| 2513 |
_cleanup_strv_free_ char **l = NULL; |
| 2514 |
InstallChange *changes = NULL; |
| 2515 |
size_t n_changes = 0; |
| 2516 |
Manager *m = ASSERT_PTR(userdata); |
| 2517 |
UnitFilePresetMode preset_mode; |
| 2518 |
int runtime, force, r; |
| 2519 |
UnitFileFlags flags; |
| 2520 |
const char *mode; |
| 2521 |
|
| 2522 |
assert(message); |
| 2523 |
|
| 2524 |
r = sd_bus_message_read_strv(message, &l); |
| 2525 |
if (r < 0) |
| 2526 |
return r; |
| 2527 |
|
| 2528 |
r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); |
| 2529 |
if (r < 0) |
| 2530 |
return r; |
| 2531 |
|
| 2532 |
flags = unit_file_bools_to_flags(runtime, force); |
| 2533 |
|
| 2534 |
if (isempty(mode)) |
| 2535 |
preset_mode = UNIT_FILE_PRESET_FULL; |
| 2536 |
else { |
| 2537 |
preset_mode = unit_file_preset_mode_from_string(mode); |
| 2538 |
if (preset_mode < 0) |
| 2539 |
return -EINVAL; |
| 2540 |
} |
| 2541 |
|
| 2542 |
r = bus_verify_manage_unit_files_async(m, message, reterr_error); |
| 2543 |
if (r < 0) |
| 2544 |
return r; |
| 2545 |
if (r == 0) |
| 2546 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2547 |
|
| 2548 |
r = unit_file_preset(m->runtime_scope, flags, NULL, l, preset_mode, &changes, &n_changes); |
| 2549 |
manager_unit_files_changed(m, changes, n_changes); |
| 2550 |
if (r < 0) |
| 2551 |
return install_error(reterr_error, r, changes, n_changes); |
| 2552 |
|
| 2553 |
return reply_install_changes_and_free(m, message, r, changes, n_changes, reterr_error); |
| 2554 |
} |
| 2555 |
|
| 2556 |
static int method_disable_unit_files_generic( |
| 2557 |
sd_bus_message *message, |
| 2558 |
Manager *m, |
| 2559 |
int (*call)(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char * const *files, InstallChange **changes, size_t *n_changes), |
| 2560 |
bool carries_install_info, |
| 2561 |
sd_bus_error *reterr_error) { |
| 2562 |
|
| 2563 |
_cleanup_strv_free_ char **l = NULL; |
| 2564 |
InstallChange *changes = NULL; |
| 2565 |
UnitFileFlags flags; |
| 2566 |
size_t n_changes = 0; |
| 2567 |
int r; |
| 2568 |
|
| 2569 |
assert(message); |
| 2570 |
assert(m); |
| 2571 |
|
| 2572 |
r = sd_bus_message_read_strv(message, &l); |
| 2573 |
if (r < 0) |
| 2574 |
return r; |
| 2575 |
|
| 2576 |
if (sd_bus_message_is_method_call(message, NULL, "DisableUnitFilesWithFlags") || |
| 2577 |
sd_bus_message_is_method_call(message, NULL, "DisableUnitFilesWithFlagsAndInstallInfo")) { |
| 2578 |
uint64_t raw_flags; |
| 2579 |
|
| 2580 |
r = sd_bus_message_read(message, "t", &raw_flags); |
| 2581 |
if (r < 0) |
| 2582 |
return r; |
| 2583 |
if ((raw_flags & ~_UNIT_FILE_FLAGS_MASK_PUBLIC) != 0 || |
| 2584 |
FLAGS_SET(raw_flags, UNIT_FILE_FORCE)) |
| 2585 |
return -EINVAL; |
| 2586 |
flags = raw_flags; |
| 2587 |
} else { |
| 2588 |
int runtime; |
| 2589 |
|
| 2590 |
r = sd_bus_message_read(message, "b", &runtime); |
| 2591 |
if (r < 0) |
| 2592 |
return r; |
| 2593 |
flags = unit_file_bools_to_flags(runtime, false); |
| 2594 |
} |
| 2595 |
|
| 2596 |
r = bus_verify_manage_unit_files_async(m, message, reterr_error); |
| 2597 |
if (r < 0) |
| 2598 |
return r; |
| 2599 |
if (r == 0) |
| 2600 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2601 |
|
| 2602 |
r = call(m->runtime_scope, flags, NULL, l, &changes, &n_changes); |
| 2603 |
manager_unit_files_changed(m, changes, n_changes); |
| 2604 |
if (r < 0) |
| 2605 |
return install_error(reterr_error, r, changes, n_changes); |
| 2606 |
|
| 2607 |
return reply_install_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes, reterr_error); |
| 2608 |
} |
| 2609 |
|
| 2610 |
static int method_disable_unit_files_with_flags(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2611 |
return method_disable_unit_files_generic(message, userdata, unit_file_disable, /* carries_install_info= */ false, reterr_error); |
| 2612 |
} |
| 2613 |
|
| 2614 |
static int method_disable_unit_files_with_flags_and_install_info(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2615 |
return method_disable_unit_files_generic(message, userdata, unit_file_disable, /* carries_install_info= */ true, reterr_error); |
| 2616 |
} |
| 2617 |
|
| 2618 |
static int method_disable_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2619 |
return method_disable_unit_files_generic(message, userdata, unit_file_disable, /* carries_install_info= */ false, reterr_error); |
| 2620 |
} |
| 2621 |
|
| 2622 |
static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2623 |
return method_disable_unit_files_generic(message, userdata, unit_file_unmask, /* carries_install_info= */ false, reterr_error); |
| 2624 |
} |
| 2625 |
|
| 2626 |
static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2627 |
_cleanup_strv_free_ char **l = NULL; |
| 2628 |
InstallChange *changes = NULL; |
| 2629 |
size_t n_changes = 0; |
| 2630 |
Manager *m = ASSERT_PTR(userdata); |
| 2631 |
int r; |
| 2632 |
|
| 2633 |
assert(message); |
| 2634 |
|
| 2635 |
r = sd_bus_message_read_strv(message, &l); |
| 2636 |
if (r < 0) |
| 2637 |
return r; |
| 2638 |
|
| 2639 |
r = bus_verify_manage_unit_files_async(m, message, reterr_error); |
| 2640 |
if (r < 0) |
| 2641 |
return r; |
| 2642 |
if (r == 0) |
| 2643 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2644 |
|
| 2645 |
r = unit_file_revert(m->runtime_scope, NULL, l, &changes, &n_changes); |
| 2646 |
manager_unit_files_changed(m, changes, n_changes); |
| 2647 |
if (r < 0) |
| 2648 |
return install_error(reterr_error, r, changes, n_changes); |
| 2649 |
|
| 2650 |
return reply_install_changes_and_free(m, message, -1, changes, n_changes, reterr_error); |
| 2651 |
} |
| 2652 |
|
| 2653 |
static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2654 |
InstallChange *changes = NULL; |
| 2655 |
size_t n_changes = 0; |
| 2656 |
Manager *m = ASSERT_PTR(userdata); |
| 2657 |
const char *name; |
| 2658 |
int force, r; |
| 2659 |
|
| 2660 |
assert(message); |
| 2661 |
|
| 2662 |
r = mac_selinux_access_check(message, "enable", reterr_error); |
| 2663 |
if (r < 0) |
| 2664 |
return r; |
| 2665 |
|
| 2666 |
r = sd_bus_message_read(message, "sb", &name, &force); |
| 2667 |
if (r < 0) |
| 2668 |
return r; |
| 2669 |
|
| 2670 |
r = bus_verify_manage_unit_files_async(m, message, reterr_error); |
| 2671 |
if (r < 0) |
| 2672 |
return r; |
| 2673 |
if (r == 0) |
| 2674 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2675 |
|
| 2676 |
r = unit_file_set_default(m->runtime_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes); |
| 2677 |
manager_unit_files_changed(m, changes, n_changes); |
| 2678 |
if (r < 0) |
| 2679 |
return install_error(reterr_error, r, changes, n_changes); |
| 2680 |
|
| 2681 |
return reply_install_changes_and_free(m, message, -1, changes, n_changes, reterr_error); |
| 2682 |
} |
| 2683 |
|
| 2684 |
static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2685 |
InstallChange *changes = NULL; |
| 2686 |
size_t n_changes = 0; |
| 2687 |
Manager *m = ASSERT_PTR(userdata); |
| 2688 |
UnitFilePresetMode preset_mode; |
| 2689 |
const char *mode; |
| 2690 |
UnitFileFlags flags; |
| 2691 |
int force, runtime, r; |
| 2692 |
|
| 2693 |
assert(message); |
| 2694 |
|
| 2695 |
r = mac_selinux_access_check(message, "enable", reterr_error); |
| 2696 |
if (r < 0) |
| 2697 |
return r; |
| 2698 |
|
| 2699 |
r = sd_bus_message_read(message, "sbb", &mode, &runtime, &force); |
| 2700 |
if (r < 0) |
| 2701 |
return r; |
| 2702 |
|
| 2703 |
flags = unit_file_bools_to_flags(runtime, force); |
| 2704 |
|
| 2705 |
if (isempty(mode)) |
| 2706 |
preset_mode = UNIT_FILE_PRESET_FULL; |
| 2707 |
else { |
| 2708 |
preset_mode = unit_file_preset_mode_from_string(mode); |
| 2709 |
if (preset_mode < 0) |
| 2710 |
return -EINVAL; |
| 2711 |
} |
| 2712 |
|
| 2713 |
r = bus_verify_manage_unit_files_async(m, message, reterr_error); |
| 2714 |
if (r < 0) |
| 2715 |
return r; |
| 2716 |
if (r == 0) |
| 2717 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2718 |
|
| 2719 |
r = unit_file_preset_all(m->runtime_scope, flags, NULL, preset_mode, &changes, &n_changes); |
| 2720 |
manager_unit_files_changed(m, changes, n_changes); |
| 2721 |
if (r < 0) |
| 2722 |
return install_error(reterr_error, r, changes, n_changes); |
| 2723 |
|
| 2724 |
return reply_install_changes_and_free(m, message, -1, changes, n_changes, reterr_error); |
| 2725 |
} |
| 2726 |
|
| 2727 |
static int method_add_dependency_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2728 |
_cleanup_strv_free_ char **l = NULL; |
| 2729 |
Manager *m = ASSERT_PTR(userdata); |
| 2730 |
InstallChange *changes = NULL; |
| 2731 |
size_t n_changes = 0; |
| 2732 |
int runtime, force, r; |
| 2733 |
char *target, *type; |
| 2734 |
UnitDependency dep; |
| 2735 |
UnitFileFlags flags; |
| 2736 |
|
| 2737 |
assert(message); |
| 2738 |
|
| 2739 |
r = bus_verify_manage_unit_files_async(m, message, reterr_error); |
| 2740 |
if (r < 0) |
| 2741 |
return r; |
| 2742 |
if (r == 0) |
| 2743 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2744 |
|
| 2745 |
r = sd_bus_message_read_strv(message, &l); |
| 2746 |
if (r < 0) |
| 2747 |
return r; |
| 2748 |
|
| 2749 |
r = sd_bus_message_read(message, "ssbb", &target, &type, &runtime, &force); |
| 2750 |
if (r < 0) |
| 2751 |
return r; |
| 2752 |
|
| 2753 |
flags = unit_file_bools_to_flags(runtime, force); |
| 2754 |
|
| 2755 |
dep = unit_dependency_from_string(type); |
| 2756 |
if (dep < 0 || !IN_SET(dep, UNIT_WANTS, UNIT_REQUIRES)) |
| 2757 |
return -EINVAL; |
| 2758 |
|
| 2759 |
r = unit_file_add_dependency(m->runtime_scope, flags, NULL, l, target, dep, &changes, &n_changes); |
| 2760 |
manager_unit_files_changed(m, changes, n_changes); |
| 2761 |
if (r < 0) |
| 2762 |
return install_error(reterr_error, r, changes, n_changes); |
| 2763 |
|
| 2764 |
return reply_install_changes_and_free(m, message, -1, changes, n_changes, reterr_error); |
| 2765 |
} |
| 2766 |
|
| 2767 |
static int method_get_unit_file_links(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2768 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 2769 |
Manager *m = ASSERT_PTR(userdata); |
| 2770 |
InstallChange *changes = NULL; |
| 2771 |
size_t n_changes = 0, i; |
| 2772 |
const char *name; |
| 2773 |
int runtime, r; |
| 2774 |
|
| 2775 |
CLEANUP_ARRAY(changes, n_changes, install_changes_free); |
| 2776 |
|
| 2777 |
r = sd_bus_message_read(message, "sb", &name, &runtime); |
| 2778 |
if (r < 0) |
| 2779 |
return r; |
| 2780 |
|
| 2781 |
r = sd_bus_message_new_method_return(message, &reply); |
| 2782 |
if (r < 0) |
| 2783 |
return r; |
| 2784 |
|
| 2785 |
r = sd_bus_message_open_container(reply, SD_BUS_TYPE_ARRAY, "s"); |
| 2786 |
if (r < 0) |
| 2787 |
return r; |
| 2788 |
|
| 2789 |
r = unit_file_disable(m->runtime_scope, |
| 2790 |
UNIT_FILE_DRY_RUN | (runtime ? UNIT_FILE_RUNTIME : 0), |
| 2791 |
NULL, STRV_MAKE(name), &changes, &n_changes); |
| 2792 |
if (r < 0) |
| 2793 |
return log_error_errno(r, "Failed to get file links for %s: %m", name); |
| 2794 |
|
| 2795 |
for (i = 0; i < n_changes; i++) |
| 2796 |
if (changes[i].type == INSTALL_CHANGE_UNLINK) { |
| 2797 |
r = sd_bus_message_append(reply, "s", changes[i].path); |
| 2798 |
if (r < 0) |
| 2799 |
return r; |
| 2800 |
} |
| 2801 |
|
| 2802 |
r = sd_bus_message_close_container(reply); |
| 2803 |
if (r < 0) |
| 2804 |
return r; |
| 2805 |
|
| 2806 |
return sd_bus_message_send(reply); |
| 2807 |
} |
| 2808 |
|
| 2809 |
static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2810 |
Manager *m = ASSERT_PTR(userdata); |
| 2811 |
uint32_t id; |
| 2812 |
Job *j; |
| 2813 |
int r; |
| 2814 |
|
| 2815 |
assert(message); |
| 2816 |
|
| 2817 |
r = sd_bus_message_read(message, "u", &id); |
| 2818 |
if (r < 0) |
| 2819 |
return r; |
| 2820 |
|
| 2821 |
j = manager_get_job(m, id); |
| 2822 |
if (!j) |
| 2823 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); |
| 2824 |
|
| 2825 |
return bus_job_method_get_waiting_jobs(message, j, reterr_error); |
| 2826 |
} |
| 2827 |
|
| 2828 |
static int method_abandon_scope(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2829 |
Manager *m = ASSERT_PTR(userdata); |
| 2830 |
const char *name; |
| 2831 |
Unit *u; |
| 2832 |
int r; |
| 2833 |
|
| 2834 |
assert(message); |
| 2835 |
|
| 2836 |
r = sd_bus_message_read(message, "s", &name); |
| 2837 |
if (r < 0) |
| 2838 |
return r; |
| 2839 |
|
| 2840 |
r = bus_get_unit_by_name(m, message, name, &u, reterr_error); |
| 2841 |
if (r < 0) |
| 2842 |
return r; |
| 2843 |
|
| 2844 |
if (u->type != UNIT_SCOPE) |
| 2845 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 2846 |
"Unit '%s' is not a scope unit, refusing.", name); |
| 2847 |
|
| 2848 |
return bus_scope_method_abandon(message, u, reterr_error); |
| 2849 |
} |
| 2850 |
|
| 2851 |
static int method_set_show_status(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2852 |
Manager *m = ASSERT_PTR(userdata); |
| 2853 |
ShowStatus mode = _SHOW_STATUS_INVALID; |
| 2854 |
const char *t; |
| 2855 |
int r; |
| 2856 |
|
| 2857 |
assert(message); |
| 2858 |
|
| 2859 |
r = mac_selinux_access_check(message, "reload", reterr_error); |
| 2860 |
if (r < 0) |
| 2861 |
return r; |
| 2862 |
|
| 2863 |
r = bus_verify_set_environment_async(m, message, reterr_error); |
| 2864 |
if (r < 0) |
| 2865 |
return r; |
| 2866 |
if (r == 0) |
| 2867 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 2868 |
|
| 2869 |
r = sd_bus_message_read(message, "s", &t); |
| 2870 |
if (r < 0) |
| 2871 |
return r; |
| 2872 |
|
| 2873 |
if (!isempty(t)) { |
| 2874 |
mode = show_status_from_string(t); |
| 2875 |
if (mode < 0) |
| 2876 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, |
| 2877 |
"Invalid show status '%s'", t); |
| 2878 |
} |
| 2879 |
|
| 2880 |
manager_override_show_status(m, mode, "bus"); |
| 2881 |
|
| 2882 |
return sd_bus_reply_method_return(message, NULL); |
| 2883 |
} |
| 2884 |
|
| 2885 |
static int method_dump_unit_descriptor_store(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2886 |
return method_generic_unit_operation(message, userdata, reterr_error, UNIT_SERVICE, bus_service_method_dump_file_descriptor_store, GENERIC_UNIT_VALIDATE_LOADED); |
| 2887 |
} |
| 2888 |
|
| 2889 |
static int method_start_aux_scope(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 2890 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, "StartAuxiliaryScope() method has been removed."); |
| 2891 |
} |
| 2892 |
|
| 2893 |
const sd_bus_vtable bus_manager_vtable[] = { |
| 2894 |
SD_BUS_VTABLE_START(0), |
| 2895 |
|
| 2896 |
SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 2897 |
SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 2898 |
SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 2899 |
SD_BUS_PROPERTY("ConfidentialVirtualization", "s", property_get_confidential_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 2900 |
SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 2901 |
SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 2902 |
BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FIRMWARE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2903 |
BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_LOADER]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2904 |
BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_KERNEL]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2905 |
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2906 |
BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_USERSPACE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2907 |
BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2908 |
BUS_PROPERTY_DUAL_TIMESTAMP("ShutdownStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SHUTDOWN_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2909 |
BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2910 |
BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2911 |
BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2912 |
BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2913 |
BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2914 |
BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2915 |
BUS_PROPERTY_DUAL_TIMESTAMP("UnitsLoadTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_UNITS_LOAD]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2916 |
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2917 |
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDSecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2918 |
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2919 |
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2920 |
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2921 |
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2922 |
SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), |
| 2923 |
SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), |
| 2924 |
SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size, offsetof(Manager, units), 0), |
| 2925 |
SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size, offsetof(Manager, failed_units), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 2926 |
SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size, offsetof(Manager, jobs), 0), |
| 2927 |
SD_BUS_PROPERTY("NInstalledJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_installed_jobs), 0), |
| 2928 |
SD_BUS_PROPERTY("NFailedJobs", "u", bus_property_get_unsigned, offsetof(Manager, n_failed_jobs), 0), |
| 2929 |
SD_BUS_PROPERTY("TransactionsWithOrderingCycle", "at", property_get_transactions_with_cycle, 0, 0), |
| 2930 |
SD_BUS_PROPERTY("Progress", "d", property_get_progress, 0, 0), |
| 2931 |
SD_BUS_PROPERTY("Environment", "as", property_get_environment, 0, 0), |
| 2932 |
SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2933 |
SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status, 0, 0), |
| 2934 |
SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2935 |
SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, defaults.std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2936 |
SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, defaults.std_error), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2937 |
SD_BUS_PROPERTY("WatchdogDevice", "s", property_get_watchdog_device, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 2938 |
SD_BUS_PROPERTY("WatchdogLastPingTimestamp", "t", property_get_watchdog_last_ping_realtime, 0, 0), |
| 2939 |
SD_BUS_PROPERTY("WatchdogLastPingTimestampMonotonic", "t", property_get_watchdog_last_ping_monotonic, 0, 0), |
| 2940 |
SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", property_get_runtime_watchdog, property_set_runtime_watchdog, 0, 0), |
| 2941 |
SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogPreUSec", "t", property_get_pretimeout_watchdog, property_set_pretimeout_watchdog, 0, 0), |
| 2942 |
SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogPreGovernor", "s", property_get_pretimeout_watchdog_governor, property_set_pretimeout_watchdog_governor, 0, 0), |
| 2943 |
SD_BUS_WRITABLE_PROPERTY("RebootWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, 0), |
| 2944 |
/* The following item is an obsolete alias */ |
| 2945 |
SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", property_get_reboot_watchdog, property_set_reboot_watchdog, 0, SD_BUS_VTABLE_HIDDEN), |
| 2946 |
SD_BUS_WRITABLE_PROPERTY("KExecWatchdogUSec", "t", property_get_kexec_watchdog, property_set_kexec_watchdog, 0, 0), |
| 2947 |
SD_BUS_WRITABLE_PROPERTY("ServiceWatchdogs", "b", bus_property_get_bool, bus_property_set_bool, offsetof(Manager, service_watchdogs), 0), |
| 2948 |
SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0), |
| 2949 |
SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0), |
| 2950 |
SD_BUS_PROPERTY("ExitCode", "y", NULL, offsetof(Manager, return_value), 0), |
| 2951 |
SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2952 |
SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2953 |
SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2954 |
SD_BUS_PROPERTY("DefaultTimeoutAbortUSec", "t", property_get_default_timeout_abort_usec, 0, 0), |
| 2955 |
SD_BUS_PROPERTY("DefaultDeviceTimeoutUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.device_timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2956 |
SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2957 |
SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2958 |
/* The following two items are obsolete alias */ |
| 2959 |
SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
| 2960 |
SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
| 2961 |
SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, defaults.start_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2962 |
SD_BUS_PROPERTY("EventLoopRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, event_loop_ratelimit.interval), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2963 |
SD_BUS_PROPERTY("EventLoopRateLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, event_loop_ratelimit.burst), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2964 |
SD_BUS_PROPERTY("DefaultIOAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.io_accounting), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2965 |
SD_BUS_PROPERTY("DefaultIPAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.ip_accounting), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2966 |
SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2967 |
SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2968 |
SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2969 |
SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2970 |
SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2971 |
SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2972 |
SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2973 |
SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2974 |
SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2975 |
SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2976 |
SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2977 |
SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2978 |
SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2979 |
SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2980 |
SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2981 |
SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2982 |
SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2983 |
SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2984 |
SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2985 |
SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2986 |
SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2987 |
SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2988 |
SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2989 |
SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2990 |
SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2991 |
SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2992 |
SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2993 |
SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2994 |
SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2995 |
SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2996 |
SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2997 |
SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2998 |
SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 2999 |
SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
| 3000 |
SD_BUS_PROPERTY("DefaultTasksMax", "t", bus_property_get_tasks_max, offsetof(Manager, defaults.tasks_max), 0), |
| 3001 |
SD_BUS_PROPERTY("DefaultMemoryPressureThresholdUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.pressure[PRESSURE_MEMORY].threshold_usec), 0), |
| 3002 |
SD_BUS_PROPERTY("DefaultMemoryPressureWatch", "s", bus_property_get_cgroup_pressure_watch, offsetof(Manager, defaults.pressure[PRESSURE_MEMORY].watch), 0), |
| 3003 |
SD_BUS_PROPERTY("DefaultCPUPressureThresholdUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.pressure[PRESSURE_CPU].threshold_usec), 0), |
| 3004 |
SD_BUS_PROPERTY("DefaultCPUPressureWatch", "s", bus_property_get_cgroup_pressure_watch, offsetof(Manager, defaults.pressure[PRESSURE_CPU].watch), 0), |
| 3005 |
SD_BUS_PROPERTY("DefaultIOPressureThresholdUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.pressure[PRESSURE_IO].threshold_usec), 0), |
| 3006 |
SD_BUS_PROPERTY("DefaultIOPressureWatch", "s", bus_property_get_cgroup_pressure_watch, offsetof(Manager, defaults.pressure[PRESSURE_IO].watch), 0), |
| 3007 |
SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 3008 |
SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy, offsetof(Manager, defaults.oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), |
| 3009 |
SD_BUS_PROPERTY("DefaultOOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 3010 |
SD_BUS_PROPERTY("DefaultRestrictSUIDSGID", "b", bus_property_get_bool, offsetof(Manager, defaults.restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST), |
| 3011 |
SD_BUS_PROPERTY("CtrlAltDelBurstAction", "s", bus_property_get_emergency_action, offsetof(Manager, cad_burst_action), SD_BUS_VTABLE_PROPERTY_CONST), |
| 3012 |
SD_BUS_PROPERTY("SoftRebootsCount", "u", bus_property_get_unsigned, offsetof(Manager, soft_reboots_count), SD_BUS_VTABLE_PROPERTY_CONST), |
| 3013 |
SD_BUS_PROPERTY("ReloadCount", "t", NULL, offsetof(Manager, reload_count), 0), |
| 3014 |
SD_BUS_PROPERTY("DefaultMemoryZSwapWriteback", "b", bus_property_get_bool, offsetof(Manager, defaults.memory_zswap_writeback), SD_BUS_VTABLE_PROPERTY_CONST), |
| 3015 |
|
| 3016 |
/* deprecated cgroup v1 property */ |
| 3017 |
SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool_false, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), |
| 3018 |
/* see comment in bus_cgroup_vtable */ |
| 3019 |
SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool_true, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), |
| 3020 |
|
| 3021 |
SD_BUS_METHOD_WITH_ARGS("GetUnit", |
| 3022 |
SD_BUS_ARGS("s", name), |
| 3023 |
SD_BUS_RESULT("o", unit), |
| 3024 |
method_get_unit, |
| 3025 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3026 |
SD_BUS_METHOD_WITH_ARGS("GetUnitByPID", |
| 3027 |
SD_BUS_ARGS("u", pid), |
| 3028 |
SD_BUS_RESULT("o", unit), |
| 3029 |
method_get_unit_by_pid, |
| 3030 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3031 |
SD_BUS_METHOD_WITH_ARGS("GetUnitByInvocationID", |
| 3032 |
SD_BUS_ARGS("ay", invocation_id), |
| 3033 |
SD_BUS_RESULT("o", unit), |
| 3034 |
method_get_unit_by_invocation_id, |
| 3035 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3036 |
SD_BUS_METHOD_WITH_ARGS("GetUnitByControlGroup", |
| 3037 |
SD_BUS_ARGS("s", cgroup), |
| 3038 |
SD_BUS_RESULT("o", unit), |
| 3039 |
method_get_unit_by_control_group, |
| 3040 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3041 |
SD_BUS_METHOD_WITH_ARGS("GetUnitByPIDFD", |
| 3042 |
SD_BUS_ARGS("h", pidfd), |
| 3043 |
SD_BUS_RESULT("o", unit, "s", unit_id, "ay", invocation_id), |
| 3044 |
method_get_unit_by_pidfd, |
| 3045 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3046 |
SD_BUS_METHOD_WITH_ARGS("LoadUnit", |
| 3047 |
SD_BUS_ARGS("s", name), |
| 3048 |
SD_BUS_RESULT("o", unit), |
| 3049 |
method_load_unit, |
| 3050 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3051 |
SD_BUS_METHOD_WITH_ARGS("StartUnit", |
| 3052 |
SD_BUS_ARGS("s", name, "s", mode), |
| 3053 |
SD_BUS_RESULT("o", job), |
| 3054 |
method_start_unit, |
| 3055 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3056 |
SD_BUS_METHOD_WITH_ARGS("StartUnitWithFlags", |
| 3057 |
SD_BUS_ARGS("s", name, "s", mode, "t", flags), |
| 3058 |
SD_BUS_RESULT("o", job), |
| 3059 |
method_start_unit, |
| 3060 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3061 |
SD_BUS_METHOD_WITH_ARGS("StartUnitReplace", |
| 3062 |
SD_BUS_ARGS("s", old_unit, "s", new_unit, "s", mode), |
| 3063 |
SD_BUS_RESULT("o", job), |
| 3064 |
method_start_unit_replace, |
| 3065 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3066 |
SD_BUS_METHOD_WITH_ARGS("StopUnit", |
| 3067 |
SD_BUS_ARGS("s", name, "s", mode), |
| 3068 |
SD_BUS_RESULT("o", job), |
| 3069 |
method_stop_unit, |
| 3070 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3071 |
SD_BUS_METHOD_WITH_ARGS("ReloadUnit", |
| 3072 |
SD_BUS_ARGS("s", name, "s", mode), |
| 3073 |
SD_BUS_RESULT("o", job), |
| 3074 |
method_reload_unit, |
| 3075 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3076 |
SD_BUS_METHOD_WITH_ARGS("RestartUnit", |
| 3077 |
SD_BUS_ARGS("s", name, "s", mode), |
| 3078 |
SD_BUS_RESULT("o", job), |
| 3079 |
method_restart_unit, |
| 3080 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3081 |
SD_BUS_METHOD_WITH_ARGS("TryRestartUnit", |
| 3082 |
SD_BUS_ARGS("s", name, "s", mode), |
| 3083 |
SD_BUS_RESULT("o", job), |
| 3084 |
method_try_restart_unit, |
| 3085 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3086 |
SD_BUS_METHOD_WITH_ARGS("ReloadOrRestartUnit", |
| 3087 |
SD_BUS_ARGS("s", name, "s", mode), |
| 3088 |
SD_BUS_RESULT("o", job), |
| 3089 |
method_reload_or_restart_unit, |
| 3090 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3091 |
SD_BUS_METHOD_WITH_ARGS("ReloadOrTryRestartUnit", |
| 3092 |
SD_BUS_ARGS("s", name, "s", mode), |
| 3093 |
SD_BUS_RESULT("o", job), |
| 3094 |
method_reload_or_try_restart_unit, |
| 3095 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3096 |
SD_BUS_METHOD_WITH_ARGS("EnqueueUnitJob", |
| 3097 |
SD_BUS_ARGS("s", name, "s", job_type, "s", job_mode), |
| 3098 |
SD_BUS_RESULT("u", job_id, "o", job_path, "s", unit_id, "o", unit_path, "s", job_type, "a(uosos)", affected_jobs), |
| 3099 |
method_enqueue_unit_job, |
| 3100 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3101 |
SD_BUS_METHOD_WITH_ARGS("KillUnit", |
| 3102 |
SD_BUS_ARGS("s", name, "s", whom, "i", signal), |
| 3103 |
SD_BUS_NO_RESULT, |
| 3104 |
method_kill_unit, |
| 3105 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3106 |
SD_BUS_METHOD_WITH_ARGS("KillUnitSubgroup", |
| 3107 |
SD_BUS_ARGS("s", name, "s", whom, "s", subgroup, "i", signal), |
| 3108 |
SD_BUS_NO_RESULT, |
| 3109 |
method_kill_unit_subgroup, |
| 3110 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3111 |
SD_BUS_METHOD_WITH_ARGS("QueueSignalUnit", |
| 3112 |
SD_BUS_ARGS("s", name, "s", whom, "i", signal, "i", value), |
| 3113 |
SD_BUS_NO_RESULT, |
| 3114 |
method_kill_unit, |
| 3115 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3116 |
SD_BUS_METHOD_WITH_ARGS("CleanUnit", |
| 3117 |
SD_BUS_ARGS("s", name, "as", mask), |
| 3118 |
SD_BUS_NO_RESULT, |
| 3119 |
method_clean_unit, |
| 3120 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3121 |
SD_BUS_METHOD_WITH_ARGS("FreezeUnit", |
| 3122 |
SD_BUS_ARGS("s", name), |
| 3123 |
SD_BUS_NO_RESULT, |
| 3124 |
method_freeze_unit, |
| 3125 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3126 |
SD_BUS_METHOD_WITH_ARGS("ThawUnit", |
| 3127 |
SD_BUS_ARGS("s", name), |
| 3128 |
SD_BUS_NO_RESULT, |
| 3129 |
method_thaw_unit, |
| 3130 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3131 |
SD_BUS_METHOD_WITH_ARGS("ResetFailedUnit", |
| 3132 |
SD_BUS_ARGS("s", name), |
| 3133 |
SD_BUS_NO_RESULT, |
| 3134 |
method_reset_failed_unit, |
| 3135 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3136 |
SD_BUS_METHOD_WITH_ARGS("SetUnitProperties", |
| 3137 |
SD_BUS_ARGS("s", name, "b", runtime, "a(sv)", properties), |
| 3138 |
SD_BUS_NO_RESULT, |
| 3139 |
method_set_unit_properties, |
| 3140 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3141 |
SD_BUS_METHOD_WITH_ARGS("BindMountUnit", |
| 3142 |
SD_BUS_ARGS("s", name, "s", source, "s", destination, "b", read_only, "b", mkdir), |
| 3143 |
SD_BUS_NO_RESULT, |
| 3144 |
method_bind_mount_unit, |
| 3145 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3146 |
SD_BUS_METHOD_WITH_ARGS("MountImageUnit", |
| 3147 |
SD_BUS_ARGS("s", name, "s", source, "s", destination, "b", read_only, "b", mkdir, "a(ss)", options), |
| 3148 |
SD_BUS_NO_RESULT, |
| 3149 |
method_mount_image_unit, |
| 3150 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3151 |
SD_BUS_METHOD_WITH_ARGS("RefUnit", |
| 3152 |
SD_BUS_ARGS("s", name), |
| 3153 |
SD_BUS_NO_RESULT, |
| 3154 |
method_ref_unit, |
| 3155 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3156 |
SD_BUS_METHOD_WITH_ARGS("UnrefUnit", |
| 3157 |
SD_BUS_ARGS("s", name), |
| 3158 |
SD_BUS_NO_RESULT, |
| 3159 |
method_unref_unit, |
| 3160 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3161 |
SD_BUS_METHOD_WITH_ARGS("StartTransientUnit", |
| 3162 |
SD_BUS_ARGS("s", name, "s", mode, "a(sv)", properties, "a(sa(sv))", aux), |
| 3163 |
SD_BUS_RESULT("o", job), |
| 3164 |
method_start_transient_unit, |
| 3165 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3166 |
SD_BUS_METHOD_WITH_ARGS("GetUnitProcesses", |
| 3167 |
SD_BUS_ARGS("s", name), |
| 3168 |
SD_BUS_RESULT("a(sus)", processes), |
| 3169 |
method_get_unit_processes, |
| 3170 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3171 |
SD_BUS_METHOD_WITH_ARGS("AttachProcessesToUnit", |
| 3172 |
SD_BUS_ARGS("s", unit_name, "s", subcgroup, "au", pids), |
| 3173 |
SD_BUS_NO_RESULT, |
| 3174 |
method_attach_processes_to_unit, |
| 3175 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3176 |
SD_BUS_METHOD_WITH_ARGS("RemoveSubgroupFromUnit", |
| 3177 |
SD_BUS_ARGS("s", unit_name, "s", subcgroup, "t", flags), |
| 3178 |
SD_BUS_NO_RESULT, |
| 3179 |
method_remove_subgroup_from_unit, |
| 3180 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3181 |
SD_BUS_METHOD_WITH_ARGS("AbandonScope", |
| 3182 |
SD_BUS_ARGS("s", name), |
| 3183 |
SD_BUS_NO_RESULT, |
| 3184 |
method_abandon_scope, |
| 3185 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3186 |
SD_BUS_METHOD_WITH_ARGS("GetJob", |
| 3187 |
SD_BUS_ARGS("u", id), |
| 3188 |
SD_BUS_RESULT("o", job), |
| 3189 |
method_get_job, |
| 3190 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3191 |
SD_BUS_METHOD_WITH_ARGS("GetJobAfter", |
| 3192 |
SD_BUS_ARGS("u", id), |
| 3193 |
SD_BUS_RESULT("a(usssoo)", jobs), |
| 3194 |
method_get_job_waiting, |
| 3195 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3196 |
SD_BUS_METHOD_WITH_ARGS("GetJobBefore", |
| 3197 |
SD_BUS_ARGS("u", id), |
| 3198 |
SD_BUS_RESULT("a(usssoo)", jobs), |
| 3199 |
method_get_job_waiting, |
| 3200 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3201 |
SD_BUS_METHOD_WITH_ARGS("CancelJob", |
| 3202 |
SD_BUS_ARGS("u", id), |
| 3203 |
SD_BUS_NO_RESULT, |
| 3204 |
method_cancel_job, |
| 3205 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3206 |
SD_BUS_METHOD("ClearJobs", |
| 3207 |
NULL, |
| 3208 |
NULL, |
| 3209 |
method_clear_jobs, |
| 3210 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3211 |
SD_BUS_METHOD("ResetFailed", |
| 3212 |
NULL, |
| 3213 |
NULL, |
| 3214 |
method_reset_failed, |
| 3215 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3216 |
SD_BUS_METHOD_WITH_ARGS("SetShowStatus", |
| 3217 |
SD_BUS_ARGS("s", mode), |
| 3218 |
SD_BUS_NO_RESULT, |
| 3219 |
method_set_show_status, |
| 3220 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3221 |
SD_BUS_METHOD_WITH_ARGS("ListUnits", |
| 3222 |
SD_BUS_NO_ARGS, |
| 3223 |
SD_BUS_RESULT("a(ssssssouso)", units), |
| 3224 |
method_list_units, |
| 3225 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3226 |
SD_BUS_METHOD_WITH_ARGS("ListUnitsFiltered", |
| 3227 |
SD_BUS_ARGS("as", states), |
| 3228 |
SD_BUS_RESULT("a(ssssssouso)", units), |
| 3229 |
method_list_units_filtered, |
| 3230 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3231 |
SD_BUS_METHOD_WITH_ARGS("ListUnitsByPatterns", |
| 3232 |
SD_BUS_ARGS("as", states, "as", patterns), |
| 3233 |
SD_BUS_RESULT("a(ssssssouso)", units), |
| 3234 |
method_list_units_by_patterns, |
| 3235 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3236 |
SD_BUS_METHOD_WITH_ARGS("ListUnitsByNames", |
| 3237 |
SD_BUS_ARGS("as", names), |
| 3238 |
SD_BUS_RESULT("a(ssssssouso)", units), |
| 3239 |
method_list_units_by_names, |
| 3240 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3241 |
SD_BUS_METHOD_WITH_ARGS("ListJobs", |
| 3242 |
SD_BUS_NO_ARGS, |
| 3243 |
SD_BUS_RESULT("a(usssoo)", jobs), |
| 3244 |
method_list_jobs, |
| 3245 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3246 |
SD_BUS_METHOD("Subscribe", |
| 3247 |
NULL, |
| 3248 |
NULL, |
| 3249 |
method_subscribe, |
| 3250 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3251 |
SD_BUS_METHOD("Unsubscribe", |
| 3252 |
NULL, |
| 3253 |
NULL, |
| 3254 |
method_unsubscribe, |
| 3255 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3256 |
SD_BUS_METHOD_WITH_ARGS("Dump", |
| 3257 |
SD_BUS_NO_ARGS, |
| 3258 |
SD_BUS_RESULT("s", output), |
| 3259 |
method_dump, |
| 3260 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3261 |
SD_BUS_METHOD_WITH_ARGS("DumpUnitsMatchingPatterns", |
| 3262 |
SD_BUS_ARGS("as", patterns), |
| 3263 |
SD_BUS_RESULT("s", output), |
| 3264 |
method_dump_units_matching_patterns, |
| 3265 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3266 |
SD_BUS_METHOD_WITH_ARGS("DumpByFileDescriptor", |
| 3267 |
SD_BUS_NO_ARGS, |
| 3268 |
SD_BUS_RESULT("h", fd), |
| 3269 |
method_dump_by_fd, |
| 3270 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3271 |
SD_BUS_METHOD_WITH_ARGS("DumpUnitsMatchingPatternsByFileDescriptor", |
| 3272 |
SD_BUS_ARGS("as", patterns), |
| 3273 |
SD_BUS_RESULT("h", fd), |
| 3274 |
method_dump_units_matching_patterns_by_fd, |
| 3275 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3276 |
SD_BUS_METHOD_WITH_ARGS("CreateSnapshot", |
| 3277 |
SD_BUS_ARGS("s", name, "b", cleanup), |
| 3278 |
SD_BUS_RESULT("o", unit), |
| 3279 |
method_refuse_snapshot, |
| 3280 |
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), |
| 3281 |
SD_BUS_METHOD_WITH_ARGS("RemoveSnapshot", |
| 3282 |
SD_BUS_ARGS("s", name), |
| 3283 |
SD_BUS_NO_RESULT, |
| 3284 |
method_refuse_snapshot, |
| 3285 |
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), |
| 3286 |
SD_BUS_METHOD("Reload", |
| 3287 |
NULL, |
| 3288 |
NULL, |
| 3289 |
method_reload, |
| 3290 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3291 |
SD_BUS_METHOD("Reexecute", |
| 3292 |
NULL, |
| 3293 |
NULL, |
| 3294 |
method_reexecute, |
| 3295 |
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_METHOD_NO_REPLY), |
| 3296 |
SD_BUS_METHOD("Exit", |
| 3297 |
NULL, |
| 3298 |
NULL, |
| 3299 |
method_exit, |
| 3300 |
0), |
| 3301 |
SD_BUS_METHOD("Reboot", |
| 3302 |
NULL, |
| 3303 |
NULL, |
| 3304 |
method_reboot, |
| 3305 |
SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), |
| 3306 |
SD_BUS_METHOD_WITH_ARGS("SoftReboot", |
| 3307 |
SD_BUS_ARGS("s", new_root), |
| 3308 |
SD_BUS_NO_RESULT, |
| 3309 |
method_soft_reboot, |
| 3310 |
SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), |
| 3311 |
SD_BUS_METHOD("PowerOff", |
| 3312 |
NULL, |
| 3313 |
NULL, |
| 3314 |
method_poweroff, |
| 3315 |
SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), |
| 3316 |
SD_BUS_METHOD("Halt", |
| 3317 |
NULL, |
| 3318 |
NULL, |
| 3319 |
method_halt, |
| 3320 |
SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), |
| 3321 |
SD_BUS_METHOD("KExec", |
| 3322 |
NULL, |
| 3323 |
NULL, |
| 3324 |
method_kexec, |
| 3325 |
SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), |
| 3326 |
SD_BUS_METHOD_WITH_ARGS("SwitchRoot", |
| 3327 |
SD_BUS_ARGS("s", new_root, "s", init), |
| 3328 |
SD_BUS_NO_RESULT, |
| 3329 |
method_switch_root, |
| 3330 |
SD_BUS_VTABLE_CAPABILITY(CAP_SYS_BOOT)), |
| 3331 |
SD_BUS_METHOD_WITH_ARGS("SetEnvironment", |
| 3332 |
SD_BUS_ARGS("as", assignments), |
| 3333 |
SD_BUS_NO_RESULT, |
| 3334 |
method_set_environment, |
| 3335 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3336 |
SD_BUS_METHOD_WITH_ARGS("UnsetEnvironment", |
| 3337 |
SD_BUS_ARGS("as", names), |
| 3338 |
SD_BUS_NO_RESULT, |
| 3339 |
method_unset_environment, |
| 3340 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3341 |
SD_BUS_METHOD_WITH_ARGS("UnsetAndSetEnvironment", |
| 3342 |
SD_BUS_ARGS("as", names, "as", assignments), |
| 3343 |
SD_BUS_NO_RESULT, |
| 3344 |
method_unset_and_set_environment, |
| 3345 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3346 |
SD_BUS_METHOD_WITH_ARGS("EnqueueMarkedJobs", |
| 3347 |
SD_BUS_NO_ARGS, |
| 3348 |
SD_BUS_RESULT("ao", jobs), |
| 3349 |
method_enqueue_marked_jobs, |
| 3350 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3351 |
SD_BUS_METHOD_WITH_ARGS("ListUnitFiles", |
| 3352 |
SD_BUS_NO_ARGS, |
| 3353 |
SD_BUS_RESULT("a(ss)", unit_files), |
| 3354 |
method_list_unit_files, |
| 3355 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3356 |
SD_BUS_METHOD_WITH_ARGS("ListUnitFilesByPatterns", |
| 3357 |
SD_BUS_ARGS("as", states, "as", patterns), |
| 3358 |
SD_BUS_RESULT("a(ss)", unit_files), |
| 3359 |
method_list_unit_files_by_patterns, |
| 3360 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3361 |
SD_BUS_METHOD_WITH_ARGS("GetUnitFileState", |
| 3362 |
SD_BUS_ARGS("s", file), |
| 3363 |
SD_BUS_RESULT("s", state), |
| 3364 |
method_get_unit_file_state, |
| 3365 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3366 |
SD_BUS_METHOD_WITH_ARGS("EnableUnitFiles", |
| 3367 |
SD_BUS_ARGS("as", files, "b", runtime, "b", force), |
| 3368 |
SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), |
| 3369 |
method_enable_unit_files, |
| 3370 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3371 |
SD_BUS_METHOD_WITH_ARGS("DisableUnitFiles", |
| 3372 |
SD_BUS_ARGS("as", files, "b", runtime), |
| 3373 |
SD_BUS_RESULT("a(sss)", changes), |
| 3374 |
method_disable_unit_files, |
| 3375 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3376 |
SD_BUS_METHOD_WITH_ARGS("EnableUnitFilesWithFlags", |
| 3377 |
SD_BUS_ARGS("as", files, "t", flags), |
| 3378 |
SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), |
| 3379 |
method_enable_unit_files_with_flags, |
| 3380 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3381 |
SD_BUS_METHOD_WITH_ARGS("DisableUnitFilesWithFlags", |
| 3382 |
SD_BUS_ARGS("as", files, "t", flags), |
| 3383 |
SD_BUS_RESULT("a(sss)", changes), |
| 3384 |
method_disable_unit_files_with_flags, |
| 3385 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3386 |
SD_BUS_METHOD_WITH_ARGS("DisableUnitFilesWithFlagsAndInstallInfo", |
| 3387 |
SD_BUS_ARGS("as", files, "t", flags), |
| 3388 |
SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), |
| 3389 |
method_disable_unit_files_with_flags_and_install_info, |
| 3390 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3391 |
SD_BUS_METHOD_WITH_ARGS("ReenableUnitFiles", |
| 3392 |
SD_BUS_ARGS("as", files, "b", runtime, "b", force), |
| 3393 |
SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), |
| 3394 |
method_reenable_unit_files, |
| 3395 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3396 |
SD_BUS_METHOD_WITH_ARGS("LinkUnitFiles", |
| 3397 |
SD_BUS_ARGS("as", files, "b", runtime, "b", force), |
| 3398 |
SD_BUS_RESULT("a(sss)", changes), |
| 3399 |
method_link_unit_files, |
| 3400 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3401 |
SD_BUS_METHOD_WITH_ARGS("PresetUnitFiles", |
| 3402 |
SD_BUS_ARGS("as", files, "b", runtime, "b", force), |
| 3403 |
SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), |
| 3404 |
method_preset_unit_files, |
| 3405 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3406 |
SD_BUS_METHOD_WITH_ARGS("PresetUnitFilesWithMode", |
| 3407 |
SD_BUS_ARGS("as", files, "s", mode, "b", runtime, "b", force), |
| 3408 |
SD_BUS_RESULT("b", carries_install_info, "a(sss)", changes), |
| 3409 |
method_preset_unit_files_with_mode, |
| 3410 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3411 |
SD_BUS_METHOD_WITH_ARGS("MaskUnitFiles", |
| 3412 |
SD_BUS_ARGS("as", files, "b", runtime, "b", force), |
| 3413 |
SD_BUS_RESULT("a(sss)", changes), |
| 3414 |
method_mask_unit_files, |
| 3415 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3416 |
SD_BUS_METHOD_WITH_ARGS("UnmaskUnitFiles", |
| 3417 |
SD_BUS_ARGS("as", files, "b", runtime), |
| 3418 |
SD_BUS_RESULT("a(sss)", changes), |
| 3419 |
method_unmask_unit_files, |
| 3420 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3421 |
SD_BUS_METHOD_WITH_ARGS("RevertUnitFiles", |
| 3422 |
SD_BUS_ARGS("as", files), |
| 3423 |
SD_BUS_RESULT("a(sss)", changes), |
| 3424 |
method_revert_unit_files, |
| 3425 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3426 |
SD_BUS_METHOD_WITH_ARGS("SetDefaultTarget", |
| 3427 |
SD_BUS_ARGS("s", name, "b", force), |
| 3428 |
SD_BUS_RESULT("a(sss)", changes), |
| 3429 |
method_set_default_target, |
| 3430 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3431 |
SD_BUS_METHOD_WITH_ARGS("GetDefaultTarget", |
| 3432 |
SD_BUS_NO_ARGS, |
| 3433 |
SD_BUS_RESULT("s", name), |
| 3434 |
method_get_default_target, |
| 3435 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3436 |
SD_BUS_METHOD_WITH_ARGS("PresetAllUnitFiles", |
| 3437 |
SD_BUS_ARGS("s", mode, "b", runtime, "b", force), |
| 3438 |
SD_BUS_RESULT("a(sss)", changes), |
| 3439 |
method_preset_all_unit_files, |
| 3440 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3441 |
SD_BUS_METHOD_WITH_ARGS("AddDependencyUnitFiles", |
| 3442 |
SD_BUS_ARGS("as", files, "s", target, "s", type, "b", runtime, "b", force), |
| 3443 |
SD_BUS_RESULT("a(sss)", changes), |
| 3444 |
method_add_dependency_unit_files, |
| 3445 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3446 |
SD_BUS_METHOD_WITH_ARGS("GetUnitFileLinks", |
| 3447 |
SD_BUS_ARGS("s", name, "b", runtime), |
| 3448 |
SD_BUS_RESULT("as", links), |
| 3449 |
method_get_unit_file_links, |
| 3450 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3451 |
SD_BUS_METHOD_WITH_ARGS("SetExitCode", |
| 3452 |
SD_BUS_ARGS("y", number), |
| 3453 |
SD_BUS_NO_RESULT, |
| 3454 |
method_set_exit_code, |
| 3455 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3456 |
SD_BUS_METHOD_WITH_ARGS("LookupDynamicUserByName", |
| 3457 |
SD_BUS_ARGS("s", name), |
| 3458 |
SD_BUS_RESULT("u", uid), |
| 3459 |
method_lookup_dynamic_user_by_name, |
| 3460 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3461 |
SD_BUS_METHOD_WITH_ARGS("LookupDynamicUserByUID", |
| 3462 |
SD_BUS_ARGS("u", uid), |
| 3463 |
SD_BUS_RESULT("s", name), |
| 3464 |
method_lookup_dynamic_user_by_uid, |
| 3465 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3466 |
SD_BUS_METHOD_WITH_ARGS("GetDynamicUsers", |
| 3467 |
SD_BUS_NO_ARGS, |
| 3468 |
SD_BUS_RESULT("a(us)", users), |
| 3469 |
method_get_dynamic_users, |
| 3470 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3471 |
SD_BUS_METHOD_WITH_ARGS("DumpUnitFileDescriptorStore", |
| 3472 |
SD_BUS_ARGS("s", name), |
| 3473 |
SD_BUS_RESULT("a(suuutuusu)", entries), |
| 3474 |
method_dump_unit_descriptor_store, |
| 3475 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 3476 |
SD_BUS_METHOD_WITH_ARGS("StartAuxiliaryScope", |
| 3477 |
SD_BUS_ARGS("s", name, "ah", pidfds, "t", flags, "a(sv)", properties), |
| 3478 |
SD_BUS_RESULT("o", job), |
| 3479 |
method_start_aux_scope, |
| 3480 |
SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_HIDDEN), |
| 3481 |
|
| 3482 |
SD_BUS_SIGNAL_WITH_ARGS("UnitNew", |
| 3483 |
SD_BUS_ARGS("s", id, "o", unit), |
| 3484 |
0), |
| 3485 |
SD_BUS_SIGNAL_WITH_ARGS("UnitRemoved", |
| 3486 |
SD_BUS_ARGS("s", id, "o", unit), |
| 3487 |
0), |
| 3488 |
SD_BUS_SIGNAL_WITH_ARGS("JobNew", |
| 3489 |
SD_BUS_ARGS("u", id, "o", job, "s", unit), |
| 3490 |
0), |
| 3491 |
SD_BUS_SIGNAL_WITH_ARGS("JobRemoved", |
| 3492 |
SD_BUS_ARGS("u", id, "o", job, "s", unit, "s", result), |
| 3493 |
0), |
| 3494 |
SD_BUS_SIGNAL_WITH_ARGS("StartupFinished", |
| 3495 |
SD_BUS_ARGS("t", firmware, "t", loader, "t", kernel, "t", initrd, "t", userspace, "t", total), |
| 3496 |
0), |
| 3497 |
SD_BUS_SIGNAL("UnitFilesChanged", NULL, 0), |
| 3498 |
SD_BUS_SIGNAL_WITH_ARGS("Reloading", |
| 3499 |
SD_BUS_ARGS("b", active), |
| 3500 |
0), |
| 3501 |
|
| 3502 |
SD_BUS_VTABLE_END |
| 3503 |
}; |
| 3504 |
|
| 3505 |
const sd_bus_vtable bus_manager_log_control_vtable[] = { |
| 3506 |
SD_BUS_VTABLE_START(0), |
| 3507 |
|
| 3508 |
/* We define a private version of this interface here, since we want slightly different |
| 3509 |
* implementations for the setters. We'll still use the generic getters however, and we share the |
| 3510 |
* setters with the implementations for the Manager interface above (which pre-dates the generic |
| 3511 |
* service API interface). */ |
| 3512 |
|
| 3513 |
SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0), |
| 3514 |
SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0), |
| 3515 |
SD_BUS_PROPERTY("SyslogIdentifier", "s", bus_property_get_syslog_identifier, 0, 0), |
| 3516 |
|
| 3517 |
SD_BUS_VTABLE_END, |
| 3518 |
}; |
| 3519 |
|
| 3520 |
static int send_finished(sd_bus *bus, void *userdata) { |
| 3521 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
| 3522 |
usec_t *times = ASSERT_PTR(userdata); |
| 3523 |
int r; |
| 3524 |
|
| 3525 |
assert(bus); |
| 3526 |
|
| 3527 |
r = sd_bus_message_new_signal(bus, |
| 3528 |
&message, |
| 3529 |
"/org/freedesktop/systemd1", |
| 3530 |
"org.freedesktop.systemd1.Manager", |
| 3531 |
"StartupFinished"); |
| 3532 |
if (r < 0) |
| 3533 |
return r; |
| 3534 |
|
| 3535 |
r = sd_bus_message_append(message, "tttttt", times[0], times[1], times[2], times[3], times[4], times[5]); |
| 3536 |
if (r < 0) |
| 3537 |
return r; |
| 3538 |
|
| 3539 |
return sd_bus_send(bus, message, NULL); |
| 3540 |
} |
| 3541 |
|
| 3542 |
void bus_manager_send_finished( |
| 3543 |
Manager *m, |
| 3544 |
usec_t firmware_usec, |
| 3545 |
usec_t loader_usec, |
| 3546 |
usec_t kernel_usec, |
| 3547 |
usec_t initrd_usec, |
| 3548 |
usec_t userspace_usec, |
| 3549 |
usec_t total_usec) { |
| 3550 |
|
| 3551 |
int r; |
| 3552 |
|
| 3553 |
assert(m); |
| 3554 |
|
| 3555 |
r = bus_foreach_bus( |
| 3556 |
m, |
| 3557 |
NULL, |
| 3558 |
send_finished, |
| 3559 |
(usec_t[6]) { |
| 3560 |
firmware_usec, |
| 3561 |
loader_usec, |
| 3562 |
kernel_usec, |
| 3563 |
initrd_usec, |
| 3564 |
userspace_usec, |
| 3565 |
total_usec |
| 3566 |
}); |
| 3567 |
if (r < 0) |
| 3568 |
log_debug_errno(r, "Failed to send finished signal: %m"); |
| 3569 |
} |
| 3570 |
|
| 3571 |
static int send_reloading(sd_bus *bus, void *userdata) { |
| 3572 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL; |
| 3573 |
int r; |
| 3574 |
|
| 3575 |
assert(bus); |
| 3576 |
|
| 3577 |
r = sd_bus_message_new_signal(bus, &message, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading"); |
| 3578 |
if (r < 0) |
| 3579 |
return r; |
| 3580 |
|
| 3581 |
r = sd_bus_message_append(message, "b", PTR_TO_INT(userdata)); |
| 3582 |
if (r < 0) |
| 3583 |
return r; |
| 3584 |
|
| 3585 |
return sd_bus_send(bus, message, NULL); |
| 3586 |
} |
| 3587 |
|
| 3588 |
void bus_manager_send_reloading(Manager *m, bool active) { |
| 3589 |
int r; |
| 3590 |
|
| 3591 |
assert(m); |
| 3592 |
|
| 3593 |
r = bus_foreach_bus(m, NULL, send_reloading, INT_TO_PTR(active)); |
| 3594 |
if (r < 0) |
| 3595 |
log_debug_errno(r, "Failed to send reloading signal: %m"); |
| 3596 |
} |
| 3597 |
|
| 3598 |
static int send_changed_signal(sd_bus *bus, void *userdata) { |
| 3599 |
assert(bus); |
| 3600 |
|
| 3601 |
return sd_bus_emit_properties_changed_strv(bus, |
| 3602 |
"/org/freedesktop/systemd1", |
| 3603 |
"org.freedesktop.systemd1.Manager", |
| 3604 |
NULL); |
| 3605 |
} |
| 3606 |
|
| 3607 |
void bus_manager_send_change_signal(Manager *m) { |
| 3608 |
int r; |
| 3609 |
|
| 3610 |
assert(m); |
| 3611 |
|
| 3612 |
r = bus_foreach_bus(m, NULL, send_changed_signal, NULL); |
| 3613 |
if (r < 0) |
| 3614 |
log_debug_errno(r, "Failed to send manager change signal: %m"); |
| 3615 |
} |