| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-bus.h" |
| 4 |
|
| 5 |
#include "alloc-util.h" |
| 6 |
#include "bitfield.h" |
| 7 |
#include "cgroup.h" |
| 8 |
#include "condition.h" |
| 9 |
#include "dbus.h" |
| 10 |
#include "extract-word.h" |
| 11 |
#include "fileio.h" |
| 12 |
#include "format-util.h" |
| 13 |
#include "glyph-util.h" |
| 14 |
#include "parse-util.h" |
| 15 |
#include "serialize.h" |
| 16 |
#include "set.h" |
| 17 |
#include "string-util.h" |
| 18 |
#include "strv.h" |
| 19 |
#include "unit.h" |
| 20 |
#include "unit-serialize.h" |
| 21 |
#include "user-util.h" |
| 22 |
|
| 23 |
/* Make sure out values fit in the bitfield. */ |
| 24 |
assert_cc(_UNIT_MARKER_MAX <= sizeof(((Unit){}).markers) * 8); |
| 25 |
|
| 26 |
static int serialize_markers(FILE *f, unsigned markers) { |
| 27 |
assert(f); |
| 28 |
|
| 29 |
if (markers == 0) |
| 30 |
return 0; |
| 31 |
|
| 32 |
bool space = false; |
| 33 |
|
| 34 |
fputs("markers=", f); |
| 35 |
BIT_FOREACH(m, markers) |
| 36 |
fputs_with_separator(f, unit_marker_to_string(m), /* separator= */ NULL, &space); |
| 37 |
fputc('\n', f); |
| 38 |
return 0; |
| 39 |
} |
| 40 |
|
| 41 |
static int deserialize_markers(Unit *u, const char *value) { |
| 42 |
assert(u); |
| 43 |
assert(value); |
| 44 |
int r; |
| 45 |
|
| 46 |
for (const char *p = value;;) { |
| 47 |
_cleanup_free_ char *word = NULL; |
| 48 |
|
| 49 |
r = extract_first_word(&p, &word, NULL, 0); |
| 50 |
if (r <= 0) |
| 51 |
return r; |
| 52 |
|
| 53 |
UnitMarker m = unit_marker_from_string(word); |
| 54 |
if (m < 0) { |
| 55 |
log_unit_debug_errno(u, m, "Unknown unit marker \"%s\", ignoring.", word); |
| 56 |
continue; |
| 57 |
} |
| 58 |
|
| 59 |
u->markers |= 1u << m; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
int unit_serialize_state(Unit *u, FILE *f, FDSet *fds, bool switching_root) { |
| 64 |
int r; |
| 65 |
|
| 66 |
assert(u); |
| 67 |
assert(f); |
| 68 |
assert(fds); |
| 69 |
|
| 70 |
if (switching_root && UNIT_VTABLE(u)->exclude_from_switch_root_serialization) { |
| 71 |
/* In the new root, paths for mounts and automounts will be different, so it doesn't make |
| 72 |
* much sense to serialize things. API file systems will be moved to the new root, but we |
| 73 |
* don't have mount units for those. */ |
| 74 |
log_unit_debug(u, "not serializing before switch-root"); |
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
/* Start marker */ |
| 79 |
fputs(u->id, f); |
| 80 |
fputc('\n', f); |
| 81 |
|
| 82 |
assert(!!UNIT_VTABLE(u)->serialize == !!UNIT_VTABLE(u)->deserialize_item); |
| 83 |
|
| 84 |
if (UNIT_VTABLE(u)->serialize) { |
| 85 |
r = UNIT_VTABLE(u)->serialize(u, f, fds); |
| 86 |
if (r < 0) |
| 87 |
return r; |
| 88 |
} |
| 89 |
|
| 90 |
(void) serialize_dual_timestamp(f, "state-change-timestamp", &u->state_change_timestamp); |
| 91 |
|
| 92 |
(void) serialize_dual_timestamp(f, "inactive-exit-timestamp", &u->inactive_exit_timestamp); |
| 93 |
(void) serialize_dual_timestamp(f, "active-enter-timestamp", &u->active_enter_timestamp); |
| 94 |
(void) serialize_dual_timestamp(f, "active-exit-timestamp", &u->active_exit_timestamp); |
| 95 |
(void) serialize_dual_timestamp(f, "inactive-enter-timestamp", &u->inactive_enter_timestamp); |
| 96 |
|
| 97 |
(void) serialize_dual_timestamp(f, "condition-timestamp", &u->condition_timestamp); |
| 98 |
(void) serialize_dual_timestamp(f, "assert-timestamp", &u->assert_timestamp); |
| 99 |
|
| 100 |
(void) serialize_ratelimit(f, "start-ratelimit", &u->start_ratelimit); |
| 101 |
(void) serialize_ratelimit(f, "auto-start-stop-ratelimit", &u->auto_start_stop_ratelimit); |
| 102 |
|
| 103 |
if (dual_timestamp_is_set(&u->condition_timestamp)) |
| 104 |
(void) serialize_bool(f, "condition-result", u->condition_result); |
| 105 |
|
| 106 |
if (dual_timestamp_is_set(&u->assert_timestamp)) |
| 107 |
(void) serialize_bool(f, "assert-result", u->assert_result); |
| 108 |
|
| 109 |
(void) serialize_bool(f, "transient", u->transient); |
| 110 |
(void) serialize_bool(f, "in-audit", u->in_audit); |
| 111 |
|
| 112 |
(void) serialize_bool(f, "debug-invocation", u->debug_invocation); |
| 113 |
|
| 114 |
(void) serialize_bool(f, "exported-invocation-id", u->exported_invocation_id); |
| 115 |
(void) serialize_bool(f, "exported-log-level-max", u->exported_log_level_max); |
| 116 |
(void) serialize_bool(f, "exported-log-extra-fields", u->exported_log_extra_fields); |
| 117 |
(void) serialize_bool(f, "exported-log-rate-limit-interval", u->exported_log_ratelimit_interval); |
| 118 |
(void) serialize_bool(f, "exported-log-rate-limit-burst", u->exported_log_ratelimit_burst); |
| 119 |
|
| 120 |
(void) cgroup_runtime_serialize(u, f, fds); |
| 121 |
|
| 122 |
if (uid_is_valid(u->ref_uid)) |
| 123 |
(void) serialize_item_format(f, "ref-uid", UID_FMT, u->ref_uid); |
| 124 |
if (gid_is_valid(u->ref_gid)) |
| 125 |
(void) serialize_item_format(f, "ref-gid", GID_FMT, u->ref_gid); |
| 126 |
|
| 127 |
(void) serialize_id128(f, "invocation-id", u->invocation_id); |
| 128 |
|
| 129 |
(void) serialize_item(f, "freezer-state", freezer_state_to_string(u->freezer_state)); |
| 130 |
|
| 131 |
(void) serialize_markers(f, u->markers); |
| 132 |
|
| 133 |
bus_track_serialize(u->bus_track, f, "ref"); |
| 134 |
|
| 135 |
if (!switching_root) { |
| 136 |
if (u->job) { |
| 137 |
fputs("job\n", f); |
| 138 |
job_serialize(u->job, f); |
| 139 |
} |
| 140 |
|
| 141 |
if (u->nop_job) { |
| 142 |
fputs("job\n", f); |
| 143 |
job_serialize(u->nop_job, f); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
/* End marker */ |
| 148 |
fputc('\n', f); |
| 149 |
return 0; |
| 150 |
} |
| 151 |
|
| 152 |
static int unit_deserialize_job(Unit *u, FILE *f) { |
| 153 |
_cleanup_(job_freep) Job *j = NULL; |
| 154 |
int r; |
| 155 |
|
| 156 |
assert(u); |
| 157 |
assert(f); |
| 158 |
|
| 159 |
j = job_new_raw(u); |
| 160 |
if (!j) |
| 161 |
return log_oom(); |
| 162 |
|
| 163 |
r = job_deserialize(j, f); |
| 164 |
if (r < 0) |
| 165 |
return r; |
| 166 |
|
| 167 |
r = job_install_deserialized(j); |
| 168 |
if (r < 0) |
| 169 |
return r; |
| 170 |
|
| 171 |
TAKE_PTR(j); |
| 172 |
return 0; |
| 173 |
} |
| 174 |
|
| 175 |
#define MATCH_DESERIALIZE(key, l, v, parse_func, target) \ |
| 176 |
({ \ |
| 177 |
bool _deserialize_matched = streq(l, key); \ |
| 178 |
if (_deserialize_matched) { \ |
| 179 |
int _deserialize_r = parse_func(v); \ |
| 180 |
if (_deserialize_r < 0) \ |
| 181 |
log_unit_debug_errno(u, _deserialize_r, \ |
| 182 |
"Failed to parse \"%s=%s\", ignoring.", l, v); \ |
| 183 |
else \ |
| 184 |
target = _deserialize_r; \ |
| 185 |
}; \ |
| 186 |
_deserialize_matched; \ |
| 187 |
}) |
| 188 |
|
| 189 |
#define MATCH_DESERIALIZE_IMMEDIATE(key, l, v, parse_func, target) \ |
| 190 |
({ \ |
| 191 |
bool _deserialize_matched = streq(l, key); \ |
| 192 |
if (_deserialize_matched) { \ |
| 193 |
int _deserialize_r = parse_func(v, &target); \ |
| 194 |
if (_deserialize_r < 0) \ |
| 195 |
log_unit_debug_errno(u, _deserialize_r, \ |
| 196 |
"Failed to parse \"%s=%s\", ignoring", l, v); \ |
| 197 |
}; \ |
| 198 |
_deserialize_matched; \ |
| 199 |
}) |
| 200 |
|
| 201 |
int unit_deserialize_state(Unit *u, FILE *f, FDSet *fds) { |
| 202 |
int r; |
| 203 |
|
| 204 |
assert(u); |
| 205 |
assert(f); |
| 206 |
assert(fds); |
| 207 |
|
| 208 |
for (;;) { |
| 209 |
_cleanup_free_ char *l = NULL; |
| 210 |
size_t k; |
| 211 |
char *v; |
| 212 |
|
| 213 |
r = deserialize_read_line(f, &l); |
| 214 |
if (r < 0) |
| 215 |
return r; |
| 216 |
if (r == 0) /* eof or end marker */ |
| 217 |
break; |
| 218 |
|
| 219 |
k = strcspn(l, "="); |
| 220 |
|
| 221 |
if (l[k] == '=') { |
| 222 |
l[k] = 0; |
| 223 |
v = l+k+1; |
| 224 |
} else |
| 225 |
v = l+k; |
| 226 |
|
| 227 |
if (streq(l, "job")) { |
| 228 |
if (v[0] == '\0') { |
| 229 |
/* New-style serialized job */ |
| 230 |
r = unit_deserialize_job(u, f); |
| 231 |
if (r < 0) |
| 232 |
return r; |
| 233 |
} else /* Legacy for pre-44 */ |
| 234 |
log_unit_warning(u, "Update from too old systemd versions are unsupported, cannot deserialize job: %s", v); |
| 235 |
continue; |
| 236 |
} else if (streq(l, "state-change-timestamp")) { |
| 237 |
(void) deserialize_dual_timestamp(v, &u->state_change_timestamp); |
| 238 |
continue; |
| 239 |
} else if (streq(l, "inactive-exit-timestamp")) { |
| 240 |
(void) deserialize_dual_timestamp(v, &u->inactive_exit_timestamp); |
| 241 |
continue; |
| 242 |
} else if (streq(l, "active-enter-timestamp")) { |
| 243 |
(void) deserialize_dual_timestamp(v, &u->active_enter_timestamp); |
| 244 |
continue; |
| 245 |
} else if (streq(l, "active-exit-timestamp")) { |
| 246 |
(void) deserialize_dual_timestamp(v, &u->active_exit_timestamp); |
| 247 |
continue; |
| 248 |
} else if (streq(l, "inactive-enter-timestamp")) { |
| 249 |
(void) deserialize_dual_timestamp(v, &u->inactive_enter_timestamp); |
| 250 |
continue; |
| 251 |
} else if (streq(l, "condition-timestamp")) { |
| 252 |
(void) deserialize_dual_timestamp(v, &u->condition_timestamp); |
| 253 |
continue; |
| 254 |
} else if (streq(l, "assert-timestamp")) { |
| 255 |
(void) deserialize_dual_timestamp(v, &u->assert_timestamp); |
| 256 |
continue; |
| 257 |
|
| 258 |
} else if (streq(l, "start-ratelimit")) { |
| 259 |
deserialize_ratelimit(&u->start_ratelimit, l, v); |
| 260 |
continue; |
| 261 |
} else if (streq(l, "auto-start-stop-ratelimit")) { |
| 262 |
deserialize_ratelimit(&u->auto_start_stop_ratelimit, l, v); |
| 263 |
continue; |
| 264 |
|
| 265 |
} else if (MATCH_DESERIALIZE("condition-result", l, v, parse_boolean, u->condition_result)) |
| 266 |
continue; |
| 267 |
|
| 268 |
else if (MATCH_DESERIALIZE("assert-result", l, v, parse_boolean, u->assert_result)) |
| 269 |
continue; |
| 270 |
|
| 271 |
else if (MATCH_DESERIALIZE("transient", l, v, parse_boolean, u->transient)) |
| 272 |
continue; |
| 273 |
|
| 274 |
else if (MATCH_DESERIALIZE("in-audit", l, v, parse_boolean, u->in_audit)) |
| 275 |
continue; |
| 276 |
|
| 277 |
else if (MATCH_DESERIALIZE("debug-invocation", l, v, parse_boolean, u->debug_invocation)) |
| 278 |
continue; |
| 279 |
|
| 280 |
else if (MATCH_DESERIALIZE("exported-invocation-id", l, v, parse_boolean, u->exported_invocation_id)) |
| 281 |
continue; |
| 282 |
|
| 283 |
else if (MATCH_DESERIALIZE("exported-log-level-max", l, v, parse_boolean, u->exported_log_level_max)) |
| 284 |
continue; |
| 285 |
|
| 286 |
else if (MATCH_DESERIALIZE("exported-log-extra-fields", l, v, parse_boolean, u->exported_log_extra_fields)) |
| 287 |
continue; |
| 288 |
|
| 289 |
else if (MATCH_DESERIALIZE("exported-log-rate-limit-interval", l, v, parse_boolean, u->exported_log_ratelimit_interval)) |
| 290 |
continue; |
| 291 |
|
| 292 |
else if (MATCH_DESERIALIZE("exported-log-rate-limit-burst", l, v, parse_boolean, u->exported_log_ratelimit_burst)) |
| 293 |
continue; |
| 294 |
|
| 295 |
else if (streq(l, "ref-uid")) { |
| 296 |
uid_t uid; |
| 297 |
|
| 298 |
r = parse_uid(v, &uid); |
| 299 |
if (r < 0) |
| 300 |
log_unit_debug(u, "Failed to parse \"%s=%s\", ignoring.", l, v); |
| 301 |
else |
| 302 |
unit_ref_uid_gid(u, uid, GID_INVALID); |
| 303 |
continue; |
| 304 |
|
| 305 |
} else if (streq(l, "ref-gid")) { |
| 306 |
gid_t gid; |
| 307 |
|
| 308 |
r = parse_gid(v, &gid); |
| 309 |
if (r < 0) |
| 310 |
log_unit_debug(u, "Failed to parse \"%s=%s\", ignoring.", l, v); |
| 311 |
else |
| 312 |
unit_ref_uid_gid(u, UID_INVALID, gid); |
| 313 |
continue; |
| 314 |
|
| 315 |
} else if (streq(l, "ref")) { |
| 316 |
r = strv_extend(&u->deserialized_refs, v); |
| 317 |
if (r < 0) |
| 318 |
return log_oom(); |
| 319 |
continue; |
| 320 |
|
| 321 |
} else if (streq(l, "invocation-id")) { |
| 322 |
sd_id128_t id; |
| 323 |
|
| 324 |
r = sd_id128_from_string(v, &id); |
| 325 |
if (r < 0) |
| 326 |
log_unit_debug(u, "Failed to parse \"%s=%s\", ignoring.", l, v); |
| 327 |
else { |
| 328 |
r = unit_set_invocation_id(u, id); |
| 329 |
if (r < 0) |
| 330 |
log_unit_warning_errno(u, r, "Failed to set invocation ID for unit: %m"); |
| 331 |
} |
| 332 |
|
| 333 |
continue; |
| 334 |
|
| 335 |
} else if (MATCH_DESERIALIZE("freezer-state", l, v, freezer_state_from_string, u->freezer_state)) |
| 336 |
continue; |
| 337 |
|
| 338 |
else if (streq(l, "markers")) { |
| 339 |
r = deserialize_markers(u, v); |
| 340 |
if (r < 0) |
| 341 |
log_unit_debug_errno(u, r, "Failed to deserialize \"%s=%s\", ignoring: %m", l, v); |
| 342 |
continue; |
| 343 |
} |
| 344 |
|
| 345 |
r = exec_shared_runtime_deserialize_compat(u, l, v, fds); |
| 346 |
if (r < 0) { |
| 347 |
log_unit_warning(u, "Failed to deserialize runtime parameter '%s', ignoring.", l); |
| 348 |
continue; |
| 349 |
} else if (r > 0) |
| 350 |
/* Returns positive if key was handled by the call */ |
| 351 |
continue; |
| 352 |
|
| 353 |
r = cgroup_runtime_deserialize_one(u, l, v, fds); |
| 354 |
if (r < 0) { |
| 355 |
log_unit_warning(u, "Failed to deserialize cgroup runtime parameter '%s, ignoring.", l); |
| 356 |
continue; |
| 357 |
} else if (r > 0) |
| 358 |
continue; /* was handled */ |
| 359 |
|
| 360 |
if (UNIT_VTABLE(u)->deserialize_item) { |
| 361 |
r = UNIT_VTABLE(u)->deserialize_item(u, l, v, fds); |
| 362 |
if (r < 0) |
| 363 |
log_unit_warning(u, "Failed to deserialize unit parameter '%s', ignoring.", l); |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
/* Let's make sure that everything that is deserialized also gets any potential new cgroup settings |
| 368 |
* applied after we are done. For that we invalidate anything already realized, so that we can |
| 369 |
* realize it again. */ |
| 370 |
CGroupRuntime *crt = unit_get_cgroup_runtime(u); |
| 371 |
if (crt && crt->cgroup_path) { |
| 372 |
/* Since v258, CGroupRuntime.cgroup_path is coupled with cgroup realized state, which however |
| 373 |
* wasn't the case in prior versions with the realized state tracked in a discrete field. |
| 374 |
* Patch cgroup_realized == 0 back to no cgroup_path here hence. */ |
| 375 |
if (crt->deserialized_cgroup_realized == 0) |
| 376 |
unit_release_cgroup(u, /* drop_cgroup_runtime= */ false); |
| 377 |
else { |
| 378 |
unit_invalidate_cgroup(u, _CGROUP_MASK_ALL); |
| 379 |
unit_invalidate_cgroup_bpf_firewall(u); |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
return 0; |
| 384 |
} |
| 385 |
|
| 386 |
int unit_deserialize_state_skip(FILE *f) { |
| 387 |
int r; |
| 388 |
|
| 389 |
assert(f); |
| 390 |
|
| 391 |
/* Skip serialized data for this unit. We don't know what it is. */ |
| 392 |
|
| 393 |
for (;;) { |
| 394 |
_cleanup_free_ char *line = NULL; |
| 395 |
|
| 396 |
r = read_stripped_line(f, LONG_LINE_MAX, &line); |
| 397 |
if (r < 0) |
| 398 |
return log_error_errno(r, "Failed to read serialization line: %m"); |
| 399 |
if (r == 0) |
| 400 |
return 0; |
| 401 |
|
| 402 |
/* End marker */ |
| 403 |
if (isempty(line)) |
| 404 |
return 1; |
| 405 |
|
| 406 |
/* A unit's serialized state may embed one or more "job" subsections (for u->job and |
| 407 |
* u->nop_job), each itself terminated by an empty line. We must consume those nested |
| 408 |
* sections fully, otherwise we'd stop at the job's end marker and treat the rest of the |
| 409 |
* unit's fields as a new top-level entry. */ |
| 410 |
if (streq(line, "job")) |
| 411 |
for (;;) { |
| 412 |
_cleanup_free_ char *job_line = NULL; |
| 413 |
|
| 414 |
r = read_stripped_line(f, LONG_LINE_MAX, &job_line); |
| 415 |
if (r < 0) |
| 416 |
return log_error_errno(r, "Failed to read serialization line: %m"); |
| 417 |
if (r == 0) |
| 418 |
return 0; |
| 419 |
if (isempty(job_line)) |
| 420 |
break; |
| 421 |
} |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
static void print_unit_dependency_mask(FILE *f, const char *kind, UnitDependencyMask mask, bool *space) { |
| 426 |
const struct { |
| 427 |
UnitDependencyMask mask; |
| 428 |
const char *name; |
| 429 |
} table[] = { |
| 430 |
{ UNIT_DEPENDENCY_FILE, "file" }, |
| 431 |
{ UNIT_DEPENDENCY_IMPLICIT, "implicit" }, |
| 432 |
{ UNIT_DEPENDENCY_DEFAULT, "default" }, |
| 433 |
{ UNIT_DEPENDENCY_UDEV, "udev" }, |
| 434 |
{ UNIT_DEPENDENCY_PATH, "path" }, |
| 435 |
{ UNIT_DEPENDENCY_MOUNT_FILE, "mount-file" }, |
| 436 |
{ UNIT_DEPENDENCY_MOUNTINFO, "mountinfo" }, |
| 437 |
{ UNIT_DEPENDENCY_PROC_SWAP, "proc-swap" }, |
| 438 |
{ UNIT_DEPENDENCY_SLICE_PROPERTY, "slice-property" }, |
| 439 |
}; |
| 440 |
|
| 441 |
assert(f); |
| 442 |
assert(kind); |
| 443 |
assert(space); |
| 444 |
|
| 445 |
FOREACH_ELEMENT(i, table) { |
| 446 |
if (mask == 0) |
| 447 |
break; |
| 448 |
|
| 449 |
if (FLAGS_SET(mask, i->mask)) { |
| 450 |
if (*space) |
| 451 |
fputc(' ', f); |
| 452 |
else |
| 453 |
*space = true; |
| 454 |
|
| 455 |
fputs(kind, f); |
| 456 |
fputs("-", f); |
| 457 |
fputs(i->name, f); |
| 458 |
|
| 459 |
mask &= ~i->mask; |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
assert(mask == 0); |
| 464 |
} |
| 465 |
|
| 466 |
void unit_dump(Unit *u, FILE *f, const char *prefix) { |
| 467 |
char *t; |
| 468 |
const char *prefix2; |
| 469 |
Unit *following; |
| 470 |
_cleanup_set_free_ Set *following_set = NULL; |
| 471 |
CGroupMask m; |
| 472 |
int r; |
| 473 |
|
| 474 |
assert(u); |
| 475 |
assert(u->type >= 0); |
| 476 |
|
| 477 |
prefix = strempty(prefix); |
| 478 |
prefix2 = strjoina(prefix, "\t"); |
| 479 |
|
| 480 |
fprintf(f, |
| 481 |
"%s%s Unit %s:\n", |
| 482 |
prefix, glyph(GLYPH_ARROW_RIGHT), u->id); |
| 483 |
|
| 484 |
SET_FOREACH(t, u->aliases) |
| 485 |
fprintf(f, "%s\tAlias: %s\n", prefix, t); |
| 486 |
|
| 487 |
fprintf(f, |
| 488 |
"%s\tDescription: %s\n" |
| 489 |
"%s\tInstance: %s\n" |
| 490 |
"%s\tUnit Load State: %s\n" |
| 491 |
"%s\tUnit Active State: %s\n" |
| 492 |
"%s\tState Change Timestamp: %s\n" |
| 493 |
"%s\tInactive Exit Timestamp: %s\n" |
| 494 |
"%s\tActive Enter Timestamp: %s\n" |
| 495 |
"%s\tActive Exit Timestamp: %s\n" |
| 496 |
"%s\tInactive Enter Timestamp: %s\n" |
| 497 |
"%s\tMay GC: %s\n" |
| 498 |
"%s\tNeed Daemon Reload: %s\n" |
| 499 |
"%s\tTransient: %s\n" |
| 500 |
"%s\tPerpetual: %s\n" |
| 501 |
"%s\tGarbage Collection Mode: %s\n", |
| 502 |
prefix, unit_description(u), |
| 503 |
prefix, strna(u->instance), |
| 504 |
prefix, unit_load_state_to_string(u->load_state), |
| 505 |
prefix, unit_active_state_to_string(unit_active_state(u)), |
| 506 |
prefix, strna(FORMAT_TIMESTAMP(u->state_change_timestamp.realtime)), |
| 507 |
prefix, strna(FORMAT_TIMESTAMP(u->inactive_exit_timestamp.realtime)), |
| 508 |
prefix, strna(FORMAT_TIMESTAMP(u->active_enter_timestamp.realtime)), |
| 509 |
prefix, strna(FORMAT_TIMESTAMP(u->active_exit_timestamp.realtime)), |
| 510 |
prefix, strna(FORMAT_TIMESTAMP(u->inactive_enter_timestamp.realtime)), |
| 511 |
prefix, yes_no(unit_may_gc(u)), |
| 512 |
prefix, yes_no(unit_need_daemon_reload(u)), |
| 513 |
prefix, yes_no(u->transient), |
| 514 |
prefix, yes_no(u->perpetual), |
| 515 |
prefix, collect_mode_to_string(u->collect_mode)); |
| 516 |
|
| 517 |
if (u->markers != 0) { |
| 518 |
fprintf(f, "%s\tMarkers:", prefix); |
| 519 |
|
| 520 |
BIT_FOREACH(marker, u->markers) |
| 521 |
fprintf(f, " %s", unit_marker_to_string(marker)); |
| 522 |
fputs("\n", f); |
| 523 |
} |
| 524 |
|
| 525 |
if (UNIT_HAS_CGROUP_CONTEXT(u)) { |
| 526 |
CGroupRuntime *crt = unit_get_cgroup_runtime(u); |
| 527 |
|
| 528 |
fprintf(f, |
| 529 |
"%s\tSlice: %s\n" |
| 530 |
"%s\tCGroup: %s\n", |
| 531 |
prefix, strna(unit_slice_name(u)), |
| 532 |
prefix, strna(crt ? crt->cgroup_path : NULL)); |
| 533 |
|
| 534 |
if (crt && crt->cgroup_realized_mask != 0) { |
| 535 |
_cleanup_free_ char *s = NULL; |
| 536 |
(void) cg_mask_to_string(crt->cgroup_realized_mask, &s); |
| 537 |
fprintf(f, "%s\tCGroup realized mask: %s\n", prefix, strnull(s)); |
| 538 |
} |
| 539 |
|
| 540 |
if (crt && crt->cgroup_enabled_mask != 0) { |
| 541 |
_cleanup_free_ char *s = NULL; |
| 542 |
(void) cg_mask_to_string(crt->cgroup_enabled_mask, &s); |
| 543 |
fprintf(f, "%s\tCGroup enabled mask: %s\n", prefix, strnull(s)); |
| 544 |
} |
| 545 |
|
| 546 |
m = unit_get_own_mask(u); |
| 547 |
if (m != 0) { |
| 548 |
_cleanup_free_ char *s = NULL; |
| 549 |
(void) cg_mask_to_string(m, &s); |
| 550 |
fprintf(f, "%s\tCGroup own mask: %s\n", prefix, strnull(s)); |
| 551 |
} |
| 552 |
|
| 553 |
m = unit_get_members_mask(u); |
| 554 |
if (m != 0) { |
| 555 |
_cleanup_free_ char *s = NULL; |
| 556 |
(void) cg_mask_to_string(m, &s); |
| 557 |
fprintf(f, "%s\tCGroup members mask: %s\n", prefix, strnull(s)); |
| 558 |
} |
| 559 |
|
| 560 |
m = unit_get_delegate_mask(u); |
| 561 |
if (m != 0) { |
| 562 |
_cleanup_free_ char *s = NULL; |
| 563 |
(void) cg_mask_to_string(m, &s); |
| 564 |
fprintf(f, "%s\tCGroup delegate mask: %s\n", prefix, strnull(s)); |
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
if (!sd_id128_is_null(u->invocation_id)) |
| 569 |
fprintf(f, "%s\tInvocation ID: " SD_ID128_FORMAT_STR "\n", |
| 570 |
prefix, SD_ID128_FORMAT_VAL(u->invocation_id)); |
| 571 |
|
| 572 |
STRV_FOREACH(j, u->documentation) |
| 573 |
fprintf(f, "%s\tDocumentation: %s\n", prefix, *j); |
| 574 |
|
| 575 |
if (u->access_selinux_context) |
| 576 |
fprintf(f, "%s\tAccess SELinux Context: %s\n", prefix, u->access_selinux_context); |
| 577 |
|
| 578 |
following = unit_following(u); |
| 579 |
if (following) |
| 580 |
fprintf(f, "%s\tFollowing: %s\n", prefix, following->id); |
| 581 |
|
| 582 |
r = unit_following_set(u, &following_set); |
| 583 |
if (r >= 0) { |
| 584 |
Unit *other; |
| 585 |
|
| 586 |
SET_FOREACH(other, following_set) |
| 587 |
fprintf(f, "%s\tFollowing Set Member: %s\n", prefix, other->id); |
| 588 |
} |
| 589 |
|
| 590 |
if (u->fragment_path) |
| 591 |
fprintf(f, "%s\tFragment Path: %s\n", prefix, u->fragment_path); |
| 592 |
|
| 593 |
if (u->source_path) |
| 594 |
fprintf(f, "%s\tSource Path: %s\n", prefix, u->source_path); |
| 595 |
|
| 596 |
STRV_FOREACH(j, u->dropin_paths) |
| 597 |
fprintf(f, "%s\tDropIn Path: %s\n", prefix, *j); |
| 598 |
|
| 599 |
if (u->failure_action != EMERGENCY_ACTION_NONE) |
| 600 |
fprintf(f, "%s\tFailure Action: %s\n", prefix, emergency_action_to_string(u->failure_action)); |
| 601 |
if (u->failure_action_exit_status >= 0) |
| 602 |
fprintf(f, "%s\tFailure Action Exit Status: %i\n", prefix, u->failure_action_exit_status); |
| 603 |
if (u->success_action != EMERGENCY_ACTION_NONE) |
| 604 |
fprintf(f, "%s\tSuccess Action: %s\n", prefix, emergency_action_to_string(u->success_action)); |
| 605 |
if (u->success_action_exit_status >= 0) |
| 606 |
fprintf(f, "%s\tSuccess Action Exit Status: %i\n", prefix, u->success_action_exit_status); |
| 607 |
|
| 608 |
if (u->job_timeout != USEC_INFINITY) |
| 609 |
fprintf(f, "%s\tJob Timeout: %s\n", prefix, FORMAT_TIMESPAN(u->job_timeout, 0)); |
| 610 |
|
| 611 |
if (u->job_timeout_action != EMERGENCY_ACTION_NONE) |
| 612 |
fprintf(f, "%s\tJob Timeout Action: %s\n", prefix, emergency_action_to_string(u->job_timeout_action)); |
| 613 |
|
| 614 |
if (u->job_timeout_reboot_arg) |
| 615 |
fprintf(f, "%s\tJob Timeout Reboot Argument: %s\n", prefix, u->job_timeout_reboot_arg); |
| 616 |
|
| 617 |
condition_dump_list(u->conditions, f, prefix, condition_type_to_string); |
| 618 |
condition_dump_list(u->asserts, f, prefix, assert_type_to_string); |
| 619 |
|
| 620 |
if (dual_timestamp_is_set(&u->condition_timestamp)) |
| 621 |
fprintf(f, |
| 622 |
"%s\tCondition Timestamp: %s\n" |
| 623 |
"%s\tCondition Result: %s\n", |
| 624 |
prefix, strna(FORMAT_TIMESTAMP(u->condition_timestamp.realtime)), |
| 625 |
prefix, yes_no(u->condition_result)); |
| 626 |
|
| 627 |
if (dual_timestamp_is_set(&u->assert_timestamp)) |
| 628 |
fprintf(f, |
| 629 |
"%s\tAssert Timestamp: %s\n" |
| 630 |
"%s\tAssert Result: %s\n", |
| 631 |
prefix, strna(FORMAT_TIMESTAMP(u->assert_timestamp.realtime)), |
| 632 |
prefix, yes_no(u->assert_result)); |
| 633 |
|
| 634 |
for (UnitDependency d = 0; d < _UNIT_DEPENDENCY_MAX; d++) { |
| 635 |
UnitDependencyInfo di; |
| 636 |
Unit *other; |
| 637 |
|
| 638 |
HASHMAP_FOREACH_KEY(di.data, other, unit_get_dependencies(u, d)) { |
| 639 |
bool space = false; |
| 640 |
|
| 641 |
fprintf(f, "%s\t%s: %s (", prefix, unit_dependency_to_string(d), other->id); |
| 642 |
|
| 643 |
print_unit_dependency_mask(f, "origin", di.origin_mask, &space); |
| 644 |
print_unit_dependency_mask(f, "destination", di.destination_mask, &space); |
| 645 |
|
| 646 |
fputs(")\n", f); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
for (UnitMountDependencyType type = 0; type < _UNIT_MOUNT_DEPENDENCY_TYPE_MAX; type++) |
| 651 |
if (!hashmap_isempty(u->mounts_for[type])) { |
| 652 |
UnitDependencyInfo di; |
| 653 |
const char *path; |
| 654 |
|
| 655 |
HASHMAP_FOREACH_KEY(di.data, path, u->mounts_for[type]) { |
| 656 |
bool space = false; |
| 657 |
|
| 658 |
fprintf(f, |
| 659 |
"%s\t%s: %s (", |
| 660 |
prefix, |
| 661 |
unit_mount_dependency_type_to_string(type), |
| 662 |
path); |
| 663 |
|
| 664 |
print_unit_dependency_mask(f, "origin", di.origin_mask, &space); |
| 665 |
print_unit_dependency_mask(f, "destination", di.destination_mask, &space); |
| 666 |
|
| 667 |
fputs(")\n", f); |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
if (u->load_state == UNIT_LOADED) { |
| 672 |
|
| 673 |
fprintf(f, |
| 674 |
"%s\tStopWhenUnneeded: %s\n" |
| 675 |
"%s\tRefuseManualStart: %s\n" |
| 676 |
"%s\tRefuseManualStop: %s\n" |
| 677 |
"%s\tDefaultDependencies: %s\n" |
| 678 |
"%s\tSurviveFinalKillSignal: %s\n" |
| 679 |
"%s\tOnSuccessJobMode: %s\n" |
| 680 |
"%s\tOnFailureJobMode: %s\n" |
| 681 |
"%s\tIgnoreOnIsolate: %s\n", |
| 682 |
prefix, yes_no(u->stop_when_unneeded), |
| 683 |
prefix, yes_no(u->refuse_manual_start), |
| 684 |
prefix, yes_no(u->refuse_manual_stop), |
| 685 |
prefix, yes_no(u->default_dependencies), |
| 686 |
prefix, yes_no(u->survive_final_kill_signal), |
| 687 |
prefix, job_mode_to_string(u->on_success_job_mode), |
| 688 |
prefix, job_mode_to_string(u->on_failure_job_mode), |
| 689 |
prefix, yes_no(u->ignore_on_isolate)); |
| 690 |
|
| 691 |
if (UNIT_VTABLE(u)->dump) |
| 692 |
UNIT_VTABLE(u)->dump(u, f, prefix2); |
| 693 |
|
| 694 |
} else if (u->load_state == UNIT_MERGED) |
| 695 |
fprintf(f, |
| 696 |
"%s\tMerged into: %s\n", |
| 697 |
prefix, u->merged_into->id); |
| 698 |
else if (u->load_state == UNIT_ERROR) { |
| 699 |
errno = ABS(u->load_error); |
| 700 |
fprintf(f, "%s\tLoad Error Code: %m\n", prefix); |
| 701 |
} |
| 702 |
|
| 703 |
for (const char *n = sd_bus_track_first(u->bus_track); n; n = sd_bus_track_next(u->bus_track)) |
| 704 |
fprintf(f, "%s\tBus Ref: %s\n", prefix, n); |
| 705 |
|
| 706 |
if (u->job) |
| 707 |
job_dump(u->job, f, prefix2); |
| 708 |
|
| 709 |
if (u->nop_job) |
| 710 |
job_dump(u->nop_job, f, prefix2); |
| 711 |
} |