]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/path-lookup.c
Merge pull request #13439 from yuwata/core-support-systemctl-clean-more
[thirdparty/systemd.git] / src / shared / path-lookup.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include "alloc-util.h"
9 #include "fs-util.h"
10 #include "install.h"
11 #include "log.h"
12 #include "macro.h"
13 #include "mkdir.h"
14 #include "path-lookup.h"
15 #include "path-util.h"
16 #include "rm-rf.h"
17 #include "stat-util.h"
18 #include "string-util.h"
19 #include "strv.h"
20 #include "tmpfile-util.h"
21 #include "user-util.h"
22 #include "util.h"
23
24 int xdg_user_runtime_dir(char **ret, const char *suffix) {
25 const char *e;
26 char *j;
27
28 assert(ret);
29 assert(suffix);
30
31 e = getenv("XDG_RUNTIME_DIR");
32 if (!e)
33 return -ENXIO;
34
35 j = strjoin(e, suffix);
36 if (!j)
37 return -ENOMEM;
38
39 *ret = j;
40 return 0;
41 }
42
43 int xdg_user_config_dir(char **ret, const char *suffix) {
44 const char *e;
45 char *j;
46 int r;
47
48 assert(ret);
49
50 e = getenv("XDG_CONFIG_HOME");
51 if (e)
52 j = strjoin(e, suffix);
53 else {
54 _cleanup_free_ char *home = NULL;
55
56 r = get_home_dir(&home);
57 if (r < 0)
58 return r;
59
60 j = strjoin(home, "/.config", suffix);
61 }
62
63 if (!j)
64 return -ENOMEM;
65
66 *ret = j;
67 return 0;
68 }
69
70 int xdg_user_data_dir(char **ret, const char *suffix) {
71 const char *e;
72 char *j;
73 int r;
74
75 assert(ret);
76 assert(suffix);
77
78 /* We don't treat /etc/xdg/systemd here as the spec
79 * suggests because we assume that is a link to
80 * /etc/systemd/ anyway. */
81
82 e = getenv("XDG_DATA_HOME");
83 if (e)
84 j = strjoin(e, suffix);
85 else {
86 _cleanup_free_ char *home = NULL;
87
88 r = get_home_dir(&home);
89 if (r < 0)
90 return r;
91
92 j = strjoin(home, "/.local/share", suffix);
93 }
94 if (!j)
95 return -ENOMEM;
96
97 *ret = j;
98 return 1;
99 }
100
101 static const char* const user_data_unit_paths[] = {
102 "/usr/local/lib/systemd/user",
103 "/usr/local/share/systemd/user",
104 USER_DATA_UNIT_PATH,
105 "/usr/lib/systemd/user",
106 "/usr/share/systemd/user",
107 NULL
108 };
109
110 static const char* const user_config_unit_paths[] = {
111 USER_CONFIG_UNIT_PATH,
112 "/etc/systemd/user",
113 NULL
114 };
115
116 int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs) {
117 /* Implement the mechanisms defined in
118 *
119 * http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
120 *
121 * We look in both the config and the data dirs because we
122 * want to encourage that distributors ship their unit files
123 * as data, and allow overriding as configuration.
124 */
125 const char *e;
126 _cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL;
127
128 e = getenv("XDG_CONFIG_DIRS");
129 if (e) {
130 config_dirs = strv_split(e, ":");
131 if (!config_dirs)
132 return -ENOMEM;
133 }
134
135 e = getenv("XDG_DATA_DIRS");
136 if (e)
137 data_dirs = strv_split(e, ":");
138 else
139 data_dirs = strv_new("/usr/local/share",
140 "/usr/share");
141 if (!data_dirs)
142 return -ENOMEM;
143
144 *ret_config_dirs = TAKE_PTR(config_dirs);
145 *ret_data_dirs = TAKE_PTR(data_dirs);
146
147 return 0;
148 }
149
150 static char** user_dirs(
151 const char *persistent_config,
152 const char *runtime_config,
153 const char *global_persistent_config,
154 const char *global_runtime_config,
155 const char *generator,
156 const char *generator_early,
157 const char *generator_late,
158 const char *transient,
159 const char *persistent_control,
160 const char *runtime_control) {
161
162 _cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL;
163 _cleanup_free_ char *data_home = NULL;
164 _cleanup_strv_free_ char **res = NULL;
165 int r;
166
167 r = xdg_user_dirs(&config_dirs, &data_dirs);
168 if (r < 0)
169 return NULL;
170
171 r = xdg_user_data_dir(&data_home, "/systemd/user");
172 if (r < 0 && r != -ENXIO)
173 return NULL;
174
175 /* Now merge everything we found. */
176 if (strv_extend(&res, persistent_control) < 0)
177 return NULL;
178
179 if (strv_extend(&res, runtime_control) < 0)
180 return NULL;
181
182 if (strv_extend(&res, transient) < 0)
183 return NULL;
184
185 if (strv_extend(&res, generator_early) < 0)
186 return NULL;
187
188 if (strv_extend_strv_concat(&res, config_dirs, "/systemd/user") < 0)
189 return NULL;
190
191 if (strv_extend(&res, persistent_config) < 0)
192 return NULL;
193
194 /* global config has lower priority than the user config of the same type */
195 if (strv_extend(&res, global_persistent_config) < 0)
196 return NULL;
197
198 if (strv_extend_strv(&res, (char**) user_config_unit_paths, false) < 0)
199 return NULL;
200
201 if (strv_extend(&res, runtime_config) < 0)
202 return NULL;
203
204 if (strv_extend(&res, global_runtime_config) < 0)
205 return NULL;
206
207 if (strv_extend(&res, generator) < 0)
208 return NULL;
209
210 if (strv_extend(&res, data_home) < 0)
211 return NULL;
212
213 if (strv_extend_strv_concat(&res, data_dirs, "/systemd/user") < 0)
214 return NULL;
215
216 if (strv_extend_strv(&res, (char**) user_data_unit_paths, false) < 0)
217 return NULL;
218
219 if (strv_extend(&res, generator_late) < 0)
220 return NULL;
221
222 if (path_strv_make_absolute_cwd(res) < 0)
223 return NULL;
224
225 return TAKE_PTR(res);
226 }
227
228 bool path_is_user_data_dir(const char *path) {
229 assert(path);
230
231 return strv_contains((char**) user_data_unit_paths, path);
232 }
233
234 bool path_is_user_config_dir(const char *path) {
235 assert(path);
236
237 return strv_contains((char**) user_config_unit_paths, path);
238 }
239
240 static int acquire_generator_dirs(
241 UnitFileScope scope,
242 const char *tempdir,
243 char **generator,
244 char **generator_early,
245 char **generator_late) {
246
247 _cleanup_free_ char *x = NULL, *y = NULL, *z = NULL;
248 const char *prefix;
249
250 assert(generator);
251 assert(generator_early);
252 assert(generator_late);
253 assert(IN_SET(scope, UNIT_FILE_SYSTEM, UNIT_FILE_USER, UNIT_FILE_GLOBAL));
254
255 if (scope == UNIT_FILE_GLOBAL)
256 return -EOPNOTSUPP;
257
258 if (tempdir)
259 prefix = tempdir;
260 else if (scope == UNIT_FILE_SYSTEM)
261 prefix = "/run/systemd";
262 else {
263 /* UNIT_FILE_USER */
264 const char *e;
265
266 e = getenv("XDG_RUNTIME_DIR");
267 if (!e)
268 return -ENXIO;
269
270 prefix = strjoina(e, "/systemd");
271 }
272
273 x = path_join(prefix, "generator");
274 if (!x)
275 return -ENOMEM;
276
277 y = path_join(prefix, "generator.early");
278 if (!y)
279 return -ENOMEM;
280
281 z = path_join(prefix, "generator.late");
282 if (!z)
283 return -ENOMEM;
284
285 *generator = TAKE_PTR(x);
286 *generator_early = TAKE_PTR(y);
287 *generator_late = TAKE_PTR(z);
288
289 return 0;
290 }
291
292 static int acquire_transient_dir(
293 UnitFileScope scope,
294 const char *tempdir,
295 char **ret) {
296
297 char *transient;
298
299 assert(ret);
300 assert(IN_SET(scope, UNIT_FILE_SYSTEM, UNIT_FILE_USER, UNIT_FILE_GLOBAL));
301
302 if (scope == UNIT_FILE_GLOBAL)
303 return -EOPNOTSUPP;
304
305 if (tempdir)
306 transient = path_join(tempdir, "transient");
307 else if (scope == UNIT_FILE_SYSTEM)
308 transient = strdup("/run/systemd/transient");
309 else
310 return xdg_user_runtime_dir(ret, "/systemd/transient");
311
312 if (!transient)
313 return -ENOMEM;
314 *ret = transient;
315 return 0;
316 }
317
318 static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **runtime) {
319 _cleanup_free_ char *a = NULL, *b = NULL;
320 int r;
321
322 assert(persistent);
323 assert(runtime);
324
325 switch (scope) {
326
327 case UNIT_FILE_SYSTEM:
328 a = strdup(SYSTEM_CONFIG_UNIT_PATH);
329 b = strdup("/run/systemd/system");
330 break;
331
332 case UNIT_FILE_GLOBAL:
333 a = strdup(USER_CONFIG_UNIT_PATH);
334 b = strdup("/run/systemd/user");
335 break;
336
337 case UNIT_FILE_USER:
338 r = xdg_user_config_dir(&a, "/systemd/user");
339 if (r < 0 && r != -ENXIO)
340 return r;
341
342 r = xdg_user_runtime_dir(runtime, "/systemd/user");
343 if (r < 0) {
344 if (r != -ENXIO)
345 return r;
346
347 /* If XDG_RUNTIME_DIR is not set, don't consider that fatal, simply initialize the runtime
348 * directory to NULL */
349 *runtime = NULL;
350 }
351
352 *persistent = TAKE_PTR(a);
353
354 return 0;
355
356 default:
357 assert_not_reached("Hmm, unexpected scope value.");
358 }
359
360 if (!a || !b)
361 return -ENOMEM;
362
363 *persistent = TAKE_PTR(a);
364 *runtime = TAKE_PTR(b);
365
366 return 0;
367 }
368
369 static int acquire_control_dirs(UnitFileScope scope, char **persistent, char **runtime) {
370 _cleanup_free_ char *a = NULL;
371 int r;
372
373 assert(persistent);
374 assert(runtime);
375
376 switch (scope) {
377
378 case UNIT_FILE_SYSTEM: {
379 _cleanup_free_ char *b = NULL;
380
381 a = strdup("/etc/systemd/system.control");
382 if (!a)
383 return -ENOMEM;
384
385 b = strdup("/run/systemd/system.control");
386 if (!b)
387 return -ENOMEM;
388
389 *runtime = TAKE_PTR(b);
390
391 break;
392 }
393
394 case UNIT_FILE_USER:
395 r = xdg_user_config_dir(&a, "/systemd/user.control");
396 if (r < 0 && r != -ENXIO)
397 return r;
398
399 r = xdg_user_runtime_dir(runtime, "/systemd/user.control");
400 if (r < 0) {
401 if (r != -ENXIO)
402 return r;
403
404 /* If XDG_RUNTIME_DIR is not set, don't consider this fatal, simply initialize the directory to
405 * NULL */
406 *runtime = NULL;
407 }
408
409 break;
410
411 case UNIT_FILE_GLOBAL:
412 return -EOPNOTSUPP;
413
414 default:
415 assert_not_reached("Hmm, unexpected scope value.");
416 }
417
418 *persistent = TAKE_PTR(a);
419
420 return 0;
421 }
422
423 static int acquire_attached_dirs(
424 UnitFileScope scope,
425 char **ret_persistent,
426 char **ret_runtime) {
427
428 _cleanup_free_ char *a = NULL, *b = NULL;
429
430 assert(ret_persistent);
431 assert(ret_runtime);
432
433 /* Portable services are not available to regular users for now. */
434 if (scope != UNIT_FILE_SYSTEM)
435 return -EOPNOTSUPP;
436
437 a = strdup("/etc/systemd/system.attached");
438 if (!a)
439 return -ENOMEM;
440
441 b = strdup("/run/systemd/system.attached");
442 if (!b)
443 return -ENOMEM;
444
445 *ret_persistent = TAKE_PTR(a);
446 *ret_runtime = TAKE_PTR(b);
447
448 return 0;
449 }
450
451 static int patch_root_prefix(char **p, const char *root_dir) {
452 char *c;
453
454 assert(p);
455
456 if (!*p)
457 return 0;
458
459 c = path_join(root_dir, *p);
460 if (!c)
461 return -ENOMEM;
462
463 free_and_replace(*p, c);
464 return 0;
465 }
466
467 static int patch_root_prefix_strv(char **l, const char *root_dir) {
468 char **i;
469 int r;
470
471 if (!root_dir)
472 return 0;
473
474 STRV_FOREACH(i, l) {
475 r = patch_root_prefix(i, root_dir);
476 if (r < 0)
477 return r;
478 }
479
480 return 0;
481 }
482
483 int lookup_paths_init(
484 LookupPaths *p,
485 UnitFileScope scope,
486 LookupPathsFlags flags,
487 const char *root_dir) {
488
489 _cleanup_(rmdir_and_freep) char *tempdir = NULL;
490 _cleanup_free_ char
491 *root = NULL,
492 *persistent_config = NULL, *runtime_config = NULL,
493 *global_persistent_config = NULL, *global_runtime_config = NULL,
494 *generator = NULL, *generator_early = NULL, *generator_late = NULL,
495 *transient = NULL,
496 *persistent_control = NULL, *runtime_control = NULL,
497 *persistent_attached = NULL, *runtime_attached = NULL;
498 bool append = false; /* Add items from SYSTEMD_UNIT_PATH before normal directories */
499 _cleanup_strv_free_ char **paths = NULL;
500 const char *e;
501 int r;
502
503 assert(p);
504 assert(scope >= 0);
505 assert(scope < _UNIT_FILE_SCOPE_MAX);
506
507 #if HAVE_SPLIT_USR
508 flags |= LOOKUP_PATHS_SPLIT_USR;
509 #endif
510
511 if (!empty_or_root(root_dir)) {
512 if (scope == UNIT_FILE_USER)
513 return -EINVAL;
514
515 r = is_dir(root_dir, true);
516 if (r < 0)
517 return r;
518 if (r == 0)
519 return -ENOTDIR;
520
521 root = strdup(root_dir);
522 if (!root)
523 return -ENOMEM;
524 }
525
526 if (flags & LOOKUP_PATHS_TEMPORARY_GENERATED) {
527 r = mkdtemp_malloc("/tmp/systemd-temporary-XXXXXX", &tempdir);
528 if (r < 0)
529 return log_debug_errno(r, "Failed to create temporary directory: %m");
530 }
531
532 /* Note: when XDG_RUNTIME_DIR is not set this will not return -ENXIO, but simply set runtime_config to NULL */
533 r = acquire_config_dirs(scope, &persistent_config, &runtime_config);
534 if (r < 0)
535 return r;
536
537 if (scope == UNIT_FILE_USER) {
538 r = acquire_config_dirs(UNIT_FILE_GLOBAL, &global_persistent_config, &global_runtime_config);
539 if (r < 0)
540 return r;
541 }
542
543 if ((flags & LOOKUP_PATHS_EXCLUDE_GENERATED) == 0) {
544 /* Note: if XDG_RUNTIME_DIR is not set, this will fail completely with ENXIO */
545 r = acquire_generator_dirs(scope, tempdir,
546 &generator, &generator_early, &generator_late);
547 if (r < 0 && !IN_SET(r, -EOPNOTSUPP, -ENXIO))
548 return r;
549 }
550
551 /* Note: if XDG_RUNTIME_DIR is not set, this will fail completely with ENXIO */
552 r = acquire_transient_dir(scope, tempdir, &transient);
553 if (r < 0 && !IN_SET(r, -EOPNOTSUPP, -ENXIO))
554 return r;
555
556 /* Note: when XDG_RUNTIME_DIR is not set this will not return -ENXIO, but simply set runtime_control to NULL */
557 r = acquire_control_dirs(scope, &persistent_control, &runtime_control);
558 if (r < 0 && r != -EOPNOTSUPP)
559 return r;
560
561 r = acquire_attached_dirs(scope, &persistent_attached, &runtime_attached);
562 if (r < 0 && r != -EOPNOTSUPP)
563 return r;
564
565 /* First priority is whatever has been passed to us via env vars */
566 e = getenv("SYSTEMD_UNIT_PATH");
567 if (e) {
568 const char *k;
569
570 k = endswith(e, ":");
571 if (k) {
572 e = strndupa(e, k - e);
573 append = true;
574 }
575
576 /* FIXME: empty components in other places should be rejected. */
577
578 r = path_split_and_make_absolute(e, &paths);
579 if (r < 0)
580 return r;
581 }
582
583 if (!paths || append) {
584 /* Let's figure something out. */
585
586 _cleanup_strv_free_ char **add = NULL;
587
588 /* For the user units we include share/ in the search
589 * path in order to comply with the XDG basedir spec.
590 * For the system stuff we avoid such nonsense. OTOH
591 * we include /lib in the search path for the system
592 * stuff but avoid it for user stuff. */
593
594 switch (scope) {
595
596 case UNIT_FILE_SYSTEM:
597 add = strv_new(
598 /* If you modify this you also want to modify
599 * systemdsystemunitpath= in systemd.pc.in! */
600 STRV_IFNOTNULL(persistent_control),
601 STRV_IFNOTNULL(runtime_control),
602 STRV_IFNOTNULL(transient),
603 STRV_IFNOTNULL(generator_early),
604 persistent_config,
605 SYSTEM_CONFIG_UNIT_PATH,
606 "/etc/systemd/system",
607 STRV_IFNOTNULL(persistent_attached),
608 runtime_config,
609 "/run/systemd/system",
610 STRV_IFNOTNULL(runtime_attached),
611 STRV_IFNOTNULL(generator),
612 "/usr/local/lib/systemd/system",
613 SYSTEM_DATA_UNIT_PATH,
614 "/usr/lib/systemd/system",
615 STRV_IFNOTNULL(flags & LOOKUP_PATHS_SPLIT_USR ? "/lib/systemd/system" : NULL),
616 STRV_IFNOTNULL(generator_late));
617 break;
618
619 case UNIT_FILE_GLOBAL:
620 add = strv_new(
621 /* If you modify this you also want to modify
622 * systemduserunitpath= in systemd.pc.in, and
623 * the arrays in user_dirs() above! */
624 STRV_IFNOTNULL(persistent_control),
625 STRV_IFNOTNULL(runtime_control),
626 STRV_IFNOTNULL(transient),
627 STRV_IFNOTNULL(generator_early),
628 persistent_config,
629 USER_CONFIG_UNIT_PATH,
630 "/etc/systemd/user",
631 runtime_config,
632 "/run/systemd/user",
633 STRV_IFNOTNULL(generator),
634 "/usr/local/share/systemd/user",
635 "/usr/share/systemd/user",
636 "/usr/local/lib/systemd/user",
637 USER_DATA_UNIT_PATH,
638 "/usr/lib/systemd/user",
639 STRV_IFNOTNULL(generator_late));
640 break;
641
642 case UNIT_FILE_USER:
643 add = user_dirs(persistent_config, runtime_config,
644 global_persistent_config, global_runtime_config,
645 generator, generator_early, generator_late,
646 transient,
647 persistent_control, runtime_control);
648 break;
649
650 default:
651 assert_not_reached("Hmm, unexpected scope?");
652 }
653
654 if (!add)
655 return -ENOMEM;
656
657 if (paths) {
658 r = strv_extend_strv(&paths, add, true);
659 if (r < 0)
660 return r;
661 } else
662 /* Small optimization: if paths is NULL (and it usually is), we can simply assign 'add' to it,
663 * and don't have to copy anything */
664 paths = TAKE_PTR(add);
665 }
666
667 r = patch_root_prefix(&persistent_config, root);
668 if (r < 0)
669 return r;
670 r = patch_root_prefix(&runtime_config, root);
671 if (r < 0)
672 return r;
673
674 r = patch_root_prefix(&generator, root);
675 if (r < 0)
676 return r;
677 r = patch_root_prefix(&generator_early, root);
678 if (r < 0)
679 return r;
680 r = patch_root_prefix(&generator_late, root);
681 if (r < 0)
682 return r;
683
684 r = patch_root_prefix(&transient, root);
685 if (r < 0)
686 return r;
687
688 r = patch_root_prefix(&persistent_control, root);
689 if (r < 0)
690 return r;
691 r = patch_root_prefix(&runtime_control, root);
692 if (r < 0)
693 return r;
694
695 r = patch_root_prefix(&persistent_attached, root);
696 if (r < 0)
697 return r;
698 r = patch_root_prefix(&runtime_attached, root);
699 if (r < 0)
700 return r;
701
702 r = patch_root_prefix_strv(paths, root);
703 if (r < 0)
704 return -ENOMEM;
705
706 *p = (LookupPaths) {
707 .search_path = strv_uniq(TAKE_PTR(paths)),
708
709 .persistent_config = TAKE_PTR(persistent_config),
710 .runtime_config = TAKE_PTR(runtime_config),
711
712 .generator = TAKE_PTR(generator),
713 .generator_early = TAKE_PTR(generator_early),
714 .generator_late = TAKE_PTR(generator_late),
715
716 .transient = TAKE_PTR(transient),
717
718 .persistent_control = TAKE_PTR(persistent_control),
719 .runtime_control = TAKE_PTR(runtime_control),
720
721 .persistent_attached = TAKE_PTR(persistent_attached),
722 .runtime_attached = TAKE_PTR(runtime_attached),
723
724 .root_dir = TAKE_PTR(root),
725 .temporary_dir = TAKE_PTR(tempdir),
726 };
727
728 return 0;
729 }
730
731 void lookup_paths_free(LookupPaths *p) {
732 if (!p)
733 return;
734
735 p->search_path = strv_free(p->search_path);
736
737 p->persistent_config = mfree(p->persistent_config);
738 p->runtime_config = mfree(p->runtime_config);
739
740 p->persistent_attached = mfree(p->persistent_attached);
741 p->runtime_attached = mfree(p->runtime_attached);
742
743 p->generator = mfree(p->generator);
744 p->generator_early = mfree(p->generator_early);
745 p->generator_late = mfree(p->generator_late);
746
747 p->transient = mfree(p->transient);
748
749 p->persistent_control = mfree(p->persistent_control);
750 p->runtime_control = mfree(p->runtime_control);
751
752 p->root_dir = mfree(p->root_dir);
753 p->temporary_dir = mfree(p->temporary_dir);
754 }
755
756 void lookup_paths_log(LookupPaths *p) {
757 assert(p);
758
759 if (strv_isempty(p->search_path)) {
760 log_debug("Ignoring unit files.");
761 p->search_path = strv_free(p->search_path);
762 } else {
763 _cleanup_free_ char *t;
764
765 t = strv_join(p->search_path, "\n\t");
766 log_debug("Looking for unit files in (higher priority first):\n\t%s", strna(t));
767 }
768 }
769
770 int lookup_paths_mkdir_generator(LookupPaths *p) {
771 int r, q;
772
773 assert(p);
774
775 if (!p->generator || !p->generator_early || !p->generator_late)
776 return -EINVAL;
777
778 r = mkdir_p_label(p->generator, 0755);
779
780 q = mkdir_p_label(p->generator_early, 0755);
781 if (q < 0 && r >= 0)
782 r = q;
783
784 q = mkdir_p_label(p->generator_late, 0755);
785 if (q < 0 && r >= 0)
786 r = q;
787
788 return r;
789 }
790
791 void lookup_paths_trim_generator(LookupPaths *p) {
792 assert(p);
793
794 /* Trim empty dirs */
795
796 if (p->generator)
797 (void) rmdir(p->generator);
798 if (p->generator_early)
799 (void) rmdir(p->generator_early);
800 if (p->generator_late)
801 (void) rmdir(p->generator_late);
802 }
803
804 void lookup_paths_flush_generator(LookupPaths *p) {
805 assert(p);
806
807 /* Flush the generated unit files in full */
808
809 if (p->generator)
810 (void) rm_rf(p->generator, REMOVE_ROOT|REMOVE_PHYSICAL);
811 if (p->generator_early)
812 (void) rm_rf(p->generator_early, REMOVE_ROOT|REMOVE_PHYSICAL);
813 if (p->generator_late)
814 (void) rm_rf(p->generator_late, REMOVE_ROOT|REMOVE_PHYSICAL);
815
816 if (p->temporary_dir)
817 (void) rm_rf(p->temporary_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
818 }
819
820 char **generator_binary_paths(UnitFileScope scope) {
821
822 switch (scope) {
823
824 case UNIT_FILE_SYSTEM:
825 return strv_new("/run/systemd/system-generators",
826 "/etc/systemd/system-generators",
827 "/usr/local/lib/systemd/system-generators",
828 SYSTEM_GENERATOR_PATH);
829
830 case UNIT_FILE_GLOBAL:
831 case UNIT_FILE_USER:
832 return strv_new("/run/systemd/user-generators",
833 "/etc/systemd/user-generators",
834 "/usr/local/lib/systemd/user-generators",
835 USER_GENERATOR_PATH);
836
837 default:
838 assert_not_reached("Hmm, unexpected scope.");
839 }
840 }