| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <fcntl.h> |
| 4 |
#include <sys/stat.h> |
| 5 |
#include <sys/sysmacros.h> |
| 6 |
|
| 7 |
#include "alloc-util.h" |
| 8 |
#include "async.h" |
| 9 |
#include "bus-common-errors.h" |
| 10 |
#include "bus-get-properties.h" |
| 11 |
#include "constants.h" |
| 12 |
#include "dbus-cgroup.h" |
| 13 |
#include "dbus-execute.h" |
| 14 |
#include "dbus-kill.h" |
| 15 |
#include "dbus-manager.h" |
| 16 |
#include "dbus-service.h" |
| 17 |
#include "dbus-util.h" |
| 18 |
#include "dissect-image.h" |
| 19 |
#include "execute.h" |
| 20 |
#include "exit-status.h" |
| 21 |
#include "fd-util.h" |
| 22 |
#include "glyph-util.h" |
| 23 |
#include "locale-util.h" |
| 24 |
#include "manager.h" |
| 25 |
#include "mount-util.h" |
| 26 |
#include "open-file.h" |
| 27 |
#include "path-util.h" |
| 28 |
#include "selinux-access.h" |
| 29 |
#include "service.h" |
| 30 |
#include "signal-util.h" |
| 31 |
#include "stat-util.h" |
| 32 |
#include "string-util.h" |
| 33 |
#include "strv.h" |
| 34 |
#include "unit.h" |
| 35 |
|
| 36 |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, service_type, ServiceType); |
| 37 |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exit_type, service_exit_type, ServiceExitType); |
| 38 |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, service_result, ServiceResult); |
| 39 |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_restart, service_restart, ServiceRestart); |
| 40 |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_restart_mode, service_restart_mode, ServiceRestartMode); |
| 41 |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_emergency_action, emergency_action, EmergencyAction); |
| 42 |
static BUS_DEFINE_PROPERTY_GET2(property_get_notify_access, "s", Service, service_get_notify_access, notify_access_to_string); |
| 43 |
static BUS_DEFINE_PROPERTY_GET(property_get_restart_usec_next, "t", Service, service_restart_usec_next); |
| 44 |
static BUS_DEFINE_PROPERTY_GET(property_get_timeout_abort_usec, "t", Service, service_timeout_abort_usec); |
| 45 |
static BUS_DEFINE_PROPERTY_GET(property_get_watchdog_usec, "t", Service, service_get_watchdog_usec); |
| 46 |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_timeout_failure_mode, service_timeout_failure_mode, ServiceTimeoutFailureMode); |
| 47 |
|
| 48 |
static int property_get_open_files( |
| 49 |
sd_bus *bus, |
| 50 |
const char *path, |
| 51 |
const char *interface, |
| 52 |
const char *property, |
| 53 |
sd_bus_message *reply, |
| 54 |
void *userdata, |
| 55 |
sd_bus_error *reterr_error) { |
| 56 |
|
| 57 |
OpenFile **open_files = ASSERT_PTR(userdata); |
| 58 |
int r; |
| 59 |
|
| 60 |
assert(bus); |
| 61 |
assert(reply); |
| 62 |
|
| 63 |
r = sd_bus_message_open_container(reply, 'a', "(sst)"); |
| 64 |
if (r < 0) |
| 65 |
return r; |
| 66 |
|
| 67 |
LIST_FOREACH(open_files, of, *open_files) { |
| 68 |
r = sd_bus_message_append(reply, "(sst)", of->path, of->fdname, (uint64_t) of->flags); |
| 69 |
if (r < 0) |
| 70 |
return r; |
| 71 |
} |
| 72 |
|
| 73 |
return sd_bus_message_close_container(reply); |
| 74 |
} |
| 75 |
|
| 76 |
static int property_get_extra_file_descriptors( |
| 77 |
sd_bus *bus, |
| 78 |
const char *path, |
| 79 |
const char *interface, |
| 80 |
const char *property, |
| 81 |
sd_bus_message *reply, |
| 82 |
void *userdata, |
| 83 |
sd_bus_error *reterr_error) { |
| 84 |
|
| 85 |
Service *s = ASSERT_PTR(userdata); |
| 86 |
int r; |
| 87 |
|
| 88 |
assert(bus); |
| 89 |
assert(reply); |
| 90 |
|
| 91 |
r = sd_bus_message_open_container(reply, 'a', "s"); |
| 92 |
if (r < 0) |
| 93 |
return r; |
| 94 |
|
| 95 |
FOREACH_ARRAY(i, s->extra_fds, s->n_extra_fds) { |
| 96 |
r = sd_bus_message_append_basic(reply, 's', i->fdname); |
| 97 |
if (r < 0) |
| 98 |
return r; |
| 99 |
} |
| 100 |
|
| 101 |
return sd_bus_message_close_container(reply); |
| 102 |
} |
| 103 |
|
| 104 |
static int property_get_refresh_on_reload( |
| 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 |
Service *s = ASSERT_PTR(userdata); |
| 114 |
_cleanup_strv_free_ char **l = NULL; |
| 115 |
int r; |
| 116 |
|
| 117 |
assert(bus); |
| 118 |
assert(reply); |
| 119 |
|
| 120 |
r = service_refresh_on_reload_to_strv(s->refresh_on_reload_flags, &l); |
| 121 |
if (r < 0) |
| 122 |
return r; |
| 123 |
|
| 124 |
return sd_bus_message_append_strv(reply, l); |
| 125 |
} |
| 126 |
|
| 127 |
static int property_get_exit_status_set( |
| 128 |
sd_bus *bus, |
| 129 |
const char *path, |
| 130 |
const char *interface, |
| 131 |
const char *property, |
| 132 |
sd_bus_message *reply, |
| 133 |
void *userdata, |
| 134 |
sd_bus_error *reterr_error) { |
| 135 |
|
| 136 |
const ExitStatusSet *status_set = ASSERT_PTR(userdata); |
| 137 |
unsigned n; |
| 138 |
int r; |
| 139 |
|
| 140 |
assert(bus); |
| 141 |
assert(reply); |
| 142 |
|
| 143 |
r = sd_bus_message_open_container(reply, 'r', "aiai"); |
| 144 |
if (r < 0) |
| 145 |
return r; |
| 146 |
|
| 147 |
r = sd_bus_message_open_container(reply, 'a', "i"); |
| 148 |
if (r < 0) |
| 149 |
return r; |
| 150 |
|
| 151 |
BITMAP_FOREACH(n, &status_set->status) { |
| 152 |
assert(n < 256); |
| 153 |
|
| 154 |
r = sd_bus_message_append_basic(reply, 'i', &n); |
| 155 |
if (r < 0) |
| 156 |
return r; |
| 157 |
} |
| 158 |
|
| 159 |
r = sd_bus_message_close_container(reply); |
| 160 |
if (r < 0) |
| 161 |
return r; |
| 162 |
|
| 163 |
r = sd_bus_message_open_container(reply, 'a', "i"); |
| 164 |
if (r < 0) |
| 165 |
return r; |
| 166 |
|
| 167 |
BITMAP_FOREACH(n, &status_set->signal) { |
| 168 |
const char *str; |
| 169 |
|
| 170 |
str = signal_to_string(n); |
| 171 |
if (!str) |
| 172 |
continue; |
| 173 |
|
| 174 |
r = sd_bus_message_append_basic(reply, 'i', &n); |
| 175 |
if (r < 0) |
| 176 |
return r; |
| 177 |
} |
| 178 |
|
| 179 |
r = sd_bus_message_close_container(reply); |
| 180 |
if (r < 0) |
| 181 |
return r; |
| 182 |
|
| 183 |
return sd_bus_message_close_container(reply); |
| 184 |
} |
| 185 |
|
| 186 |
static int bus_service_method_mount(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error, bool is_image) { |
| 187 |
MountInNamespaceFlags flags = 0; |
| 188 |
Unit *u = ASSERT_PTR(userdata); |
| 189 |
int r; |
| 190 |
|
| 191 |
assert(message); |
| 192 |
|
| 193 |
if (!MANAGER_IS_SYSTEM(u->manager)) |
| 194 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_NOT_SUPPORTED, "Adding bind mounts at runtime is only supported by system manager"); |
| 195 |
|
| 196 |
r = unit_can_live_mount(u, reterr_error); |
| 197 |
if (r < 0) |
| 198 |
return log_unit_debug_errno(u, r, "Cannot schedule live mount operation: %s", bus_error_message(reterr_error, r)); |
| 199 |
|
| 200 |
r = mac_selinux_unit_access_check(u, message, "start", reterr_error); |
| 201 |
if (r < 0) |
| 202 |
return r; |
| 203 |
|
| 204 |
_cleanup_(mount_options_free_allp) MountOptions *options = NULL; |
| 205 |
const char *src, *dest; |
| 206 |
int read_only, make_file_or_directory; |
| 207 |
|
| 208 |
r = sd_bus_message_read(message, "ssbb", &src, &dest, &read_only, &make_file_or_directory); |
| 209 |
if (r < 0) |
| 210 |
return r; |
| 211 |
|
| 212 |
if (!path_is_absolute(src) || !path_is_normalized(src)) |
| 213 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path must be absolute and normalized"); |
| 214 |
|
| 215 |
if (!is_image && isempty(dest)) |
| 216 |
dest = src; |
| 217 |
else if (!path_is_absolute(dest) || !path_is_normalized(dest)) |
| 218 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path must be absolute and normalized"); |
| 219 |
|
| 220 |
if (is_image) { |
| 221 |
r = bus_read_mount_options(message, reterr_error, &options, |
| 222 |
/* in_out_format_str = */ NULL, /* separator = */ NULL); |
| 223 |
if (r < 0) |
| 224 |
return r; |
| 225 |
} |
| 226 |
|
| 227 |
r = bus_verify_manage_units_async_full( |
| 228 |
u, |
| 229 |
is_image ? "mount-image" : "bind-mount", |
| 230 |
N_("Authentication is required to mount on '$(unit)'."), |
| 231 |
message, |
| 232 |
reterr_error); |
| 233 |
if (r < 0) |
| 234 |
return r; |
| 235 |
if (r == 0) |
| 236 |
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ |
| 237 |
|
| 238 |
if (is_image) |
| 239 |
flags |= MOUNT_IN_NAMESPACE_IS_IMAGE; |
| 240 |
if (read_only) |
| 241 |
flags |= MOUNT_IN_NAMESPACE_READ_ONLY; |
| 242 |
if (make_file_or_directory) |
| 243 |
flags |= MOUNT_IN_NAMESPACE_MAKE_FILE_OR_DIRECTORY; |
| 244 |
|
| 245 |
r = unit_live_mount(u, src, dest, message, flags, options, reterr_error); |
| 246 |
if (r < 0) |
| 247 |
return r; |
| 248 |
|
| 249 |
return 1; |
| 250 |
} |
| 251 |
|
| 252 |
int bus_service_method_bind_mount(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 253 |
return bus_service_method_mount(message, userdata, reterr_error, false); |
| 254 |
} |
| 255 |
|
| 256 |
int bus_service_method_mount_image(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 257 |
return bus_service_method_mount(message, userdata, reterr_error, true); |
| 258 |
} |
| 259 |
|
| 260 |
int bus_service_method_dump_file_descriptor_store(sd_bus_message *message, void *userdata, sd_bus_error *reterr_error) { |
| 261 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 262 |
Service *s = ASSERT_PTR(userdata); |
| 263 |
int r; |
| 264 |
|
| 265 |
assert(message); |
| 266 |
|
| 267 |
r = mac_selinux_unit_access_check(UNIT(s), message, "status", reterr_error); |
| 268 |
if (r < 0) |
| 269 |
return r; |
| 270 |
|
| 271 |
if (s->n_fd_store_max == 0 && s->n_fd_store == 0) |
| 272 |
return sd_bus_error_setf(reterr_error, BUS_ERROR_FILE_DESCRIPTOR_STORE_DISABLED, "File descriptor store not enabled for %s.", UNIT(s)->id); |
| 273 |
|
| 274 |
r = sd_bus_message_new_method_return(message, &reply); |
| 275 |
if (r < 0) |
| 276 |
return r; |
| 277 |
|
| 278 |
r = sd_bus_message_open_container(reply, 'a', "(suuutuusu)"); |
| 279 |
if (r < 0) |
| 280 |
return r; |
| 281 |
|
| 282 |
LIST_FOREACH(fd_store, i, s->fd_store) { |
| 283 |
_cleanup_free_ char *path = NULL; |
| 284 |
struct stat st; |
| 285 |
int flags; |
| 286 |
|
| 287 |
if (fstat(i->fd, &st) < 0) { |
| 288 |
log_debug_errno(errno, "Failed to stat() file descriptor entry '%s', skipping.", strna(i->fdname)); |
| 289 |
continue; |
| 290 |
} |
| 291 |
|
| 292 |
flags = fcntl(i->fd, F_GETFL); |
| 293 |
if (flags < 0) { |
| 294 |
log_debug_errno(errno, "Failed to issue F_GETFL on file descriptor entry '%s', skipping.", strna(i->fdname)); |
| 295 |
continue; |
| 296 |
} |
| 297 |
|
| 298 |
/* glibc implies O_LARGEFILE everywhere on 64-bit off_t builds, but forgets to hide it away on |
| 299 |
* F_GETFL, but provides no definition to check for that. Let's mask the flag away manually, |
| 300 |
* to not confuse clients. */ |
| 301 |
flags &= ~RAW_O_LARGEFILE; |
| 302 |
|
| 303 |
(void) fd_get_path(i->fd, &path); |
| 304 |
|
| 305 |
r = sd_bus_message_append( |
| 306 |
reply, |
| 307 |
"(suuutuusu)", |
| 308 |
i->fdname, |
| 309 |
(uint32_t) st.st_mode, |
| 310 |
(uint32_t) major(st.st_dev), (uint32_t) minor(st.st_dev), |
| 311 |
(uint64_t) st.st_ino, |
| 312 |
(uint32_t) major(st.st_rdev), (uint32_t) minor(st.st_rdev), |
| 313 |
path, |
| 314 |
(uint32_t) flags); |
| 315 |
if (r < 0) |
| 316 |
return r; |
| 317 |
} |
| 318 |
|
| 319 |
r = sd_bus_message_close_container(reply); |
| 320 |
if (r < 0) |
| 321 |
return r; |
| 322 |
|
| 323 |
return sd_bus_message_send(reply); |
| 324 |
} |
| 325 |
|
| 326 |
#if __SIZEOF_SIZE_T__ == 8 |
| 327 |
static int property_get_size_as_uint32( |
| 328 |
sd_bus *bus, |
| 329 |
const char *path, |
| 330 |
const char *interface, |
| 331 |
const char *property, |
| 332 |
sd_bus_message *reply, |
| 333 |
void *userdata, |
| 334 |
sd_bus_error *reterr_error) { |
| 335 |
|
| 336 |
size_t *value = ASSERT_PTR(userdata); |
| 337 |
uint32_t sz = *value >= UINT32_MAX ? UINT32_MAX : (uint32_t) *value; |
| 338 |
|
| 339 |
/* Returns a size_t as a D-Bus "u" type, i.e. as 32-bit value, even if size_t is 64-bit. We'll saturate if it doesn't fit. */ |
| 340 |
|
| 341 |
return sd_bus_message_append_basic(reply, 'u', &sz); |
| 342 |
} |
| 343 |
#elif __SIZEOF_SIZE_T__ == 4 |
| 344 |
#define property_get_size_as_uint32 ((sd_bus_property_get_t) NULL) |
| 345 |
#else |
| 346 |
#error "Unexpected size of size_t" |
| 347 |
#endif |
| 348 |
|
| 349 |
const sd_bus_vtable bus_service_vtable[] = { |
| 350 |
SD_BUS_VTABLE_START(0), |
| 351 |
SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Service, type), SD_BUS_VTABLE_PROPERTY_CONST), |
| 352 |
SD_BUS_PROPERTY("ExitType", "s", property_get_exit_type, offsetof(Service, exit_type), SD_BUS_VTABLE_PROPERTY_CONST), |
| 353 |
SD_BUS_PROPERTY("Restart", "s", property_get_restart, offsetof(Service, restart), SD_BUS_VTABLE_PROPERTY_CONST), |
| 354 |
SD_BUS_PROPERTY("RestartMode", "s", property_get_restart_mode, offsetof(Service, restart_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
| 355 |
SD_BUS_PROPERTY("PIDFile", "s", NULL, offsetof(Service, pid_file), SD_BUS_VTABLE_PROPERTY_CONST), |
| 356 |
SD_BUS_PROPERTY("NotifyAccess", "s", property_get_notify_access, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 357 |
SD_BUS_PROPERTY("RestartUSec", "t", bus_property_get_usec, offsetof(Service, restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 358 |
SD_BUS_PROPERTY("RestartSteps", "u", bus_property_get_unsigned, offsetof(Service, restart_steps), SD_BUS_VTABLE_PROPERTY_CONST), |
| 359 |
SD_BUS_PROPERTY("RestartMaxDelayUSec", "t", bus_property_get_usec, offsetof(Service, restart_max_delay_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 360 |
SD_BUS_PROPERTY("RestartUSecNext", "t", property_get_restart_usec_next, 0, 0), |
| 361 |
SD_BUS_PROPERTY("TimeoutStartUSec", "t", bus_property_get_usec, offsetof(Service, timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 362 |
SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Service, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 363 |
SD_BUS_PROPERTY("TimeoutAbortUSec", "t", property_get_timeout_abort_usec, 0, 0), |
| 364 |
SD_BUS_PROPERTY("TimeoutStartFailureMode", "s", property_get_timeout_failure_mode, offsetof(Service, timeout_start_failure_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
| 365 |
SD_BUS_PROPERTY("TimeoutStopFailureMode", "s", property_get_timeout_failure_mode, offsetof(Service, timeout_stop_failure_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
| 366 |
SD_BUS_PROPERTY("RuntimeMaxUSec", "t", bus_property_get_usec, offsetof(Service, runtime_max_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 367 |
SD_BUS_PROPERTY("RuntimeRandomizedExtraUSec", "t", bus_property_get_usec, offsetof(Service, runtime_rand_extra_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
| 368 |
SD_BUS_PROPERTY("WatchdogUSec", "t", property_get_watchdog_usec, 0, 0), |
| 369 |
BUS_PROPERTY_DUAL_TIMESTAMP("WatchdogTimestamp", offsetof(Service, watchdog_timestamp), 0), |
| 370 |
SD_BUS_PROPERTY("PermissionsStartOnly", "b", bus_property_get_bool, offsetof(Service, permissions_start_only), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), /* 😷 deprecated */ |
| 371 |
SD_BUS_PROPERTY("RootDirectoryStartOnly", "b", bus_property_get_bool, offsetof(Service, root_directory_start_only), SD_BUS_VTABLE_PROPERTY_CONST), |
| 372 |
SD_BUS_PROPERTY("RemainAfterExit", "b", bus_property_get_bool, offsetof(Service, remain_after_exit), SD_BUS_VTABLE_PROPERTY_CONST), |
| 373 |
SD_BUS_PROPERTY("GuessMainPID", "b", bus_property_get_bool, offsetof(Service, guess_main_pid), SD_BUS_VTABLE_PROPERTY_CONST), |
| 374 |
SD_BUS_PROPERTY("RestartPreventExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, restart_prevent_status), SD_BUS_VTABLE_PROPERTY_CONST), |
| 375 |
SD_BUS_PROPERTY("RestartForceExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, restart_force_status), SD_BUS_VTABLE_PROPERTY_CONST), |
| 376 |
SD_BUS_PROPERTY("SuccessExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, success_status), SD_BUS_VTABLE_PROPERTY_CONST), |
| 377 |
SD_BUS_PROPERTY("MainPID", "u", bus_property_get_pid, offsetof(Service, main_pid.pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 378 |
SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Service, control_pid.pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 379 |
SD_BUS_PROPERTY("BusName", "s", NULL, offsetof(Service, bus_name), SD_BUS_VTABLE_PROPERTY_CONST), |
| 380 |
SD_BUS_PROPERTY("FileDescriptorStoreMax", "u", bus_property_get_unsigned, offsetof(Service, n_fd_store_max), SD_BUS_VTABLE_PROPERTY_CONST), |
| 381 |
SD_BUS_PROPERTY("NFileDescriptorStore", "u", property_get_size_as_uint32, offsetof(Service, n_fd_store), 0), |
| 382 |
SD_BUS_PROPERTY("FileDescriptorStorePreserve", "s", bus_property_get_exec_preserve_mode, offsetof(Service, fd_store_preserve_mode), 0), |
| 383 |
SD_BUS_PROPERTY("StatusText", "s", NULL, offsetof(Service, status_text), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 384 |
SD_BUS_PROPERTY("StatusErrno", "i", bus_property_get_int, offsetof(Service, status_errno), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 385 |
SD_BUS_PROPERTY("StatusBusError", "s", NULL, offsetof(Service, status_bus_error), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 386 |
SD_BUS_PROPERTY("StatusVarlinkError", "s", NULL, offsetof(Service, status_varlink_error), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 387 |
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Service, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 388 |
SD_BUS_PROPERTY("ReloadResult", "s", property_get_result, offsetof(Service, reload_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 389 |
SD_BUS_PROPERTY("CleanResult", "s", property_get_result, offsetof(Service, clean_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 390 |
SD_BUS_PROPERTY("LiveMountResult", "s", property_get_result, offsetof(Service, live_mount_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 391 |
SD_BUS_PROPERTY("USBFunctionDescriptors", "s", NULL, offsetof(Service, usb_function_descriptors), SD_BUS_VTABLE_PROPERTY_CONST), |
| 392 |
SD_BUS_PROPERTY("USBFunctionStrings", "s", NULL, offsetof(Service, usb_function_strings), SD_BUS_VTABLE_PROPERTY_CONST), |
| 393 |
SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 394 |
SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 395 |
SD_BUS_PROPERTY("NRestarts", "u", bus_property_get_unsigned, offsetof(Service, n_restarts), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 396 |
SD_BUS_PROPERTY("OOMPolicy", "s", bus_property_get_oom_policy, offsetof(Service, oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), |
| 397 |
SD_BUS_PROPERTY("OpenFile", "a(sst)", property_get_open_files, offsetof(Service, open_files), SD_BUS_VTABLE_PROPERTY_CONST), |
| 398 |
SD_BUS_PROPERTY("ExtraFileDescriptorNames", "as", property_get_extra_file_descriptors, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 399 |
SD_BUS_PROPERTY("ReloadSignal", "i", bus_property_get_int, offsetof(Service, reload_signal), SD_BUS_VTABLE_PROPERTY_CONST), |
| 400 |
SD_BUS_PROPERTY("RefreshOnReload", "as", property_get_refresh_on_reload, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 401 |
|
| 402 |
BUS_EXEC_STATUS_VTABLE("ExecMain", offsetof(Service, main_exec_status), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 403 |
BUS_EXEC_COMMAND_LIST_VTABLE("ExecCondition", offsetof(Service, exec_command[SERVICE_EXEC_CONDITION]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 404 |
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecConditionEx", offsetof(Service, exec_command[SERVICE_EXEC_CONDITION]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 405 |
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPre", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 406 |
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartPreEx", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 407 |
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStart", offsetof(Service, exec_command[SERVICE_EXEC_START]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 408 |
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartEx", offsetof(Service, exec_command[SERVICE_EXEC_START]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 409 |
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPost", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 410 |
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartPostEx", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 411 |
BUS_EXEC_COMMAND_LIST_VTABLE("ExecReload", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 412 |
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecReloadEx", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 413 |
BUS_EXEC_COMMAND_LIST_VTABLE("ExecReloadPost", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 414 |
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecReloadPostEx", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 415 |
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStop", offsetof(Service, exec_command[SERVICE_EXEC_STOP]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 416 |
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStopEx", offsetof(Service, exec_command[SERVICE_EXEC_STOP]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 417 |
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStopPost", offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 418 |
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStopPostEx", offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
| 419 |
|
| 420 |
SD_BUS_METHOD_WITH_ARGS("BindMount", |
| 421 |
SD_BUS_ARGS("s", source, "s", destination, "b", read_only, "b", mkdir), |
| 422 |
SD_BUS_NO_RESULT, |
| 423 |
bus_service_method_bind_mount, |
| 424 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 425 |
|
| 426 |
SD_BUS_METHOD_WITH_ARGS("MountImage", |
| 427 |
SD_BUS_ARGS("s", source, "s", destination, "b", read_only, "b", mkdir, "a(ss)", options), |
| 428 |
SD_BUS_NO_RESULT, |
| 429 |
bus_service_method_mount_image, |
| 430 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 431 |
|
| 432 |
SD_BUS_METHOD_WITH_ARGS("DumpFileDescriptorStore", |
| 433 |
SD_BUS_NO_ARGS, |
| 434 |
SD_BUS_ARGS("a(suuutuusu)", entries), |
| 435 |
bus_service_method_dump_file_descriptor_store, |
| 436 |
SD_BUS_VTABLE_UNPRIVILEGED), |
| 437 |
|
| 438 |
/* The following four are obsolete, and thus marked hidden here. They moved into the Unit interface */ |
| 439 |
SD_BUS_PROPERTY("StartLimitInterval", "t", bus_property_get_usec, offsetof(Unit, start_ratelimit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
| 440 |
SD_BUS_PROPERTY("StartLimitBurst", "u", bus_property_get_unsigned, offsetof(Unit, start_ratelimit.burst), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
| 441 |
SD_BUS_PROPERTY("StartLimitAction", "s", property_get_emergency_action, offsetof(Unit, start_limit_action), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
| 442 |
SD_BUS_PROPERTY("FailureAction", "s", property_get_emergency_action, offsetof(Unit, failure_action), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
| 443 |
SD_BUS_PROPERTY("RebootArgument", "s", NULL, offsetof(Unit, reboot_arg), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
| 444 |
SD_BUS_VTABLE_END |
| 445 |
}; |
| 446 |
|
| 447 |
static int bus_set_transient_exit_status( |
| 448 |
Unit *u, |
| 449 |
const char *name, |
| 450 |
ExitStatusSet *status_set, |
| 451 |
sd_bus_message *message, |
| 452 |
UnitWriteFlags flags, |
| 453 |
sd_bus_error *reterr_error) { |
| 454 |
|
| 455 |
const int32_t *status, *signal; |
| 456 |
size_t n_status, n_signal, i; |
| 457 |
int r; |
| 458 |
|
| 459 |
r = sd_bus_message_enter_container(message, 'r', "aiai"); |
| 460 |
if (r < 0) |
| 461 |
return r; |
| 462 |
|
| 463 |
r = sd_bus_message_read_array(message, 'i', (const void **) &status, &n_status); |
| 464 |
if (r < 0) |
| 465 |
return r; |
| 466 |
|
| 467 |
r = sd_bus_message_read_array(message, 'i', (const void **) &signal, &n_signal); |
| 468 |
if (r < 0) |
| 469 |
return r; |
| 470 |
|
| 471 |
r = sd_bus_message_exit_container(message); |
| 472 |
if (r < 0) |
| 473 |
return r; |
| 474 |
|
| 475 |
n_status /= sizeof(int32_t); |
| 476 |
n_signal /= sizeof(int32_t); |
| 477 |
|
| 478 |
if (n_status == 0 && n_signal == 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 479 |
exit_status_set_free(status_set); |
| 480 |
unit_write_settingf(u, flags, name, "%s=", name); |
| 481 |
return 1; |
| 482 |
} |
| 483 |
|
| 484 |
for (i = 0; i < n_status; i++) { |
| 485 |
if (status[i] < 0 || status[i] > 255) |
| 486 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid status code in %s: %"PRIi32, name, status[i]); |
| 487 |
|
| 488 |
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 489 |
r = bitmap_set(&status_set->status, status[i]); |
| 490 |
if (r < 0) |
| 491 |
return r; |
| 492 |
|
| 493 |
unit_write_settingf(u, flags, name, "%s=%"PRIi32, name, status[i]); |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
for (i = 0; i < n_signal; i++) { |
| 498 |
const char *str; |
| 499 |
|
| 500 |
str = signal_to_string((int) signal[i]); |
| 501 |
if (!str) |
| 502 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal in %s: %"PRIi32, name, signal[i]); |
| 503 |
|
| 504 |
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 505 |
r = bitmap_set(&status_set->signal, signal[i]); |
| 506 |
if (r < 0) |
| 507 |
return r; |
| 508 |
|
| 509 |
unit_write_settingf(u, flags, name, "%s=%s", name, str); |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
return 1; |
| 514 |
} |
| 515 |
|
| 516 |
static int bus_set_transient_exec_context_fd( |
| 517 |
Unit *u, |
| 518 |
const char *name, |
| 519 |
int *p, |
| 520 |
bool *b, |
| 521 |
int verify_mode, |
| 522 |
sd_bus_message *message, |
| 523 |
UnitWriteFlags flags, |
| 524 |
sd_bus_error *reterr_error) { |
| 525 |
|
| 526 |
int fd, r; |
| 527 |
|
| 528 |
assert(name); |
| 529 |
assert(p); |
| 530 |
assert(b); |
| 531 |
assert((verify_mode & ~O_ACCMODE_STRICT) == 0); |
| 532 |
|
| 533 |
r = sd_bus_message_read(message, "h", &fd); |
| 534 |
if (r < 0) |
| 535 |
return r; |
| 536 |
|
| 537 |
r = fd_vet_accmode(fd, verify_mode); |
| 538 |
if (r < 0) |
| 539 |
return sd_bus_error_set_errnof(reterr_error, r, "%s passed is of incompatible type: %m", name); |
| 540 |
|
| 541 |
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 542 |
int copy; |
| 543 |
|
| 544 |
copy = fcntl(fd, F_DUPFD_CLOEXEC, 3); |
| 545 |
if (copy < 0) |
| 546 |
return -errno; |
| 547 |
|
| 548 |
asynchronous_close(*p); |
| 549 |
*p = copy; |
| 550 |
*b = true; |
| 551 |
} |
| 552 |
|
| 553 |
return 1; |
| 554 |
} |
| 555 |
static BUS_DEFINE_SET_TRANSIENT_PARSE(notify_access, NotifyAccess, notify_access_from_string); |
| 556 |
static BUS_DEFINE_SET_TRANSIENT_PARSE(service_type, ServiceType, service_type_from_string); |
| 557 |
static BUS_DEFINE_SET_TRANSIENT_PARSE(service_exit_type, ServiceExitType, service_exit_type_from_string); |
| 558 |
static BUS_DEFINE_SET_TRANSIENT_PARSE(service_restart, ServiceRestart, service_restart_from_string); |
| 559 |
static BUS_DEFINE_SET_TRANSIENT_PARSE(service_restart_mode, ServiceRestartMode, service_restart_mode_from_string); |
| 560 |
static BUS_DEFINE_SET_TRANSIENT_PARSE(oom_policy, OOMPolicy, oom_policy_from_string); |
| 561 |
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(bus_name, sd_bus_service_name_is_valid); |
| 562 |
static BUS_DEFINE_SET_TRANSIENT_PARSE(timeout_failure_mode, ServiceTimeoutFailureMode, service_timeout_failure_mode_from_string); |
| 563 |
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(reload_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check); |
| 564 |
|
| 565 |
static int bus_service_set_transient_property( |
| 566 |
Service *s, |
| 567 |
const char *name, |
| 568 |
sd_bus_message *message, |
| 569 |
UnitWriteFlags flags, |
| 570 |
sd_bus_error *reterr_error) { |
| 571 |
|
| 572 |
Unit *u = UNIT(s); |
| 573 |
ServiceExecCommand ci; |
| 574 |
int r; |
| 575 |
|
| 576 |
assert(s); |
| 577 |
assert(name); |
| 578 |
assert(message); |
| 579 |
|
| 580 |
flags |= UNIT_PRIVATE; |
| 581 |
|
| 582 |
if (streq(name, "PermissionsStartOnly")) |
| 583 |
return bus_set_transient_bool(u, name, &s->permissions_start_only, message, flags, reterr_error); |
| 584 |
|
| 585 |
if (streq(name, "RootDirectoryStartOnly")) |
| 586 |
return bus_set_transient_bool(u, name, &s->root_directory_start_only, message, flags, reterr_error); |
| 587 |
|
| 588 |
if (streq(name, "RemainAfterExit")) |
| 589 |
return bus_set_transient_bool(u, name, &s->remain_after_exit, message, flags, reterr_error); |
| 590 |
|
| 591 |
if (streq(name, "GuessMainPID")) |
| 592 |
return bus_set_transient_bool(u, name, &s->guess_main_pid, message, flags, reterr_error); |
| 593 |
|
| 594 |
if (streq(name, "Type")) |
| 595 |
return bus_set_transient_service_type(u, name, &s->type, message, flags, reterr_error); |
| 596 |
|
| 597 |
if (streq(name, "ExitType")) |
| 598 |
return bus_set_transient_service_exit_type(u, name, &s->exit_type, message, flags, reterr_error); |
| 599 |
|
| 600 |
if (streq(name, "OOMPolicy")) |
| 601 |
return bus_set_transient_oom_policy(u, name, &s->oom_policy, message, flags, reterr_error); |
| 602 |
|
| 603 |
if (streq(name, "RestartUSec")) |
| 604 |
return bus_set_transient_usec(u, name, &s->restart_usec, message, flags, reterr_error); |
| 605 |
|
| 606 |
if (streq(name, "RestartSteps")) |
| 607 |
return bus_set_transient_unsigned(u, name, &s->restart_steps, message, flags, reterr_error); |
| 608 |
|
| 609 |
if (streq(name, "RestartMaxDelayUSec")) |
| 610 |
return bus_set_transient_usec(u, name, &s->restart_max_delay_usec, message, flags, reterr_error); |
| 611 |
|
| 612 |
if (streq(name, "TimeoutStartUSec")) { |
| 613 |
r = bus_set_transient_usec(u, name, &s->timeout_start_usec, message, flags, reterr_error); |
| 614 |
if (r >= 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) |
| 615 |
s->start_timeout_defined = true; |
| 616 |
|
| 617 |
return r; |
| 618 |
} |
| 619 |
|
| 620 |
if (streq(name, "TimeoutStopUSec")) |
| 621 |
return bus_set_transient_usec(u, name, &s->timeout_stop_usec, message, flags, reterr_error); |
| 622 |
|
| 623 |
if (streq(name, "TimeoutAbortUSec")) { |
| 624 |
r = bus_set_transient_usec(u, name, &s->timeout_abort_usec, message, flags, reterr_error); |
| 625 |
if (r >= 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) |
| 626 |
s->timeout_abort_set = true; |
| 627 |
return r; |
| 628 |
} |
| 629 |
|
| 630 |
if (streq(name, "TimeoutStartFailureMode")) |
| 631 |
return bus_set_transient_timeout_failure_mode(u, name, &s->timeout_start_failure_mode, message, flags, reterr_error); |
| 632 |
|
| 633 |
if (streq(name, "TimeoutStopFailureMode")) |
| 634 |
return bus_set_transient_timeout_failure_mode(u, name, &s->timeout_stop_failure_mode, message, flags, reterr_error); |
| 635 |
|
| 636 |
if (streq(name, "RuntimeMaxUSec")) |
| 637 |
return bus_set_transient_usec(u, name, &s->runtime_max_usec, message, flags, reterr_error); |
| 638 |
|
| 639 |
if (streq(name, "RuntimeRandomizedExtraUSec")) |
| 640 |
return bus_set_transient_usec(u, name, &s->runtime_rand_extra_usec, message, flags, reterr_error); |
| 641 |
|
| 642 |
if (streq(name, "WatchdogUSec")) |
| 643 |
return bus_set_transient_usec(u, name, &s->watchdog_usec, message, flags, reterr_error); |
| 644 |
|
| 645 |
if (streq(name, "FileDescriptorStoreMax")) |
| 646 |
return bus_set_transient_unsigned(u, name, &s->n_fd_store_max, message, flags, reterr_error); |
| 647 |
|
| 648 |
if (streq(name, "FileDescriptorStorePreserve")) |
| 649 |
return bus_set_transient_exec_preserve_mode(u, name, &s->fd_store_preserve_mode, message, flags, reterr_error); |
| 650 |
|
| 651 |
if (streq(name, "NotifyAccess")) |
| 652 |
return bus_set_transient_notify_access(u, name, &s->notify_access, message, flags, reterr_error); |
| 653 |
|
| 654 |
if (streq(name, "PIDFile")) { |
| 655 |
_cleanup_free_ char *n = NULL; |
| 656 |
const char *v, *e; |
| 657 |
|
| 658 |
r = sd_bus_message_read(message, "s", &v); |
| 659 |
if (r < 0) |
| 660 |
return r; |
| 661 |
|
| 662 |
if (!isempty(v)) { |
| 663 |
n = path_make_absolute(v, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]); |
| 664 |
if (!n) |
| 665 |
return -ENOMEM; |
| 666 |
|
| 667 |
path_simplify(n); |
| 668 |
|
| 669 |
if (!path_is_normalized(n)) |
| 670 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "PIDFile= path '%s' is not valid", n); |
| 671 |
|
| 672 |
e = path_startswith(n, "/var/run/"); |
| 673 |
if (e) { |
| 674 |
char *z; |
| 675 |
|
| 676 |
z = path_join("/run", e); |
| 677 |
if (!z) |
| 678 |
return log_oom(); |
| 679 |
|
| 680 |
if (!UNIT_WRITE_FLAGS_NOOP(flags)) |
| 681 |
log_unit_notice(u, "Transient unit's PIDFile= property references path below legacy directory /var/run, updating %s %s %s; please update client accordingly.", |
| 682 |
n, glyph(GLYPH_ARROW_RIGHT), z); |
| 683 |
|
| 684 |
free_and_replace(n, z); |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 689 |
free_and_replace(s->pid_file, n); |
| 690 |
unit_write_settingf(u, flags, name, "%s=%s", name, strempty(s->pid_file)); |
| 691 |
} |
| 692 |
|
| 693 |
return 1; |
| 694 |
} |
| 695 |
|
| 696 |
if (streq(name, "USBFunctionDescriptors")) |
| 697 |
return bus_set_transient_path(u, name, &s->usb_function_descriptors, message, flags, reterr_error); |
| 698 |
|
| 699 |
if (streq(name, "USBFunctionStrings")) |
| 700 |
return bus_set_transient_path(u, name, &s->usb_function_strings, message, flags, reterr_error); |
| 701 |
|
| 702 |
if (streq(name, "BusName")) |
| 703 |
return bus_set_transient_bus_name(u, name, &s->bus_name, message, flags, reterr_error); |
| 704 |
|
| 705 |
if (streq(name, "Restart")) |
| 706 |
return bus_set_transient_service_restart(u, name, &s->restart, message, flags, reterr_error); |
| 707 |
|
| 708 |
if (streq(name, "RestartMode")) |
| 709 |
return bus_set_transient_service_restart_mode(u, name, &s->restart_mode, message, flags, reterr_error); |
| 710 |
|
| 711 |
if (streq(name, "RestartPreventExitStatus")) |
| 712 |
return bus_set_transient_exit_status(u, name, &s->restart_prevent_status, message, flags, reterr_error); |
| 713 |
|
| 714 |
if (streq(name, "RestartForceExitStatus")) |
| 715 |
return bus_set_transient_exit_status(u, name, &s->restart_force_status, message, flags, reterr_error); |
| 716 |
|
| 717 |
if (streq(name, "SuccessExitStatus")) |
| 718 |
return bus_set_transient_exit_status(u, name, &s->success_status, message, flags, reterr_error); |
| 719 |
|
| 720 |
ci = service_exec_command_from_string(name); |
| 721 |
if (ci < 0) |
| 722 |
ci = service_exec_ex_command_from_string(name); |
| 723 |
if (ci >= 0) |
| 724 |
return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, reterr_error); |
| 725 |
|
| 726 |
if (streq(name, "StandardInputFileDescriptor")) |
| 727 |
return bus_set_transient_exec_context_fd(u, name, &s->stdin_fd, &s->exec_context.stdio_as_fds, O_RDONLY, message, flags, reterr_error); |
| 728 |
|
| 729 |
if (streq(name, "StandardOutputFileDescriptor")) |
| 730 |
return bus_set_transient_exec_context_fd(u, name, &s->stdout_fd, &s->exec_context.stdio_as_fds, O_WRONLY, message, flags, reterr_error); |
| 731 |
|
| 732 |
if (streq(name, "StandardErrorFileDescriptor")) |
| 733 |
return bus_set_transient_exec_context_fd(u, name, &s->stderr_fd, &s->exec_context.stdio_as_fds, O_WRONLY, message, flags, reterr_error); |
| 734 |
|
| 735 |
if (streq(name, "OpenFile")) { |
| 736 |
const char *path, *fdname; |
| 737 |
uint64_t offlags; |
| 738 |
|
| 739 |
r = sd_bus_message_enter_container(message, 'a', "(sst)"); |
| 740 |
if (r < 0) |
| 741 |
return r; |
| 742 |
|
| 743 |
while ((r = sd_bus_message_read(message, "(sst)", &path, &fdname, &offlags)) > 0) { |
| 744 |
_cleanup_(open_file_freep) OpenFile *of = NULL; |
| 745 |
_cleanup_free_ char *ofs = NULL; |
| 746 |
|
| 747 |
of = new(OpenFile, 1); |
| 748 |
if (!of) |
| 749 |
return -ENOMEM; |
| 750 |
|
| 751 |
*of = (OpenFile) { |
| 752 |
.path = strdup(path), |
| 753 |
.fdname = strdup(fdname), |
| 754 |
.flags = offlags, |
| 755 |
}; |
| 756 |
|
| 757 |
if (!of->path || !of->fdname) |
| 758 |
return -ENOMEM; |
| 759 |
|
| 760 |
r = open_file_validate(of); |
| 761 |
if (r < 0) |
| 762 |
return r; |
| 763 |
|
| 764 |
if (UNIT_WRITE_FLAGS_NOOP(flags)) |
| 765 |
continue; |
| 766 |
|
| 767 |
r = open_file_to_string(of, &ofs); |
| 768 |
if (r < 0) |
| 769 |
return sd_bus_error_set_errnof( |
| 770 |
reterr_error, r, "Failed to convert OpenFile= value to string: %m"); |
| 771 |
|
| 772 |
LIST_APPEND(open_files, s->open_files, TAKE_PTR(of)); |
| 773 |
unit_write_settingf(u, flags | UNIT_ESCAPE_SPECIFIERS, name, "OpenFile=%s", ofs); |
| 774 |
} |
| 775 |
if (r < 0) |
| 776 |
return r; |
| 777 |
|
| 778 |
r = sd_bus_message_exit_container(message); |
| 779 |
if (r < 0) |
| 780 |
return r; |
| 781 |
|
| 782 |
return 1; |
| 783 |
} |
| 784 |
|
| 785 |
if (streq(name, "ReloadSignal")) |
| 786 |
return bus_set_transient_reload_signal(u, name, &s->reload_signal, message, flags, reterr_error); |
| 787 |
|
| 788 |
if (streq(name, "ExtraFileDescriptors")) { |
| 789 |
r = sd_bus_message_enter_container(message, 'a', "(hs)"); |
| 790 |
if (r < 0) |
| 791 |
return r; |
| 792 |
|
| 793 |
for (;;) { |
| 794 |
const char *fdname; |
| 795 |
int fd; |
| 796 |
|
| 797 |
r = sd_bus_message_read(message, "(hs)", &fd, &fdname); |
| 798 |
if (r < 0) |
| 799 |
return r; |
| 800 |
if (r == 0) |
| 801 |
break; |
| 802 |
|
| 803 |
/* Disallow empty string for ExtraFileDescriptors. |
| 804 |
* Unlike OpenFile, StandardInput and friends, there isn't a good sane |
| 805 |
* default for an arbitrary FD. */ |
| 806 |
if (isempty(fdname) || !fdname_is_valid(fdname)) |
| 807 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid extra fd name: %s", fdname); |
| 808 |
|
| 809 |
if (s->n_extra_fds >= NOTIFY_FD_MAX) |
| 810 |
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED, "Too many extra fds sent"); |
| 811 |
|
| 812 |
if (UNIT_WRITE_FLAGS_NOOP(flags)) |
| 813 |
continue; |
| 814 |
|
| 815 |
if (!GREEDY_REALLOC(s->extra_fds, s->n_extra_fds + 1)) |
| 816 |
return -ENOMEM; |
| 817 |
|
| 818 |
_cleanup_free_ char *fdname_dup = strdup(fdname); |
| 819 |
if (!fdname_dup) |
| 820 |
return -ENOMEM; |
| 821 |
|
| 822 |
_cleanup_close_ int fd_dup = fcntl(fd, F_DUPFD_CLOEXEC, 3); |
| 823 |
if (fd_dup < 0) |
| 824 |
return -errno; |
| 825 |
|
| 826 |
s->extra_fds[s->n_extra_fds++] = (ServiceExtraFD) { |
| 827 |
.fd = TAKE_FD(fd_dup), |
| 828 |
.fdname = TAKE_PTR(fdname_dup), |
| 829 |
}; |
| 830 |
} |
| 831 |
|
| 832 |
r = sd_bus_message_exit_container(message); |
| 833 |
if (r < 0) |
| 834 |
return r; |
| 835 |
|
| 836 |
return 1; |
| 837 |
} |
| 838 |
|
| 839 |
if (streq(name, "RootDirectoryFileDescriptor")) { |
| 840 |
int fd; |
| 841 |
|
| 842 |
r = sd_bus_message_read(message, "h", &fd); |
| 843 |
if (r < 0) |
| 844 |
return r; |
| 845 |
|
| 846 |
r = fd_verify_directory(fd); |
| 847 |
if (r < 0) |
| 848 |
return sd_bus_error_set_errnof(reterr_error, r, "RootDirectoryFileDescriptor= is not a directory: %m"); |
| 849 |
|
| 850 |
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 851 |
int fd_clone; |
| 852 |
|
| 853 |
/* Note that this invalidates the fd we got from the client. They won't be able to |
| 854 |
* move_mount() it themselves. If they already move_mount()'ed it themselves, this |
| 855 |
* will fail to clone the fd. */ |
| 856 |
fd_clone = mount_fd_clone(fd, /* recursive= */ true, /* replacement_fd= */ NULL); |
| 857 |
if (fd_clone < 0) |
| 858 |
return fd_clone; |
| 859 |
|
| 860 |
/* We're closing our own clone here, which shouldn't need an asynchronous_close(). */ |
| 861 |
close_and_replace(s->root_directory_fd, fd_clone); |
| 862 |
s->exec_context.root_directory_as_fd = true; |
| 863 |
} |
| 864 |
|
| 865 |
return 1; |
| 866 |
} |
| 867 |
|
| 868 |
if (streq(name, "RefreshOnReload")) { |
| 869 |
const char *t; |
| 870 |
int invert; |
| 871 |
|
| 872 |
r = sd_bus_message_enter_container(message, 'a', "(bs)"); |
| 873 |
if (r < 0) |
| 874 |
return r; |
| 875 |
|
| 876 |
while ((r = sd_bus_message_read(message, "(bs)", &invert, &t)) > 0) { |
| 877 |
ServiceRefreshOnReload f; |
| 878 |
|
| 879 |
f = service_refresh_on_reload_flag_from_string(t); |
| 880 |
if (f < 0) |
| 881 |
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid RefreshOnReload= value: %s", t); |
| 882 |
|
| 883 |
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 884 |
if (!s->refresh_on_reload_set) |
| 885 |
s->refresh_on_reload_flags = invert ? (SERVICE_REFRESH_ON_RELOAD_DEFAULT & ~f) : f; |
| 886 |
else |
| 887 |
SET_FLAG(s->refresh_on_reload_flags, f, !invert); |
| 888 |
|
| 889 |
s->refresh_on_reload_set = true; |
| 890 |
unit_write_settingf(u, flags, name, "%s=%s%s", name, invert ? "~" : "", t); |
| 891 |
} |
| 892 |
} |
| 893 |
if (r < 0) |
| 894 |
return r; |
| 895 |
|
| 896 |
r = sd_bus_message_exit_container(message); |
| 897 |
if (r < 0) |
| 898 |
return r; |
| 899 |
|
| 900 |
if (!UNIT_WRITE_FLAGS_NOOP(flags) && !s->refresh_on_reload_set) { /* empty array? */ |
| 901 |
s->refresh_on_reload_flags = 0; |
| 902 |
s->refresh_on_reload_set = true; |
| 903 |
unit_write_settingf(u, flags, name, "%s=no", name); |
| 904 |
} |
| 905 |
|
| 906 |
return 1; |
| 907 |
} |
| 908 |
|
| 909 |
return 0; |
| 910 |
} |
| 911 |
|
| 912 |
int bus_service_set_property( |
| 913 |
Unit *u, |
| 914 |
const char *name, |
| 915 |
sd_bus_message *message, |
| 916 |
UnitWriteFlags flags, |
| 917 |
sd_bus_error *reterr_error) { |
| 918 |
|
| 919 |
Service *s = SERVICE(u); |
| 920 |
int r; |
| 921 |
|
| 922 |
assert(s); |
| 923 |
assert(name); |
| 924 |
assert(message); |
| 925 |
|
| 926 |
r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, reterr_error); |
| 927 |
if (r != 0) |
| 928 |
return r; |
| 929 |
|
| 930 |
if (u->transient && u->load_state == UNIT_STUB) { |
| 931 |
/* This is a transient unit, let's allow a little more */ |
| 932 |
|
| 933 |
r = bus_service_set_transient_property(s, name, message, flags, reterr_error); |
| 934 |
if (r != 0) |
| 935 |
return r; |
| 936 |
|
| 937 |
r = bus_exec_context_set_transient_property(u, &s->exec_context, name, message, flags, reterr_error); |
| 938 |
if (r != 0) |
| 939 |
return r; |
| 940 |
|
| 941 |
r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, flags, reterr_error); |
| 942 |
if (r != 0) |
| 943 |
return r; |
| 944 |
} |
| 945 |
|
| 946 |
return 0; |
| 947 |
} |
| 948 |
|
| 949 |
int bus_service_commit_properties(Unit *u) { |
| 950 |
assert(u); |
| 951 |
|
| 952 |
(void) unit_realize_cgroup(u); |
| 953 |
|
| 954 |
return 0; |
| 955 |
} |