Bug Summary

File:build-scan/../src/tmpfiles/tmpfiles.c
Warning:line 2196, column 35
Potential leak of memory pointed to by 'i.argument'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name tmpfiles.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I systemd-tmpfiles.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/tmpfiles/tmpfiles.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <errno(*__errno_location ()).h>
4#include <fcntl.h>
5#include <fnmatch.h>
6#include <getopt.h>
7#include <glob.h>
8#include <limits.h>
9#include <linux1/fs.h>
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <sys/stat.h>
16#include <sys/xattr.h>
17#include <sysexits.h>
18#include <time.h>
19#include <unistd.h>
20
21#include "sd-path.h"
22
23#include "acl-util.h"
24#include "alloc-util.h"
25#include "btrfs-util.h"
26#include "capability-util.h"
27#include "chattr-util.h"
28#include "conf-files.h"
29#include "copy.h"
30#include "def.h"
31#include "dirent-util.h"
32#include "escape.h"
33#include "fd-util.h"
34#include "fileio.h"
35#include "format-util.h"
36#include "fs-util.h"
37#include "glob-util.h"
38#include "io-util.h"
39#include "label.h"
40#include "log.h"
41#include "macro.h"
42#include "missing.h"
43#include "mkdir.h"
44#include "mount-util.h"
45#include "pager.h"
46#include "parse-util.h"
47#include "path-lookup.h"
48#include "path-util.h"
49#include "rm-rf.h"
50#include "selinux-util.h"
51#include "set.h"
52#include "specifier.h"
53#include "stat-util.h"
54#include "stdio-util.h"
55#include "string-table.h"
56#include "string-util.h"
57#include "strv.h"
58#include "terminal-util.h"
59#include "umask-util.h"
60#include "user-util.h"
61#include "util.h"
62
63/* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
64 * them in the file system. This is intended to be used to create
65 * properly owned directories beneath /tmp, /var/tmp, /run, which are
66 * volatile and hence need to be recreated on bootup. */
67
68typedef enum ItemType {
69 /* These ones take file names */
70 CREATE_FILE = 'f',
71 TRUNCATE_FILE = 'F',
72 CREATE_DIRECTORY = 'd',
73 TRUNCATE_DIRECTORY = 'D',
74 CREATE_SUBVOLUME = 'v',
75 CREATE_SUBVOLUME_INHERIT_QUOTA = 'q',
76 CREATE_SUBVOLUME_NEW_QUOTA = 'Q',
77 CREATE_FIFO = 'p',
78 CREATE_SYMLINK = 'L',
79 CREATE_CHAR_DEVICE = 'c',
80 CREATE_BLOCK_DEVICE = 'b',
81 COPY_FILES = 'C',
82
83 /* These ones take globs */
84 WRITE_FILE = 'w',
85 EMPTY_DIRECTORY = 'e',
86 SET_XATTR = 't',
87 RECURSIVE_SET_XATTR = 'T',
88 SET_ACL = 'a',
89 RECURSIVE_SET_ACL = 'A',
90 SET_ATTRIBUTE = 'h',
91 RECURSIVE_SET_ATTRIBUTE = 'H',
92 IGNORE_PATH = 'x',
93 IGNORE_DIRECTORY_PATH = 'X',
94 REMOVE_PATH = 'r',
95 RECURSIVE_REMOVE_PATH = 'R',
96 RELABEL_PATH = 'z',
97 RECURSIVE_RELABEL_PATH = 'Z',
98 ADJUST_MODE = 'm', /* legacy, 'z' is identical to this */
99} ItemType;
100
101typedef struct Item {
102 ItemType type;
103
104 char *path;
105 char *argument;
106 char **xattrs;
107#if HAVE_ACL1
108 acl_t acl_access;
109 acl_t acl_default;
110#endif
111 uid_t uid;
112 gid_t gid;
113 mode_t mode;
114 usec_t age;
115
116 dev_t major_minor;
117 unsigned attribute_value;
118 unsigned attribute_mask;
119
120 bool_Bool uid_set:1;
121 bool_Bool gid_set:1;
122 bool_Bool mode_set:1;
123 bool_Bool age_set:1;
124 bool_Bool mask_perms:1;
125 bool_Bool attribute_set:1;
126
127 bool_Bool keep_first_level:1;
128
129 bool_Bool force:1;
130
131 bool_Bool done:1;
132} Item;
133
134typedef struct ItemArray {
135 Item *items;
136 size_t count;
137 size_t size;
138} ItemArray;
139
140typedef enum DirectoryType {
141 DIRECTORY_RUNTIME = 0,
142 DIRECTORY_STATE,
143 DIRECTORY_CACHE,
144 DIRECTORY_LOGS,
145 _DIRECTORY_TYPE_MAX,
146} DirectoryType;
147
148static bool_Bool arg_cat_config = false0;
149static bool_Bool arg_user = false0;
150static bool_Bool arg_create = false0;
151static bool_Bool arg_clean = false0;
152static bool_Bool arg_remove = false0;
153static bool_Bool arg_boot = false0;
154static bool_Bool arg_no_pager = false0;
155
156static char **arg_include_prefixes = NULL((void*)0);
157static char **arg_exclude_prefixes = NULL((void*)0);
158static char *arg_root = NULL((void*)0);
159static char *arg_replace = NULL((void*)0);
160
161#define MAX_DEPTH256 256
162
163static OrderedHashmap *items = NULL((void*)0), *globs = NULL((void*)0);
164static Set *unix_sockets = NULL((void*)0);
165
166static int specifier_machine_id_safe(char specifier, void *data, void *userdata, char **ret);
167static int specifier_directory(char specifier, void *data, void *userdata, char **ret);
168
169static const Specifier specifier_table[] = {
170 { 'm', specifier_machine_id_safe, NULL((void*)0) },
171 { 'b', specifier_boot_id, NULL((void*)0) },
172 { 'H', specifier_host_name, NULL((void*)0) },
173 { 'v', specifier_kernel_release, NULL((void*)0) },
174
175 { 'U', specifier_user_id, NULL((void*)0) },
176 { 'u', specifier_user_name, NULL((void*)0) },
177 { 'h', specifier_user_home, NULL((void*)0) },
178
179 { 't', specifier_directory, UINT_TO_PTR(DIRECTORY_RUNTIME)((void *) ((uintptr_t) (DIRECTORY_RUNTIME))) },
180 { 'S', specifier_directory, UINT_TO_PTR(DIRECTORY_STATE)((void *) ((uintptr_t) (DIRECTORY_STATE))) },
181 { 'C', specifier_directory, UINT_TO_PTR(DIRECTORY_CACHE)((void *) ((uintptr_t) (DIRECTORY_CACHE))) },
182 { 'L', specifier_directory, UINT_TO_PTR(DIRECTORY_LOGS)((void *) ((uintptr_t) (DIRECTORY_LOGS))) },
183 { 'T', specifier_tmp_dir, NULL((void*)0) },
184 { 'V', specifier_var_tmp_dir, NULL((void*)0) },
185 {}
186};
187
188static int specifier_machine_id_safe(char specifier, void *data, void *userdata, char **ret) {
189 int r;
190
191 /* If /etc/machine_id is missing or empty (e.g. in a chroot environment)
192 * return a recognizable error so that the caller can skip the rule
193 * gracefully. */
194
195 r = specifier_machine_id(specifier, data, userdata, ret);
196 if (IN_SET(r, -ENOENT, -ENOMEDIUM)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-2, -123})/sizeof(int)]; switch(r) { case
-2: case -123: _found = 1; break; default: break; } _found; }
)
)
197 return -ENXIO6;
198
199 return r;
200}
201
202static int specifier_directory(char specifier, void *data, void *userdata, char **ret) {
203 struct table_entry {
204 uint64_t type;
205 const char *suffix;
206 };
207
208 static const struct table_entry paths_system[] = {
209 [DIRECTORY_RUNTIME] = { SD_PATH_SYSTEM_RUNTIME },
210 [DIRECTORY_STATE] = { SD_PATH_SYSTEM_STATE_PRIVATE },
211 [DIRECTORY_CACHE] = { SD_PATH_SYSTEM_STATE_CACHE },
212 [DIRECTORY_LOGS] = { SD_PATH_SYSTEM_STATE_LOGS },
213 };
214
215 static const struct table_entry paths_user[] = {
216 [DIRECTORY_RUNTIME] = { SD_PATH_USER_RUNTIME },
217 [DIRECTORY_STATE] = { SD_PATH_USER_CONFIGURATION },
218 [DIRECTORY_CACHE] = { SD_PATH_USER_STATE_CACHE },
219 [DIRECTORY_LOGS] = { SD_PATH_USER_CONFIGURATION, "log" },
220 };
221
222 unsigned i;
223 const struct table_entry *paths;
224
225 assert_cc(ELEMENTSOF(paths_system) == ELEMENTSOF(paths_user))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_13 { char x[(__extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(paths_system), typeof(
&*(paths_system))), sizeof(paths_system)/sizeof((paths_system
)[0]), ((void)0))) == __extension__ (__builtin_choose_expr( !
__builtin_types_compatible_p(typeof(paths_user), typeof(&
*(paths_user))), sizeof(paths_user)/sizeof((paths_user)[0]), (
(void)0)))) ? 0 : -1]; }; GCC diagnostic pop
;
226 paths = arg_user ? paths_user : paths_system;
227
228 i = PTR_TO_UINT(data)((unsigned int) ((uintptr_t) (data)));
229 assert(i < ELEMENTSOF(paths_system))do { if ((__builtin_expect(!!(!(i < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(paths_system), typeof(
&*(paths_system))), sizeof(paths_system)/sizeof((paths_system
)[0]), ((void)0))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("i < ELEMENTSOF(paths_system)"), "../src/tmpfiles/tmpfiles.c"
, 229, __PRETTY_FUNCTION__); } while (0)
;
230
231 return sd_path_home(paths[i].type, paths[i].suffix, ret);
232}
233
234static int log_unresolvable_specifier(const char *filename, unsigned line) {
235 static bool_Bool notified = false0;
236
237 /* In system mode, this is called when /etc is not fully initialized (e.g.
238 * in a chroot environment) where some specifiers are unresolvable. In user
239 * mode, this is called when some variables are not defined. These cases are
240 * not considered as an error so log at LOG_NOTICE only for the first time
241 * and then downgrade this to LOG_DEBUG for the rest. */
242
243 log_full(notified ? LOG_DEBUG : LOG_NOTICE,({ int _level = (((notified ? 7 : 5))), _e = ((0)), _realm = (
LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((
_level) & 0x07)) ? log_internal_realm(((_realm) << 10
| (_level)), _e, "../src/tmpfiles/tmpfiles.c", 246, __func__
, "[%s:%u] Failed to resolve specifier: %s, skipping", filename
, line, arg_user ? "Required $XDG_... variable not defined" :
"uninitialized /etc detected") : -abs(_e); })
244 "[%s:%u] Failed to resolve specifier: %s, skipping",({ int _level = (((notified ? 7 : 5))), _e = ((0)), _realm = (
LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((
_level) & 0x07)) ? log_internal_realm(((_realm) << 10
| (_level)), _e, "../src/tmpfiles/tmpfiles.c", 246, __func__
, "[%s:%u] Failed to resolve specifier: %s, skipping", filename
, line, arg_user ? "Required $XDG_... variable not defined" :
"uninitialized /etc detected") : -abs(_e); })
245 filename, line,({ int _level = (((notified ? 7 : 5))), _e = ((0)), _realm = (
LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((
_level) & 0x07)) ? log_internal_realm(((_realm) << 10
| (_level)), _e, "../src/tmpfiles/tmpfiles.c", 246, __func__
, "[%s:%u] Failed to resolve specifier: %s, skipping", filename
, line, arg_user ? "Required $XDG_... variable not defined" :
"uninitialized /etc detected") : -abs(_e); })
246 arg_user ? "Required $XDG_... variable not defined" : "uninitialized /etc detected")({ int _level = (((notified ? 7 : 5))), _e = ((0)), _realm = (
LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((
_level) & 0x07)) ? log_internal_realm(((_realm) << 10
| (_level)), _e, "../src/tmpfiles/tmpfiles.c", 246, __func__
, "[%s:%u] Failed to resolve specifier: %s, skipping", filename
, line, arg_user ? "Required $XDG_... variable not defined" :
"uninitialized /etc detected") : -abs(_e); })
;
247
248 if (!notified)
249 log_notice("All rules containing unresolvable specifiers will be skipped.")({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 249, __func__, "All rules containing unresolvable specifiers will be skipped."
) : -abs(_e); })
;
250
251 notified = true1;
252 return 0;
253}
254
255static int user_config_paths(char*** ret) {
256 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **config_dirs = NULL((void*)0), **data_dirs = NULL((void*)0);
257 _cleanup_free___attribute__((cleanup(freep))) char *persistent_config = NULL((void*)0), *runtime_config = NULL((void*)0), *data_home = NULL((void*)0);
258 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **res = NULL((void*)0);
259 int r;
260
261 r = xdg_user_dirs(&config_dirs, &data_dirs);
262 if (r < 0)
263 return r;
264
265 r = xdg_user_config_dir(&persistent_config, "/user-tmpfiles.d");
266 if (r < 0 && r != -ENXIO6)
267 return r;
268
269 r = xdg_user_runtime_dir(&runtime_config, "/user-tmpfiles.d");
270 if (r < 0 && r != -ENXIO6)
271 return r;
272
273 r = xdg_user_data_dir(&data_home, "/user-tmpfiles.d");
274 if (r < 0 && r != -ENXIO6)
275 return r;
276
277 r = strv_extend_strv_concat(&res, config_dirs, "/user-tmpfiles.d");
278 if (r < 0)
279 return r;
280
281 r = strv_extend(&res, persistent_config);
282 if (r < 0)
283 return r;
284
285 r = strv_extend(&res, runtime_config);
286 if (r < 0)
287 return r;
288
289 r = strv_extend(&res, data_home);
290 if (r < 0)
291 return r;
292
293 r = strv_extend_strv_concat(&res, data_dirs, "/user-tmpfiles.d");
294 if (r < 0)
295 return r;
296
297 r = path_strv_make_absolute_cwd(res);
298 if (r < 0)
299 return r;
300
301 *ret = TAKE_PTR(res)({ typeof(res) _ptr_ = (res); (res) = ((void*)0); _ptr_; });
302 return 0;
303}
304
305static bool_Bool needs_glob(ItemType t) {
306 return IN_SET(t,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
307 WRITE_FILE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
308 IGNORE_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
309 IGNORE_DIRECTORY_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
310 REMOVE_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
311 RECURSIVE_REMOVE_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
312 EMPTY_DIRECTORY,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
313 ADJUST_MODE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
314 RELABEL_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
315 RECURSIVE_RELABEL_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
316 SET_XATTR,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
317 RECURSIVE_SET_XATTR,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
318 SET_ACL,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
319 RECURSIVE_SET_ACL,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
320 SET_ATTRIBUTE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
321 RECURSIVE_SET_ATTRIBUTE)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH, EMPTY_DIRECTORY, ADJUST_MODE
, RELABEL_PATH, RECURSIVE_RELABEL_PATH, SET_XATTR, RECURSIVE_SET_XATTR
, SET_ACL, RECURSIVE_SET_ACL, SET_ATTRIBUTE, RECURSIVE_SET_ATTRIBUTE
})/sizeof(int)]; switch(t) { case WRITE_FILE: case IGNORE_PATH
: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH: case RECURSIVE_REMOVE_PATH
: case EMPTY_DIRECTORY: case ADJUST_MODE: case RELABEL_PATH: case
RECURSIVE_RELABEL_PATH: case SET_XATTR: case RECURSIVE_SET_XATTR
: case SET_ACL: case RECURSIVE_SET_ACL: case SET_ATTRIBUTE: case
RECURSIVE_SET_ATTRIBUTE: _found = 1; break; default: break; }
_found; })
;
322}
323
324static bool_Bool takes_ownership(ItemType t) {
325 return IN_SET(t,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
326 CREATE_FILE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
327 TRUNCATE_FILE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
328 CREATE_DIRECTORY,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
329 EMPTY_DIRECTORY,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
330 TRUNCATE_DIRECTORY,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
331 CREATE_SUBVOLUME,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
332 CREATE_SUBVOLUME_INHERIT_QUOTA,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
333 CREATE_SUBVOLUME_NEW_QUOTA,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
334 CREATE_FIFO,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
335 CREATE_SYMLINK,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
336 CREATE_CHAR_DEVICE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
337 CREATE_BLOCK_DEVICE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
338 COPY_FILES,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
339 WRITE_FILE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
340 IGNORE_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
341 IGNORE_DIRECTORY_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
342 REMOVE_PATH,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
343 RECURSIVE_REMOVE_PATH)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_FILE, TRUNCATE_FILE, CREATE_DIRECTORY
, EMPTY_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_FIFO, CREATE_SYMLINK, CREATE_CHAR_DEVICE
, CREATE_BLOCK_DEVICE, COPY_FILES, WRITE_FILE, IGNORE_PATH, IGNORE_DIRECTORY_PATH
, REMOVE_PATH, RECURSIVE_REMOVE_PATH})/sizeof(int)]; switch(t
) { case CREATE_FILE: case TRUNCATE_FILE: case CREATE_DIRECTORY
: case EMPTY_DIRECTORY: case TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME
: case CREATE_SUBVOLUME_INHERIT_QUOTA: case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_FIFO: case CREATE_SYMLINK: case CREATE_CHAR_DEVICE
: case CREATE_BLOCK_DEVICE: case COPY_FILES: case WRITE_FILE:
case IGNORE_PATH: case IGNORE_DIRECTORY_PATH: case REMOVE_PATH
: case RECURSIVE_REMOVE_PATH: _found = 1; break; default: break
; } _found; })
;
344}
345
346static struct Item* find_glob(OrderedHashmap *h, const char *match) {
347 ItemArray *j;
348 Iterator i;
349
350 ORDERED_HASHMAP_FOREACH(j, h, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); ordered_hashmap_iterate((h), &(
i), (void**)&(j), ((void*)0)); )
{
351 unsigned n;
352
353 for (n = 0; n < j->count; n++) {
354 Item *item = j->items + n;
355
356 if (fnmatch(item->path, match, FNM_PATHNAME(1 << 0)|FNM_PERIOD(1 << 2)) == 0)
357 return item;
358 }
359 }
360
361 return NULL((void*)0);
362}
363
364static void load_unix_sockets(void) {
365 _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *f = NULL((void*)0);
366 int r;
367
368 if (unix_sockets)
369 return;
370
371 /* We maintain a cache of the sockets we found in /proc/net/unix to speed things up a little. */
372
373 unix_sockets = set_new(&path_hash_ops)internal_set_new(&path_hash_ops );
374 if (!unix_sockets) {
375 log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 375, __func__)
;
376 return;
377 }
378
379 f = fopen("/proc/net/unix", "re");
380 if (!f) {
381 log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_WARNING, errno,({ int _level = (((*__errno_location ()) == 2 ? 7 : 4)), _e =
(((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c"
, 382, __func__, "Failed to open /proc/net/unix, ignoring: %m"
) : -abs(_e); })
382 "Failed to open /proc/net/unix, ignoring: %m")({ int _level = (((*__errno_location ()) == 2 ? 7 : 4)), _e =
(((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c"
, 382, __func__, "Failed to open /proc/net/unix, ignoring: %m"
) : -abs(_e); })
;
383 goto fail;
384 }
385
386 /* Skip header */
387 r = read_line(f, LONG_LINE_MAX(1U*1024U*1024U), NULL((void*)0));
388 if (r < 0) {
389 log_warning_errno(r, "Failed to skip /proc/net/unix header line: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 389, __func__, "Failed to skip /proc/net/unix header line: %m"
) : -abs(_e); })
;
390 goto fail;
391 }
392 if (r == 0) {
393 log_warning("Premature end of file reading /proc/net/unix.")({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 393, __func__, "Premature end of file reading /proc/net/unix."
) : -abs(_e); })
;
394 goto fail;
395 }
396
397 for (;;) {
398 _cleanup_free___attribute__((cleanup(freep))) char *line = NULL((void*)0);
399 char *p, *s;
400
401 r = read_line(f, LONG_LINE_MAX(1U*1024U*1024U), &line);
402 if (r < 0) {
403 log_warning_errno(r, "Failed to read /proc/net/unix line, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 403, __func__, "Failed to read /proc/net/unix line, ignoring: %m"
) : -abs(_e); })
;
404 goto fail;
405 }
406 if (r == 0) /* EOF */
407 break;
408
409 p = strchr(line, ':');
410 if (!p)
411 continue;
412
413 if (strlen(p) < 37)
414 continue;
415
416 p += 37;
417 p += strspn(p, WHITESPACE" \t\n\r");
418 p += strcspn(p, WHITESPACE" \t\n\r"); /* skip one more word */
419 p += strspn(p, WHITESPACE" \t\n\r");
420
421 if (*p != '/')
422 continue;
423
424 s = strdup(p);
425 if (!s) {
426 log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 426, __func__)
;
427 goto fail;
428 }
429
430 path_simplify(s, false0);
431
432 r = set_consume(unix_sockets, s);
433 if (r < 0 && r != -EEXIST17) {
434 log_warning_errno(r, "Failed to add AF_UNIX socket to set, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 434, __func__, "Failed to add AF_UNIX socket to set, ignoring: %m"
) : -abs(_e); })
;
435 goto fail;
436 }
437 }
438
439 return;
440
441fail:
442 unix_sockets = set_free_free(unix_sockets);
443}
444
445static bool_Bool unix_socket_alive(const char *fn) {
446 assert(fn)do { if ((__builtin_expect(!!(!(fn)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fn"), "../src/tmpfiles/tmpfiles.c", 446
, __PRETTY_FUNCTION__); } while (0)
;
447
448 load_unix_sockets();
449
450 if (unix_sockets)
451 return !!set_get(unix_sockets, (char*) fn);
452
453 /* We don't know, so assume yes */
454 return true1;
455}
456
457static int dir_is_mount_point(DIR *d, const char *subdir) {
458
459 int mount_id_parent, mount_id;
460 int r_p, r;
461
462 r_p = name_to_handle_at_loop(dirfd(d), ".", NULL((void*)0), &mount_id_parent, 0);
463 if (r_p < 0)
464 r_p = -errno(*__errno_location ());
465
466 r = name_to_handle_at_loop(dirfd(d), subdir, NULL((void*)0), &mount_id, 0);
467 if (r < 0)
468 r = -errno(*__errno_location ());
469
470 /* got no handle; make no assumptions, return error */
471 if (r_p < 0 && r < 0)
472 return r_p;
473
474 /* got both handles; if they differ, it is a mount point */
475 if (r_p >= 0 && r >= 0)
476 return mount_id_parent != mount_id;
477
478 /* got only one handle; assume different mount points if one
479 * of both queries was not supported by the filesystem */
480 if (IN_SET(r_p, -ENOSYS, -EOPNOTSUPP)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-38, -95})/sizeof(int)]; switch(r_p) { case
-38: case -95: _found = 1; break; default: break; } _found; }
)
|| IN_SET(r, -ENOSYS, -EOPNOTSUPP)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-38, -95})/sizeof(int)]; switch(r) { case
-38: case -95: _found = 1; break; default: break; } _found; }
)
)
481 return true1;
482
483 /* return error */
484 if (r_p < 0)
485 return r_p;
486 return r;
487}
488
489static DIR* xopendirat_nomod(int dirfd, const char *path) {
490 DIR *dir;
491
492 dir = xopendirat(dirfd, path, O_NOFOLLOW0400000|O_NOATIME01000000);
493 if (dir)
494 return dir;
495
496 log_debug_errno(errno, "Cannot open %sdirectory \"%s\": %m", dirfd == AT_FDCWD ? "" : "sub", path)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 496, __func__
, "Cannot open %sdirectory \"%s\": %m", dirfd == -100 ? "" : "sub"
, path) : -abs(_e); })
;
497 if (errno(*__errno_location ()) != EPERM1)
498 return NULL((void*)0);
499
500 dir = xopendirat(dirfd, path, O_NOFOLLOW0400000);
501 if (!dir)
502 log_debug_errno(errno, "Cannot open %sdirectory \"%s\": %m", dirfd == AT_FDCWD ? "" : "sub", path)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 502, __func__
, "Cannot open %sdirectory \"%s\": %m", dirfd == -100 ? "" : "sub"
, path) : -abs(_e); })
;
503
504 return dir;
505}
506
507static DIR* opendir_nomod(const char *path) {
508 return xopendirat_nomod(AT_FDCWD-100, path);
509}
510
511static int dir_cleanup(
512 Item *i,
513 const char *p,
514 DIR *d,
515 const struct stat *ds,
516 usec_t cutoff,
517 dev_t rootdev,
518 bool_Bool mountpoint,
519 int maxdepth,
520 bool_Bool keep_this_level) {
521
522 struct dirent *dent;
523 struct timespec times[2];
524 bool_Bool deleted = false0;
525 int r = 0;
526
527 FOREACH_DIRENT_ALL(dent, d, break)for ((*__errno_location ()) = 0, dent = readdir(d);; (*__errno_location
()) = 0, dent = readdir(d)) if (!dent) { if ((*__errno_location
()) > 0) { break; } break; } else
{
528 struct stat s;
529 usec_t age;
530 _cleanup_free___attribute__((cleanup(freep))) char *sub_path = NULL((void*)0);
531
532 if (dot_or_dot_dot(dent->d_name))
533 continue;
534
535 if (fstatat(dirfd(d), dent->d_name, &s, AT_SYMLINK_NOFOLLOW0x100) < 0) {
536 if (errno(*__errno_location ()) == ENOENT2)
537 continue;
538
539 /* FUSE, NFS mounts, SELinux might return EACCES */
540 r = log_full_errno(errno == EACCES ? LOG_DEBUG : LOG_ERR, errno,({ int _level = (((*__errno_location ()) == 13 ? 7 : 3)), _e =
(((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c"
, 541, __func__, "stat(%s/%s) failed: %m", p, dent->d_name
) : -abs(_e); })
541 "stat(%s/%s) failed: %m", p, dent->d_name)({ int _level = (((*__errno_location ()) == 13 ? 7 : 3)), _e =
(((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c"
, 541, __func__, "stat(%s/%s) failed: %m", p, dent->d_name
) : -abs(_e); })
;
542 continue;
543 }
544
545 /* Stay on the same filesystem */
546 if (s.st_dev != rootdev) {
547 log_debug("Ignoring \"%s/%s\": different filesystem.", p, dent->d_name)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 547, __func__, "Ignoring \"%s/%s\": different filesystem."
, p, dent->d_name) : -abs(_e); })
;
548 continue;
549 }
550
551 /* Try to detect bind mounts of the same filesystem instance; they
552 * do not differ in device major/minors. This type of query is not
553 * supported on all kernels or filesystem types though. */
554 if (S_ISDIR(s.st_mode)((((s.st_mode)) & 0170000) == (0040000)) && dir_is_mount_point(d, dent->d_name) > 0) {
555 log_debug("Ignoring \"%s/%s\": different mount of the same filesystem.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 556, __func__, "Ignoring \"%s/%s\": different mount of the same filesystem."
, p, dent->d_name) : -abs(_e); })
556 p, dent->d_name)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 556, __func__, "Ignoring \"%s/%s\": different mount of the same filesystem."
, p, dent->d_name) : -abs(_e); })
;
557 continue;
558 }
559
560 sub_path = strjoin(p, "/", dent->d_name)strjoin_real((p), "/", dent->d_name, ((void*)0));
561 if (!sub_path) {
562 r = log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 562, __func__)
;
563 goto finish;
564 }
565
566 /* Is there an item configured for this path? */
567 if (ordered_hashmap_get(items, sub_path)) {
568 log_debug("Ignoring \"%s\": a separate entry exists.", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 568, __func__, "Ignoring \"%s\": a separate entry exists."
, sub_path) : -abs(_e); })
;
569 continue;
570 }
571
572 if (find_glob(globs, sub_path)) {
573 log_debug("Ignoring \"%s\": a separate glob exists.", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 573, __func__, "Ignoring \"%s\": a separate glob exists."
, sub_path) : -abs(_e); })
;
574 continue;
575 }
576
577 if (S_ISDIR(s.st_mode)((((s.st_mode)) & 0170000) == (0040000))) {
578
579 if (mountpoint &&
580 streq(dent->d_name, "lost+found")(strcmp((dent->d_name),("lost+found")) == 0) &&
581 s.st_uid == 0) {
582 log_debug("Ignoring \"%s\".", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 582, __func__, "Ignoring \"%s\"."
, sub_path) : -abs(_e); })
;
583 continue;
584 }
585
586 if (maxdepth <= 0)
587 log_warning("Reached max depth on \"%s\".", sub_path)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 587, __func__, "Reached max depth on \"%s\"."
, sub_path) : -abs(_e); })
;
588 else {
589 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *sub_dir;
590 int q;
591
592 sub_dir = xopendirat_nomod(dirfd(d), dent->d_name);
593 if (!sub_dir) {
594 if (errno(*__errno_location ()) != ENOENT2)
595 r = log_error_errno(errno, "opendir(%s) failed: %m", sub_path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 595, __func__
, "opendir(%s) failed: %m", sub_path) : -abs(_e); })
;
596
597 continue;
598 }
599
600 q = dir_cleanup(i, sub_path, sub_dir, &s, cutoff, rootdev, false0, maxdepth-1, false0);
601 if (q < 0)
602 r = q;
603 }
604
605 /* Note: if you are wondering why we don't
606 * support the sticky bit for excluding
607 * directories from cleaning like we do it for
608 * other file system objects: well, the sticky
609 * bit already has a meaning for directories,
610 * so we don't want to overload that. */
611
612 if (keep_this_level) {
613 log_debug("Keeping \"%s\".", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 613, __func__, "Keeping \"%s\"."
, sub_path) : -abs(_e); })
;
614 continue;
615 }
616
617 /* Ignore ctime, we change it when deleting */
618 age = timespec_load(&s.st_mtim);
619 if (age >= cutoff) {
620 char a[FORMAT_TIMESTAMP_MAX(3+1+10+1+8+1+6+1+6+1)];
621 /* Follows spelling in stat(1). */
622 log_debug("Directory \"%s\": modify time %s is too new.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 624, __func__, "Directory \"%s\": modify time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
623 sub_path,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 624, __func__, "Directory \"%s\": modify time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
624 format_timestamp_us(a, sizeof(a), age))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 624, __func__, "Directory \"%s\": modify time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
;
625 continue;
626 }
627
628 age = timespec_load(&s.st_atim);
629 if (age >= cutoff) {
630 char a[FORMAT_TIMESTAMP_MAX(3+1+10+1+8+1+6+1+6+1)];
631 log_debug("Directory \"%s\": access time %s is too new.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 633, __func__, "Directory \"%s\": access time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
632 sub_path,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 633, __func__, "Directory \"%s\": access time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
633 format_timestamp_us(a, sizeof(a), age))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 633, __func__, "Directory \"%s\": access time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
;
634 continue;
635 }
636
637 log_debug("Removing directory \"%s\".", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 637, __func__, "Removing directory \"%s\"."
, sub_path) : -abs(_e); })
;
638 if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR0x200) < 0)
639 if (!IN_SET(errno, ENOENT, ENOTEMPTY)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){2, 39})/sizeof(int)]; switch((*__errno_location
())) { case 2: case 39: _found = 1; break; default: break; }
_found; })
)
640 r = log_error_errno(errno, "rmdir(%s): %m", sub_path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 640, __func__
, "rmdir(%s): %m", sub_path) : -abs(_e); })
;
641
642 } else {
643 /* Skip files for which the sticky bit is
644 * set. These are semantics we define, and are
645 * unknown elsewhere. See XDG_RUNTIME_DIR
646 * specification for details. */
647 if (s.st_mode & S_ISVTX01000) {
648 log_debug("Skipping \"%s\": sticky bit set.", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 648, __func__, "Skipping \"%s\": sticky bit set."
, sub_path) : -abs(_e); })
;
649 continue;
650 }
651
652 if (mountpoint && S_ISREG(s.st_mode)((((s.st_mode)) & 0170000) == (0100000)))
653 if (s.st_uid == 0 && STR_IN_SET(dent->d_name,(!!strv_find((((char**) ((const char*[]) { ".journal", "aquota.user"
, "aquota.group", ((void*)0) }))), (dent->d_name)))
654 ".journal",(!!strv_find((((char**) ((const char*[]) { ".journal", "aquota.user"
, "aquota.group", ((void*)0) }))), (dent->d_name)))
655 "aquota.user",(!!strv_find((((char**) ((const char*[]) { ".journal", "aquota.user"
, "aquota.group", ((void*)0) }))), (dent->d_name)))
656 "aquota.group")(!!strv_find((((char**) ((const char*[]) { ".journal", "aquota.user"
, "aquota.group", ((void*)0) }))), (dent->d_name)))
) {
657 log_debug("Skipping \"%s\".", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 657, __func__, "Skipping \"%s\"."
, sub_path) : -abs(_e); })
;
658 continue;
659 }
660
661 /* Ignore sockets that are listed in /proc/net/unix */
662 if (S_ISSOCK(s.st_mode)((((s.st_mode)) & 0170000) == (0140000)) && unix_socket_alive(sub_path)) {
663 log_debug("Skipping \"%s\": live socket.", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 663, __func__, "Skipping \"%s\": live socket."
, sub_path) : -abs(_e); })
;
664 continue;
665 }
666
667 /* Ignore device nodes */
668 if (S_ISCHR(s.st_mode)((((s.st_mode)) & 0170000) == (0020000)) || S_ISBLK(s.st_mode)((((s.st_mode)) & 0170000) == (0060000))) {
669 log_debug("Skipping \"%s\": a device.", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 669, __func__, "Skipping \"%s\": a device."
, sub_path) : -abs(_e); })
;
670 continue;
671 }
672
673 /* Keep files on this level around if this is
674 * requested */
675 if (keep_this_level) {
676 log_debug("Keeping \"%s\".", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 676, __func__, "Keeping \"%s\"."
, sub_path) : -abs(_e); })
;
677 continue;
678 }
679
680 age = timespec_load(&s.st_mtim);
681 if (age >= cutoff) {
682 char a[FORMAT_TIMESTAMP_MAX(3+1+10+1+8+1+6+1+6+1)];
683 /* Follows spelling in stat(1). */
684 log_debug("File \"%s\": modify time %s is too new.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 686, __func__, "File \"%s\": modify time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
685 sub_path,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 686, __func__, "File \"%s\": modify time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
686 format_timestamp_us(a, sizeof(a), age))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 686, __func__, "File \"%s\": modify time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
;
687 continue;
688 }
689
690 age = timespec_load(&s.st_atim);
691 if (age >= cutoff) {
692 char a[FORMAT_TIMESTAMP_MAX(3+1+10+1+8+1+6+1+6+1)];
693 log_debug("File \"%s\": access time %s is too new.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 695, __func__, "File \"%s\": access time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
694 sub_path,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 695, __func__, "File \"%s\": access time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
695 format_timestamp_us(a, sizeof(a), age))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 695, __func__, "File \"%s\": access time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
;
696 continue;
697 }
698
699 age = timespec_load(&s.st_ctim);
700 if (age >= cutoff) {
701 char a[FORMAT_TIMESTAMP_MAX(3+1+10+1+8+1+6+1+6+1)];
702 log_debug("File \"%s\": change time %s is too new.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 704, __func__, "File \"%s\": change time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
703 sub_path,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 704, __func__, "File \"%s\": change time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
704 format_timestamp_us(a, sizeof(a), age))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 704, __func__, "File \"%s\": change time %s is too new."
, sub_path, format_timestamp_us(a, sizeof(a), age)) : -abs(_e
); })
;
705 continue;
706 }
707
708 log_debug("unlink \"%s\"", sub_path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 708, __func__, "unlink \"%s\""
, sub_path) : -abs(_e); })
;
709
710 if (unlinkat(dirfd(d), dent->d_name, 0) < 0)
711 if (errno(*__errno_location ()) != ENOENT2)
712 r = log_error_errno(errno, "unlink(%s): %m", sub_path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 712, __func__
, "unlink(%s): %m", sub_path) : -abs(_e); })
;
713
714 deleted = true1;
715 }
716 }
717
718finish:
719 if (deleted) {
720 usec_t age1, age2;
721 char a[FORMAT_TIMESTAMP_MAX(3+1+10+1+8+1+6+1+6+1)], b[FORMAT_TIMESTAMP_MAX(3+1+10+1+8+1+6+1+6+1)];
722
723 /* Restore original directory timestamps */
724 times[0] = ds->st_atim;
725 times[1] = ds->st_mtim;
726
727 age1 = timespec_load(&ds->st_atim);
728 age2 = timespec_load(&ds->st_mtim);
729 log_debug("Restoring access and modification time on \"%s\": %s, %s",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 732, __func__, "Restoring access and modification time on \"%s\": %s, %s"
, p, format_timestamp_us(a, sizeof(a), age1), format_timestamp_us
(b, sizeof(b), age2)) : -abs(_e); })
730 p,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 732, __func__, "Restoring access and modification time on \"%s\": %s, %s"
, p, format_timestamp_us(a, sizeof(a), age1), format_timestamp_us
(b, sizeof(b), age2)) : -abs(_e); })
731 format_timestamp_us(a, sizeof(a), age1),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 732, __func__, "Restoring access and modification time on \"%s\": %s, %s"
, p, format_timestamp_us(a, sizeof(a), age1), format_timestamp_us
(b, sizeof(b), age2)) : -abs(_e); })
732 format_timestamp_us(b, sizeof(b), age2))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 732, __func__, "Restoring access and modification time on \"%s\": %s, %s"
, p, format_timestamp_us(a, sizeof(a), age1), format_timestamp_us
(b, sizeof(b), age2)) : -abs(_e); })
;
733 if (futimens(dirfd(d), times) < 0)
734 log_error_errno(errno, "utimensat(%s): %m", p)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 734, __func__
, "utimensat(%s): %m", p) : -abs(_e); })
;
735 }
736
737 return r;
738}
739
740static bool_Bool dangerous_hardlinks(void) {
741 _cleanup_free___attribute__((cleanup(freep))) char *value = NULL((void*)0);
742 static int cached = -1;
743 int r;
744
745 /* Check whether the fs.protected_hardlinks sysctl is on. If we can't determine it we assume its off, as that's
746 * what the upstream default is. */
747
748 if (cached >= 0)
749 return cached;
750
751 r = read_one_line_file("/proc/sys/fs/protected_hardlinks", &value);
752 if (r < 0) {
753 log_debug_errno(r, "Failed to read fs.protected_hardlinks sysctl: %m")({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 753, __func__, "Failed to read fs.protected_hardlinks sysctl: %m"
) : -abs(_e); })
;
754 return true1;
755 }
756
757 r = parse_boolean(value);
758 if (r < 0) {
759 log_debug_errno(r, "Failed to parse fs.protected_hardlinks sysctl: %m")({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 759, __func__, "Failed to parse fs.protected_hardlinks sysctl: %m"
) : -abs(_e); })
;
760 return true1;
761 }
762
763 cached = r == 0;
764 return cached;
765}
766
767static bool_Bool hardlink_vulnerable(const struct stat *st) {
768 assert(st)do { if ((__builtin_expect(!!(!(st)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("st"), "../src/tmpfiles/tmpfiles.c", 768
, __PRETTY_FUNCTION__); } while (0)
;
769
770 return !S_ISDIR(st->st_mode)((((st->st_mode)) & 0170000) == (0040000)) && st->st_nlink > 1 && dangerous_hardlinks();
771}
772
773static int fd_set_perms(Item *i, int fd, const struct stat *st) {
774 _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0);
775 int r;
776
777 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 777,
__PRETTY_FUNCTION__); } while (0)
;
778 assert(fd)do { if ((__builtin_expect(!!(!(fd)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fd"), "../src/tmpfiles/tmpfiles.c", 778
, __PRETTY_FUNCTION__); } while (0)
;
779
780 r = fd_get_path(fd, &path);
781 if (r < 0)
782 return r;
783
784 if (!i->mode_set && !i->uid_set && !i->gid_set)
785 goto shortcut;
786
787 if (hardlink_vulnerable(st)) {
788 log_error("Refusing to set permissions on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 788, __func__, "Refusing to set permissions on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off."
, path) : -abs(_e); })
;
789 return -EPERM1;
790 }
791
792 if (i->mode_set) {
793 if (S_ISLNK(st->st_mode)((((st->st_mode)) & 0170000) == (0120000)))
794 log_debug("Skipping mode fix for symlink %s.", path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 794, __func__, "Skipping mode fix for symlink %s."
, path) : -abs(_e); })
;
795 else {
796 mode_t m = i->mode;
797
798 if (i->mask_perms) {
799 if (!(st->st_mode & 0111))
800 m &= ~0111;
801 if (!(st->st_mode & 0222))
802 m &= ~0222;
803 if (!(st->st_mode & 0444))
804 m &= ~0444;
805 if (!S_ISDIR(st->st_mode)((((st->st_mode)) & 0170000) == (0040000)))
806 m &= ~07000; /* remove sticky/sgid/suid bit, unless directory */
807 }
808
809 if (m == (st->st_mode & 07777))
810 log_debug("\"%s\" has correct mode %o already.", path, st->st_mode)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 810, __func__, "\"%s\" has correct mode %o already."
, path, st->st_mode) : -abs(_e); })
;
811 else {
812 log_debug("Changing \"%s\" to mode %o.", path, m)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 812, __func__, "Changing \"%s\" to mode %o."
, path, m) : -abs(_e); })
;
813 if (fchmod_opath(fd, m) < 0)
814 return log_error_errno(errno, "fchmod() of %s failed: %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 814, __func__
, "fchmod() of %s failed: %m", path) : -abs(_e); })
;
815 }
816 }
817 }
818
819 if ((i->uid_set && i->uid != st->st_uid) ||
820 (i->gid_set && i->gid != st->st_gid)) {
821 log_debug("Changing \"%s\" to owner "UID_FMT":"GID_FMT,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 824, __func__, "Changing \"%s\" to owner "
"%" "u"":""%" "u", path, i->uid_set ? i->uid : ((uid_t)
-1), i->gid_set ? i->gid : ((gid_t) -1)) : -abs(_e); }
)
822 path,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 824, __func__, "Changing \"%s\" to owner "
"%" "u"":""%" "u", path, i->uid_set ? i->uid : ((uid_t)
-1), i->gid_set ? i->gid : ((gid_t) -1)) : -abs(_e); }
)
823 i->uid_set ? i->uid : UID_INVALID,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 824, __func__, "Changing \"%s\" to owner "
"%" "u"":""%" "u", path, i->uid_set ? i->uid : ((uid_t)
-1), i->gid_set ? i->gid : ((gid_t) -1)) : -abs(_e); }
)
824 i->gid_set ? i->gid : GID_INVALID)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 824, __func__, "Changing \"%s\" to owner "
"%" "u"":""%" "u", path, i->uid_set ? i->uid : ((uid_t)
-1), i->gid_set ? i->gid : ((gid_t) -1)) : -abs(_e); }
)
;
825
826 if (fchownat(fd,
827 "",
828 i->uid_set ? i->uid : UID_INVALID((uid_t) -1),
829 i->gid_set ? i->gid : GID_INVALID((gid_t) -1),
830 AT_EMPTY_PATH0x1000) < 0)
831 return log_error_errno(errno, "fchownat() of %s failed: %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 831, __func__
, "fchownat() of %s failed: %m", path) : -abs(_e); })
;
832 }
833
834shortcut:
835 return label_fix(path, 0);
836}
837
838static int path_set_perms(Item *i, const char *path) {
839 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
840 struct stat st;
841
842 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 842,
__PRETTY_FUNCTION__); } while (0)
;
843 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/tmpfiles/tmpfiles.c", 843
, __PRETTY_FUNCTION__); } while (0)
;
844
845 fd = open(path, O_NOFOLLOW0400000|O_CLOEXEC02000000|O_PATH010000000);
846 if (fd < 0) {
847 int level = LOG_ERR3, r = -errno(*__errno_location ());
848
849 /* Option "e" operates only on existing objects. Do not
850 * print errors about non-existent files or directories */
851 if (i->type == EMPTY_DIRECTORY && errno(*__errno_location ()) == ENOENT2) {
852 level = LOG_DEBUG7;
853 r = 0;
854 }
855
856 log_full_errno(level, errno, "Adjusting owner and mode for %s failed: %m", path)({ int _level = ((level)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 856, __func__
, "Adjusting owner and mode for %s failed: %m", path) : -abs(
_e); })
;
857 return r;
858 }
859
860 if (fstat(fd, &st) < 0)
861 return log_error_errno(errno, "Failed to fstat() file %s: %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 861, __func__
, "Failed to fstat() file %s: %m", path) : -abs(_e); })
;
862
863 if (i->type == EMPTY_DIRECTORY && !S_ISDIR(st.st_mode)((((st.st_mode)) & 0170000) == (0040000)))
864 return log_error_errno(EEXIST, "'%s' already exists and is not a directory. ", path)({ int _level = ((3)), _e = ((17)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 864, __func__, "'%s' already exists and is not a directory. "
, path) : -abs(_e); })
;
865
866 return fd_set_perms(i, fd, &st);
867}
868
869static int parse_xattrs_from_arg(Item *i) {
870 const char *p;
871 int r;
872
873 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 873,
__PRETTY_FUNCTION__); } while (0)
;
874 assert(i->argument)do { if ((__builtin_expect(!!(!(i->argument)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i->argument"), "../src/tmpfiles/tmpfiles.c"
, 874, __PRETTY_FUNCTION__); } while (0)
;
875
876 p = i->argument;
877
878 for (;;) {
879 _cleanup_free___attribute__((cleanup(freep))) char *name = NULL((void*)0), *value = NULL((void*)0), *xattr = NULL((void*)0);
880
881 r = extract_first_word(&p, &xattr, NULL((void*)0), EXTRACT_QUOTES|EXTRACT_CUNESCAPE);
882 if (r < 0)
883 log_warning_errno(r, "Failed to parse extended attribute '%s', ignoring: %m", p)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 883, __func__, "Failed to parse extended attribute '%s', ignoring: %m"
, p) : -abs(_e); })
;
884 if (r <= 0)
885 break;
886
887 r = split_pair(xattr, "=", &name, &value);
888 if (r < 0) {
889 log_warning_errno(r, "Failed to parse extended attribute, ignoring: %s", xattr)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 889, __func__, "Failed to parse extended attribute, ignoring: %s"
, xattr) : -abs(_e); })
;
890 continue;
891 }
892
893 if (isempty(name) || isempty(value)) {
894 log_warning("Malformed extended attribute found, ignoring: %s", xattr)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 894, __func__, "Malformed extended attribute found, ignoring: %s"
, xattr) : -abs(_e); })
;
895 continue;
896 }
897
898 if (strv_push_pair(&i->xattrs, name, value) < 0)
899 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 899, __func__)
;
900
901 name = value = NULL((void*)0);
902 }
903
904 return 0;
905}
906
907static int fd_set_xattrs(Item *i, int fd, const struct stat *st) {
908 char procfs_path[STRLEN("/proc/self/fd/")(sizeof("""/proc/self/fd/""") - 1) + DECIMAL_STR_MAX(int)(2+(sizeof(int) <= 1 ? 3 : sizeof(int) <= 2 ? 5 : sizeof
(int) <= 4 ? 10 : sizeof(int) <= 8 ? 20 : sizeof(int[-2
*(sizeof(int) > 8)])))
];
909 _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0);
910 char **name, **value;
911 int r;
912
913 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 913,
__PRETTY_FUNCTION__); } while (0)
;
914 assert(fd)do { if ((__builtin_expect(!!(!(fd)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fd"), "../src/tmpfiles/tmpfiles.c", 914
, __PRETTY_FUNCTION__); } while (0)
;
915
916 r = fd_get_path(fd, &path);
917 if (r < 0)
918 return r;
919
920 xsprintf(procfs_path, "/proc/self/fd/%i", fd)do { if ((__builtin_expect(!!(!(((size_t) snprintf(procfs_path
, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(procfs_path), typeof(&*(procfs_path))), sizeof(procfs_path
)/sizeof((procfs_path)[0]), ((void)0))), "/proc/self/fd/%i", fd
) < (__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(procfs_path), typeof(&*(procfs_path))), sizeof(procfs_path
)/sizeof((procfs_path)[0]), ((void)0))))))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("xsprintf: " "procfs_path" "[] must be big enough"
), "../src/tmpfiles/tmpfiles.c", 920, __PRETTY_FUNCTION__); }
while (0)
;
921
922 STRV_FOREACH_PAIR(name, value, i->xattrs)for ((name) = (i->xattrs), (value) = (name+1); (name) &&
*(name) && *(value); (name) += 2, (value) = (name + 1
))
{
923 log_debug("Setting extended attribute '%s=%s' on %s.", *name, *value, path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 923, __func__, "Setting extended attribute '%s=%s' on %s."
, *name, *value, path) : -abs(_e); })
;
924 if (setxattr(procfs_path, *name, *value, strlen(*value), 0) < 0)
925 return log_error_errno(errno, "Setting extended attribute %s=%s on %s failed: %m",({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 926, __func__
, "Setting extended attribute %s=%s on %s failed: %m", *name,
*value, path) : -abs(_e); })
926 *name, *value, path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 926, __func__
, "Setting extended attribute %s=%s on %s failed: %m", *name,
*value, path) : -abs(_e); })
;
927 }
928 return 0;
929}
930
931static int path_set_xattrs(Item *i, const char *path) {
932 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
933
934 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 934,
__PRETTY_FUNCTION__); } while (0)
;
935 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/tmpfiles/tmpfiles.c", 935
, __PRETTY_FUNCTION__); } while (0)
;
936
937 fd = open(path, O_CLOEXEC02000000|O_NOFOLLOW0400000|O_PATH010000000);
938 if (fd < 0)
939 return log_error_errno(errno, "Cannot open '%s': %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 939, __func__
, "Cannot open '%s': %m", path) : -abs(_e); })
;
940
941 return fd_set_xattrs(i, fd, NULL((void*)0));
942}
943
944static int parse_acls_from_arg(Item *item) {
945#if HAVE_ACL1
946 int r;
947
948 assert(item)do { if ((__builtin_expect(!!(!(item)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("item"), "../src/tmpfiles/tmpfiles.c", 948
, __PRETTY_FUNCTION__); } while (0)
;
949
950 /* If force (= modify) is set, we will not modify the acl
951 * afterwards, so the mask can be added now if necessary. */
952
953 r = parse_acl(item->argument, &item->acl_access, &item->acl_default, !item->force);
954 if (r < 0)
955 log_warning_errno(r, "Failed to parse ACL \"%s\": %m. Ignoring", item->argument)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 955, __func__, "Failed to parse ACL \"%s\": %m. Ignoring"
, item->argument) : -abs(_e); })
;
956#else
957 log_warning_errno(ENOSYS, "ACLs are not supported. Ignoring")({ int _level = ((4)), _e = ((38)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 957, __func__, "ACLs are not supported. Ignoring"
) : -abs(_e); })
;
958#endif
959
960 return 0;
961}
962
963#if HAVE_ACL1
964static int path_set_acl(const char *path, const char *pretty, acl_type_t type, acl_t acl, bool_Bool modify) {
965 _cleanup_(acl_free_charpp)__attribute__((cleanup(acl_free_charpp))) char *t = NULL((void*)0);
966 _cleanup_(acl_freep)__attribute__((cleanup(acl_freep))) acl_t dup = NULL((void*)0);
967 int r;
968
969 /* Returns 0 for success, positive error if already warned,
970 * negative error otherwise. */
971
972 if (modify) {
973 r = acls_for_file(path, type, acl, &dup);
974 if (r < 0)
975 return r;
976
977 r = calc_acl_mask_if_needed(&dup);
978 if (r < 0)
979 return r;
980 } else {
981 dup = acl_dup(acl);
982 if (!dup)
983 return -errno(*__errno_location ());
984
985 /* the mask was already added earlier if needed */
986 }
987
988 r = add_base_acls_if_needed(&dup, path);
989 if (r < 0)
990 return r;
991
992 t = acl_to_any_text(dup, NULL((void*)0), ',', TEXT_ABBREVIATE0x10);
993 log_debug("Setting %s ACL %s on %s.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 995, __func__, "Setting %s ACL %s on %s."
, type == (0x8000) ? "access" : "default", strna(t), pretty) :
-abs(_e); })
994 type == ACL_TYPE_ACCESS ? "access" : "default",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 995, __func__, "Setting %s ACL %s on %s."
, type == (0x8000) ? "access" : "default", strna(t), pretty) :
-abs(_e); })
995 strna(t), pretty)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 995, __func__, "Setting %s ACL %s on %s."
, type == (0x8000) ? "access" : "default", strna(t), pretty) :
-abs(_e); })
;
996
997 r = acl_set_file(path, type, dup);
998 if (r < 0)
999 /* Return positive to indicate we already warned */
1000 return -log_error_errno(errno,({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1003, __func__
, "Setting %s ACL \"%s\" on %s failed: %m", type == (0x8000) ?
"access" : "default", strna(t), pretty) : -abs(_e); })
1001 "Setting %s ACL \"%s\" on %s failed: %m",({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1003, __func__
, "Setting %s ACL \"%s\" on %s failed: %m", type == (0x8000) ?
"access" : "default", strna(t), pretty) : -abs(_e); })
1002 type == ACL_TYPE_ACCESS ? "access" : "default",({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1003, __func__
, "Setting %s ACL \"%s\" on %s failed: %m", type == (0x8000) ?
"access" : "default", strna(t), pretty) : -abs(_e); })
1003 strna(t), pretty)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1003, __func__
, "Setting %s ACL \"%s\" on %s failed: %m", type == (0x8000) ?
"access" : "default", strna(t), pretty) : -abs(_e); })
;
1004
1005 return 0;
1006}
1007#endif
1008
1009static int fd_set_acls(Item *item, int fd, const struct stat *st) {
1010 int r = 0;
1011#if HAVE_ACL1
1012 char procfs_path[STRLEN("/proc/self/fd/")(sizeof("""/proc/self/fd/""") - 1) + DECIMAL_STR_MAX(int)(2+(sizeof(int) <= 1 ? 3 : sizeof(int) <= 2 ? 5 : sizeof
(int) <= 4 ? 10 : sizeof(int) <= 8 ? 20 : sizeof(int[-2
*(sizeof(int) > 8)])))
];
1013 _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0);
1014
1015 assert(item)do { if ((__builtin_expect(!!(!(item)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("item"), "../src/tmpfiles/tmpfiles.c", 1015
, __PRETTY_FUNCTION__); } while (0)
;
1016 assert(fd)do { if ((__builtin_expect(!!(!(fd)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fd"), "../src/tmpfiles/tmpfiles.c", 1016
, __PRETTY_FUNCTION__); } while (0)
;
1017 assert(st)do { if ((__builtin_expect(!!(!(st)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("st"), "../src/tmpfiles/tmpfiles.c", 1017
, __PRETTY_FUNCTION__); } while (0)
;
1018
1019 r = fd_get_path(fd, &path);
1020 if (r < 0)
1021 return r;
1022
1023 if (hardlink_vulnerable(st)) {
1024 log_error("Refusing to set ACLs on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off.", path)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1024, __func__, "Refusing to set ACLs on hardlinked file %s while the fs.protected_hardlinks sysctl is turned off."
, path) : -abs(_e); })
;
1025 return -EPERM1;
1026 }
1027
1028 if (S_ISLNK(st->st_mode)((((st->st_mode)) & 0170000) == (0120000))) {
1029 log_debug("Skipping ACL fix for symlink %s.", path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1029, __func__, "Skipping ACL fix for symlink %s."
, path) : -abs(_e); })
;
1030 return 0;
1031 }
1032
1033 xsprintf(procfs_path, "/proc/self/fd/%i", fd)do { if ((__builtin_expect(!!(!(((size_t) snprintf(procfs_path
, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(procfs_path), typeof(&*(procfs_path))), sizeof(procfs_path
)/sizeof((procfs_path)[0]), ((void)0))), "/proc/self/fd/%i", fd
) < (__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(procfs_path), typeof(&*(procfs_path))), sizeof(procfs_path
)/sizeof((procfs_path)[0]), ((void)0))))))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("xsprintf: " "procfs_path" "[] must be big enough"
), "../src/tmpfiles/tmpfiles.c", 1033, __PRETTY_FUNCTION__); }
while (0)
;
1034
1035 if (item->acl_access)
1036 r = path_set_acl(procfs_path, path, ACL_TYPE_ACCESS(0x8000), item->acl_access, item->force);
1037
1038 if (r == 0 && item->acl_default)
1039 r = path_set_acl(procfs_path, path, ACL_TYPE_DEFAULT(0x4000), item->acl_default, item->force);
1040
1041 if (r > 0)
1042 return -r; /* already warned */
1043 if (r == -EOPNOTSUPP95) {
1044 log_debug_errno(r, "ACLs not supported by file system at %s", path)({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1044, __func__, "ACLs not supported by file system at %s"
, path) : -abs(_e); })
;
1045 return 0;
1046 }
1047 if (r < 0)
1048 return log_error_errno(r, "ACL operation on \"%s\" failed: %m", path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1048, __func__, "ACL operation on \"%s\" failed: %m"
, path) : -abs(_e); })
;
1049#endif
1050 return r;
1051}
1052
1053static int path_set_acls(Item *item, const char *path) {
1054 int r = 0;
1055#ifdef HAVE_ACL1
1056 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
1057 struct stat st;
1058
1059 assert(item)do { if ((__builtin_expect(!!(!(item)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("item"), "../src/tmpfiles/tmpfiles.c", 1059
, __PRETTY_FUNCTION__); } while (0)
;
1060 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/tmpfiles/tmpfiles.c", 1060
, __PRETTY_FUNCTION__); } while (0)
;
1061
1062 fd = open(path, O_NOFOLLOW0400000|O_CLOEXEC02000000|O_PATH010000000);
1063 if (fd < 0)
1064 return log_error_errno(errno, "Adjusting ACL of %s failed: %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1064, __func__
, "Adjusting ACL of %s failed: %m", path) : -abs(_e); })
;
1065
1066 if (fstat(fd, &st) < 0)
1067 return log_error_errno(errno, "Failed to fstat() file %s: %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1067, __func__
, "Failed to fstat() file %s: %m", path) : -abs(_e); })
;
1068
1069 r = fd_set_acls(item, fd, &st);
1070 #endif
1071 return r;
1072 }
1073
1074#define ATTRIBUTES_ALL(0x00000080 | 0x00000008 | 0x00010000 | 0x00000020 | 0x00000004
| 0x00000040 | 0x00080000 | 0x00000010 | 0x00004000 | 0x00000001
| 0x00000002 | 0x00008000 | 0x00020000 | 0x00800000)
\
1075 (FS_NOATIME_FL0x00000080 | \
1076 FS_SYNC_FL0x00000008 | \
1077 FS_DIRSYNC_FL0x00010000 | \
1078 FS_APPEND_FL0x00000020 | \
1079 FS_COMPR_FL0x00000004 | \
1080 FS_NODUMP_FL0x00000040 | \
1081 FS_EXTENT_FL0x00080000 | \
1082 FS_IMMUTABLE_FL0x00000010 | \
1083 FS_JOURNAL_DATA_FL0x00004000 | \
1084 FS_SECRM_FL0x00000001 | \
1085 FS_UNRM_FL0x00000002 | \
1086 FS_NOTAIL_FL0x00008000 | \
1087 FS_TOPDIR_FL0x00020000 | \
1088 FS_NOCOW_FL0x00800000)
1089
1090static int parse_attribute_from_arg(Item *item) {
1091
1092 static const struct {
1093 char character;
1094 unsigned value;
1095 } attributes[] = {
1096 { 'A', FS_NOATIME_FL0x00000080 }, /* do not update atime */
1097 { 'S', FS_SYNC_FL0x00000008 }, /* Synchronous updates */
1098 { 'D', FS_DIRSYNC_FL0x00010000 }, /* dirsync behaviour (directories only) */
1099 { 'a', FS_APPEND_FL0x00000020 }, /* writes to file may only append */
1100 { 'c', FS_COMPR_FL0x00000004 }, /* Compress file */
1101 { 'd', FS_NODUMP_FL0x00000040 }, /* do not dump file */
1102 { 'e', FS_EXTENT_FL0x00080000 }, /* Extents */
1103 { 'i', FS_IMMUTABLE_FL0x00000010 }, /* Immutable file */
1104 { 'j', FS_JOURNAL_DATA_FL0x00004000 }, /* Reserved for ext3 */
1105 { 's', FS_SECRM_FL0x00000001 }, /* Secure deletion */
1106 { 'u', FS_UNRM_FL0x00000002 }, /* Undelete */
1107 { 't', FS_NOTAIL_FL0x00008000 }, /* file tail should not be merged */
1108 { 'T', FS_TOPDIR_FL0x00020000 }, /* Top of directory hierarchies */
1109 { 'C', FS_NOCOW_FL0x00800000 }, /* Do not cow file */
1110 };
1111
1112 enum {
1113 MODE_ADD,
1114 MODE_DEL,
1115 MODE_SET
1116 } mode = MODE_ADD;
1117
1118 unsigned value = 0, mask = 0;
1119 const char *p;
1120
1121 assert(item)do { if ((__builtin_expect(!!(!(item)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("item"), "../src/tmpfiles/tmpfiles.c", 1121
, __PRETTY_FUNCTION__); } while (0)
;
1122
1123 p = item->argument;
1124 if (p) {
1125 if (*p == '+') {
1126 mode = MODE_ADD;
1127 p++;
1128 } else if (*p == '-') {
1129 mode = MODE_DEL;
1130 p++;
1131 } else if (*p == '=') {
1132 mode = MODE_SET;
1133 p++;
1134 }
1135 }
1136
1137 if (isempty(p) && mode != MODE_SET) {
1138 log_error("Setting file attribute on '%s' needs an attribute specification.", item->path)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1138, __func__, "Setting file attribute on '%s' needs an attribute specification."
, item->path) : -abs(_e); })
;
1139 return -EINVAL22;
1140 }
1141
1142 for (; p && *p ; p++) {
1143 unsigned i, v;
1144
1145 for (i = 0; i < ELEMENTSOF(attributes)__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(attributes), typeof(&*(attributes))), sizeof(attributes
)/sizeof((attributes)[0]), ((void)0)))
; i++)
1146 if (*p == attributes[i].character)
1147 break;
1148
1149 if (i >= ELEMENTSOF(attributes)__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(attributes), typeof(&*(attributes))), sizeof(attributes
)/sizeof((attributes)[0]), ((void)0)))
) {
1150 log_error("Unknown file attribute '%c' on '%s'.", *p, item->path)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1150, __func__, "Unknown file attribute '%c' on '%s'."
, *p, item->path) : -abs(_e); })
;
1151 return -EINVAL22;
1152 }
1153
1154 v = attributes[i].value;
1155
1156 SET_FLAG(value, v, IN_SET(mode, MODE_ADD, MODE_SET))(value) = (({ _Bool _found = 0; static __attribute__ ((unused
)) char _static_assert__macros_need_to_be_extended[20 - sizeof
((int[]){MODE_ADD, MODE_SET})/sizeof(int)]; switch(mode) { case
MODE_ADD: case MODE_SET: _found = 1; break; default: break; }
_found; })) ? ((value) | (v)) : ((value) & ~(v))
;
1157
1158 mask |= v;
1159 }
1160
1161 if (mode == MODE_SET)
1162 mask |= ATTRIBUTES_ALL(0x00000080 | 0x00000008 | 0x00010000 | 0x00000020 | 0x00000004
| 0x00000040 | 0x00080000 | 0x00000010 | 0x00004000 | 0x00000001
| 0x00000002 | 0x00008000 | 0x00020000 | 0x00800000)
;
1163
1164 assert(mask != 0)do { if ((__builtin_expect(!!(!(mask != 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("mask != 0"), "../src/tmpfiles/tmpfiles.c"
, 1164, __PRETTY_FUNCTION__); } while (0)
;
1165
1166 item->attribute_mask = mask;
1167 item->attribute_value = value;
1168 item->attribute_set = true1;
1169
1170 return 0;
1171}
1172
1173static int fd_set_attribute(Item *item, int fd, const struct stat *st) {
1174 _cleanup_close___attribute__((cleanup(closep))) int procfs_fd = -1;
1175 _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0);
1176 unsigned f;
1177 int r;
1178
1179 if (!item->attribute_set || item->attribute_mask == 0)
1180 return 0;
1181
1182 r = fd_get_path(fd, &path);
1183 if (r < 0)
1184 return r;
1185
1186 /* Issuing the file attribute ioctls on device nodes is not
1187 * safe, as that will be delivered to the drivers, not the
1188 * file system containing the device node. */
1189 if (!S_ISREG(st->st_mode)((((st->st_mode)) & 0170000) == (0100000)) && !S_ISDIR(st->st_mode)((((st->st_mode)) & 0170000) == (0040000))) {
1190 log_error("Setting file flags is only supported on regular files and directories, cannot set on '%s'.", path)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1190, __func__, "Setting file flags is only supported on regular files and directories, cannot set on '%s'."
, path) : -abs(_e); })
;
1191 return -EINVAL22;
1192 }
1193
1194 f = item->attribute_value & item->attribute_mask;
1195
1196 /* Mask away directory-specific flags */
1197 if (!S_ISDIR(st->st_mode)((((st->st_mode)) & 0170000) == (0040000)))
1198 f &= ~FS_DIRSYNC_FL0x00010000;
1199
1200 procfs_fd = fd_reopen(fd, O_RDONLY00|O_CLOEXEC02000000|O_NOATIME01000000);
1201 if (procfs_fd < 0)
1202 return -errno(*__errno_location ());
1203
1204 r = chattr_fd(procfs_fd, f, item->attribute_mask);
1205 if (r < 0)
1206 log_full_errno(IN_SET(r, -ENOTTY, -EOPNOTSUPP) ? LOG_DEBUG : LOG_WARNING,({ int _level = ((({ _Bool _found = 0; static __attribute__ (
(unused)) char _static_assert__macros_need_to_be_extended[20 -
sizeof((int[]){-25, -95})/sizeof(int)]; switch(r) { case -25
: case -95: _found = 1; break; default: break; } _found; }) ?
7 : 4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c"
, 1209, __func__, "Cannot set file attribute for '%s', value=0x%08x, mask=0x%08x: %m"
, path, item->attribute_value, item->attribute_mask) : -
abs(_e); })
1207 r,({ int _level = ((({ _Bool _found = 0; static __attribute__ (
(unused)) char _static_assert__macros_need_to_be_extended[20 -
sizeof((int[]){-25, -95})/sizeof(int)]; switch(r) { case -25
: case -95: _found = 1; break; default: break; } _found; }) ?
7 : 4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c"
, 1209, __func__, "Cannot set file attribute for '%s', value=0x%08x, mask=0x%08x: %m"
, path, item->attribute_value, item->attribute_mask) : -
abs(_e); })
1208 "Cannot set file attribute for '%s', value=0x%08x, mask=0x%08x: %m",({ int _level = ((({ _Bool _found = 0; static __attribute__ (
(unused)) char _static_assert__macros_need_to_be_extended[20 -
sizeof((int[]){-25, -95})/sizeof(int)]; switch(r) { case -25
: case -95: _found = 1; break; default: break; } _found; }) ?
7 : 4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c"
, 1209, __func__, "Cannot set file attribute for '%s', value=0x%08x, mask=0x%08x: %m"
, path, item->attribute_value, item->attribute_mask) : -
abs(_e); })
1209 path, item->attribute_value, item->attribute_mask)({ int _level = ((({ _Bool _found = 0; static __attribute__ (
(unused)) char _static_assert__macros_need_to_be_extended[20 -
sizeof((int[]){-25, -95})/sizeof(int)]; switch(r) { case -25
: case -95: _found = 1; break; default: break; } _found; }) ?
7 : 4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c"
, 1209, __func__, "Cannot set file attribute for '%s', value=0x%08x, mask=0x%08x: %m"
, path, item->attribute_value, item->attribute_mask) : -
abs(_e); })
;
1210
1211 return 0;
1212}
1213
1214static int path_set_attribute(Item *item, const char *path) {
1215 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
1216 struct stat st;
1217
1218 if (!item->attribute_set || item->attribute_mask == 0)
1219 return 0;
1220
1221 fd = open(path, O_CLOEXEC02000000|O_NOFOLLOW0400000|O_PATH010000000);
1222 if (fd < 0)
1223 return log_error_errno(errno, "Cannot open '%s': %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1223, __func__
, "Cannot open '%s': %m", path) : -abs(_e); })
;
1224
1225 if (fstat(fd, &st) < 0)
1226 return log_error_errno(errno, "Cannot stat '%s': %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1226, __func__
, "Cannot stat '%s': %m", path) : -abs(_e); })
;
1227
1228 return fd_set_attribute(item, fd, &st);
1229}
1230
1231static int write_one_file(Item *i, const char *path) {
1232 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
1233 int flags, r = 0;
1234 struct stat st;
1235
1236 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1236
, __PRETTY_FUNCTION__); } while (0)
;
1237 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/tmpfiles/tmpfiles.c", 1237
, __PRETTY_FUNCTION__); } while (0)
;
1238
1239 flags = i->type == CREATE_FILE ? O_CREAT0100|O_EXCL0200|O_NOFOLLOW0400000 :
1240 i->type == TRUNCATE_FILE ? O_CREAT0100|O_TRUNC01000|O_NOFOLLOW0400000 : 0;
1241
1242 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
{
1243 mac_selinux_create_file_prepare(path, S_IFREG0100000);
1244 fd = open(path, flags|O_NONBLOCK04000|O_CLOEXEC02000000|O_WRONLY01|O_NOCTTY0400, i->mode);
1245 mac_selinux_create_file_clear();
1246 }
1247
1248 if (fd < 0) {
1249 if (i->type == WRITE_FILE && errno(*__errno_location ()) == ENOENT2) {
1250 log_debug_errno(errno, "Not writing missing file \"%s\": %m", path)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1250, __func__
, "Not writing missing file \"%s\": %m", path) : -abs(_e); })
;
1251 return 0;
1252 }
1253 if (i->type == CREATE_FILE && errno(*__errno_location ()) == EEXIST17) {
1254 log_debug_errno(errno, "Not writing to pre-existing file \"%s\": %m", path)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1254, __func__
, "Not writing to pre-existing file \"%s\": %m", path) : -abs
(_e); })
;
1255 goto done;
1256 }
1257
1258 r = -errno(*__errno_location ());
1259 if (!i->argument && errno(*__errno_location ()) == EROFS30 && stat(path, &st) == 0 &&
1260 (i->type == CREATE_FILE || st.st_size == 0))
1261 goto check_mode;
1262
1263 return log_error_errno(r, "Failed to create file %s: %m", path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1263, __func__, "Failed to create file %s: %m"
, path) : -abs(_e); })
;
1264 }
1265
1266 if (i->argument) {
1267 log_debug("%s to \"%s\".", i->type == CREATE_FILE ? "Appending" : "Writing", path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1267, __func__, "%s to \"%s\"."
, i->type == CREATE_FILE ? "Appending" : "Writing", path) :
-abs(_e); })
;
1268
1269 r = loop_write(fd, i->argument, strlen(i->argument), false0);
1270 if (r < 0)
1271 return log_error_errno(r, "Failed to write file \"%s\": %m", path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1271, __func__, "Failed to write file \"%s\": %m"
, path) : -abs(_e); })
;
1272 } else
1273 log_debug("\"%s\" has been created.", path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1273, __func__, "\"%s\" has been created."
, path) : -abs(_e); })
;
1274
1275 fd = safe_close(fd);
1276
1277 done:
1278 if (stat(path, &st) < 0)
1279 return log_error_errno(errno, "stat(%s) failed: %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1279, __func__
, "stat(%s) failed: %m", path) : -abs(_e); })
;
1280
1281 check_mode:
1282 if (!S_ISREG(st.st_mode)((((st.st_mode)) & 0170000) == (0100000))) {
1283 log_error("%s is not a file.", path)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1283, __func__, "%s is not a file."
, path) : -abs(_e); })
;
1284 return -EEXIST17;
1285 }
1286
1287 r = path_set_perms(i, path);
1288 if (r < 0)
1289 return r;
1290
1291 return 0;
1292}
1293
1294typedef int (*action_t)(Item *, const char *);
1295typedef int (*fdaction_t)(Item *, int fd, const struct stat *st);
1296
1297static int item_do(Item *i, int fd, const struct stat *st, fdaction_t action) {
1298 int r = 0, q;
1299
1300 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1300
, __PRETTY_FUNCTION__); } while (0)
;
1301 assert(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/tmpfiles/tmpfiles.c"
, 1301, __PRETTY_FUNCTION__); } while (0)
;
1302 assert(st)do { if ((__builtin_expect(!!(!(st)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("st"), "../src/tmpfiles/tmpfiles.c", 1302
, __PRETTY_FUNCTION__); } while (0)
;
1303
1304 /* This returns the first error we run into, but nevertheless
1305 * tries to go on */
1306 r = action(i, fd, st);
1307
1308 if (S_ISDIR(st->st_mode)((((st->st_mode)) & 0170000) == (0040000))) {
1309 char procfs_path[STRLEN("/proc/self/fd/")(sizeof("""/proc/self/fd/""") - 1) + DECIMAL_STR_MAX(int)(2+(sizeof(int) <= 1 ? 3 : sizeof(int) <= 2 ? 5 : sizeof
(int) <= 4 ? 10 : sizeof(int) <= 8 ? 20 : sizeof(int[-2
*(sizeof(int) > 8)])))
];
1310 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
1311 struct dirent *de;
1312
1313 /* The passed 'fd' was opened with O_PATH. We need to convert
1314 * it into a 'regular' fd before reading the directory content. */
1315 xsprintf(procfs_path, "/proc/self/fd/%i", fd)do { if ((__builtin_expect(!!(!(((size_t) snprintf(procfs_path
, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(procfs_path), typeof(&*(procfs_path))), sizeof(procfs_path
)/sizeof((procfs_path)[0]), ((void)0))), "/proc/self/fd/%i", fd
) < (__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(procfs_path), typeof(&*(procfs_path))), sizeof(procfs_path
)/sizeof((procfs_path)[0]), ((void)0))))))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("xsprintf: " "procfs_path" "[] must be big enough"
), "../src/tmpfiles/tmpfiles.c", 1315, __PRETTY_FUNCTION__); }
while (0)
;
1316
1317 d = opendir(procfs_path);
1318 if (!d) {
1319 r = r ?: -errno(*__errno_location ());
1320 goto finish;
1321 }
1322
1323 FOREACH_DIRENT_ALL(de, d, q = -errno; goto finish)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location
()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location (
)) > 0) { q = -(*__errno_location ()); goto finish; } break
; } else
{
1324 struct stat de_st;
1325 int de_fd;
1326
1327 if (dot_or_dot_dot(de->d_name))
1328 continue;
1329
1330 de_fd = openat(fd, de->d_name, O_NOFOLLOW0400000|O_CLOEXEC02000000|O_PATH010000000);
1331 if (de_fd >= 0 && fstat(de_fd, &de_st) >= 0)
1332 /* pass ownership of dirent fd over */
1333 q = item_do(i, de_fd, &de_st, action);
1334 else
1335 q = -errno(*__errno_location ());
1336
1337 if (q < 0 && r == 0)
1338 r = q;
1339 }
1340 }
1341finish:
1342 safe_close(fd);
1343 return r;
1344}
1345
1346static int glob_item(Item *i, action_t action) {
1347 _cleanup_globfree___attribute__((cleanup(globfree))) glob_t g = {
1348 .gl_opendir = (void *(*)(const char *)) opendir_nomod,
1349 };
1350 int r = 0, k;
1351 char **fn;
1352
1353 k = safe_glob(i->path, GLOB_NOSORT(1 << 2)|GLOB_BRACE(1 << 10), &g);
1354 if (k < 0 && k != -ENOENT2)
1355 return log_error_errno(k, "glob(%s) failed: %m", i->path)({ int _level = ((3)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1355, __func__, "glob(%s) failed: %m"
, i->path) : -abs(_e); })
;
1356
1357 STRV_FOREACH(fn, g.gl_pathv)for ((fn) = (g.gl_pathv); (fn) && *(fn); (fn)++) {
1358 k = action(i, *fn);
1359 if (k < 0 && r == 0)
1360 r = k;
1361 }
1362
1363 return r;
1364}
1365
1366static int glob_item_recursively(Item *i, fdaction_t action) {
1367 _cleanup_globfree___attribute__((cleanup(globfree))) glob_t g = {
1368 .gl_opendir = (void *(*)(const char *)) opendir_nomod,
1369 };
1370 int r = 0, k;
1371 char **fn;
1372
1373 k = safe_glob(i->path, GLOB_NOSORT(1 << 2)|GLOB_BRACE(1 << 10), &g);
1374 if (k < 0 && k != -ENOENT2)
1375 return log_error_errno(k, "glob(%s) failed: %m", i->path)({ int _level = ((3)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1375, __func__, "glob(%s) failed: %m"
, i->path) : -abs(_e); })
;
1376
1377 STRV_FOREACH(fn, g.gl_pathv)for ((fn) = (g.gl_pathv); (fn) && *(fn); (fn)++) {
1378 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
1379 struct stat st;
1380
1381 /* Make sure we won't trigger/follow file object (such as
1382 * device nodes, automounts, ...) pointed out by 'fn' with
1383 * O_PATH. Note, when O_PATH is used, flags other than
1384 * O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW are ignored. */
1385
1386 fd = open(*fn, O_CLOEXEC02000000|O_NOFOLLOW0400000|O_PATH010000000);
1387 if (fd < 0) {
1388 r = r ?: -errno(*__errno_location ());
1389 continue;
1390 }
1391
1392 if (fstat(fd, &st) < 0) {
1393 r = r ?: -errno(*__errno_location ());
1394 continue;
1395 }
1396
1397 k = item_do(i, fd, &st, action);
1398 if (k < 0 && r == 0)
1399 r = k;
1400
1401 /* we passed fd ownership to the previous call */
1402 fd = -1;
1403 }
1404
1405 return r;
1406}
1407
1408typedef enum {
1409 CREATION_NORMAL,
1410 CREATION_EXISTING,
1411 CREATION_FORCE,
1412 _CREATION_MODE_MAX,
1413 _CREATION_MODE_INVALID = -1
1414} CreationMode;
1415
1416static const char *creation_mode_verb_table[_CREATION_MODE_MAX] = {
1417 [CREATION_NORMAL] = "Created",
1418 [CREATION_EXISTING] = "Found existing",
1419 [CREATION_FORCE] = "Created replacement",
1420};
1421
1422DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(creation_mode_verb, CreationMode)static const char *creation_mode_verb_to_string(CreationMode i
) { if (i < 0 || i >= (CreationMode) __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(creation_mode_verb_table
), typeof(&*(creation_mode_verb_table))), sizeof(creation_mode_verb_table
)/sizeof((creation_mode_verb_table)[0]), ((void)0)))) return (
(void*)0); return creation_mode_verb_table[i]; }
;
1423
1424static int create_item(Item *i) {
1425 struct stat st;
1426 int r = 0;
1427 int q = 0;
1428 CreationMode creation;
1429
1430 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1430
, __PRETTY_FUNCTION__); } while (0)
;
1431
1432 log_debug("Running create action for entry %c %s", (char) i->type, i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1432, __func__, "Running create action for entry %c %s"
, (char) i->type, i->path) : -abs(_e); })
;
1433
1434 switch (i->type) {
1435
1436 case IGNORE_PATH:
1437 case IGNORE_DIRECTORY_PATH:
1438 case REMOVE_PATH:
1439 case RECURSIVE_REMOVE_PATH:
1440 return 0;
1441
1442 case CREATE_FILE:
1443 case TRUNCATE_FILE:
1444 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
1445 (void) mkdir_parents_label(i->path, 0755);
1446
1447 r = write_one_file(i, i->path);
1448 if (r < 0)
1449 return r;
1450 break;
1451
1452 case COPY_FILES:
1453 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
1454 (void) mkdir_parents_label(i->path, 0755);
1455
1456 log_debug("Copying tree \"%s\" to \"%s\".", i->argument, i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1456, __func__, "Copying tree \"%s\" to \"%s\"."
, i->argument, i->path) : -abs(_e); })
;
1457 r = copy_tree(i->argument, i->path,
1458 i->uid_set ? i->uid : UID_INVALID((uid_t) -1),
1459 i->gid_set ? i->gid : GID_INVALID((gid_t) -1),
1460 COPY_REFLINK);
1461
1462 if (r == -EROFS30 && stat(i->path, &st) == 0)
1463 r = -EEXIST17;
1464
1465 if (r < 0) {
1466 struct stat a, b;
1467
1468 if (r != -EEXIST17)
1469 return log_error_errno(r, "Failed to copy files to %s: %m", i->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1469, __func__, "Failed to copy files to %s: %m"
, i->path) : -abs(_e); })
;
1470
1471 if (stat(i->argument, &a) < 0)
1472 return log_error_errno(errno, "stat(%s) failed: %m", i->argument)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1472, __func__
, "stat(%s) failed: %m", i->argument) : -abs(_e); })
;
1473
1474 if (stat(i->path, &b) < 0)
1475 return log_error_errno(errno, "stat(%s) failed: %m", i->path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1475, __func__
, "stat(%s) failed: %m", i->path) : -abs(_e); })
;
1476
1477 if ((a.st_mode ^ b.st_mode) & S_IFMT0170000) {
1478 log_debug("Can't copy to %s, file exists already and is of different type", i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1478, __func__, "Can't copy to %s, file exists already and is of different type"
, i->path) : -abs(_e); })
;
1479 return 0;
1480 }
1481 }
1482
1483 r = path_set_perms(i, i->path);
1484 if (r < 0)
1485 return r;
1486
1487 break;
1488
1489 case WRITE_FILE:
1490 r = glob_item(i, write_one_file);
1491 if (r < 0)
1492 return r;
1493
1494 break;
1495
1496 case CREATE_DIRECTORY:
1497 case TRUNCATE_DIRECTORY:
1498 case CREATE_SUBVOLUME:
1499 case CREATE_SUBVOLUME_INHERIT_QUOTA:
1500 case CREATE_SUBVOLUME_NEW_QUOTA:
1501 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
1502 (void) mkdir_parents_label(i->path, 0755);
1503
1504 if (IN_SET(i->type, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA
, CREATE_SUBVOLUME_NEW_QUOTA})/sizeof(int)]; switch(i->type
) { case CREATE_SUBVOLUME: case CREATE_SUBVOLUME_INHERIT_QUOTA
: case CREATE_SUBVOLUME_NEW_QUOTA: _found = 1; break; default
: break; } _found; })
) {
1505
1506 if (btrfs_is_subvol(empty_to_root(arg_root)) <= 0)
1507
1508 /* Don't create a subvolume unless the
1509 * root directory is one, too. We do
1510 * this under the assumption that if
1511 * the root directory is just a plain
1512 * directory (i.e. very light-weight),
1513 * we shouldn't try to split it up
1514 * into subvolumes (i.e. more
1515 * heavy-weight). Thus, chroot()
1516 * environments and suchlike will get
1517 * a full brtfs subvolume set up below
1518 * their tree only if they
1519 * specifically set up a btrfs
1520 * subvolume for the root dir too. */
1521
1522 r = -ENOTTY25;
1523 else {
1524 RUN_WITH_UMASK((~i->mode) & 0777)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask((~i->mode) & 0777), 0 }; !_saved_umask_
.quit ; _saved_umask_.quit = 1)
1525 r = btrfs_subvol_make(i->path);
1526 }
1527 } else
1528 r = 0;
1529
1530 if (IN_SET(i->type, CREATE_DIRECTORY, TRUNCATE_DIRECTORY)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_DIRECTORY, TRUNCATE_DIRECTORY})/sizeof
(int)]; switch(i->type) { case CREATE_DIRECTORY: case TRUNCATE_DIRECTORY
: _found = 1; break; default: break; } _found; })
|| r == -ENOTTY25)
1531 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
1532 r = mkdir_label(i->path, i->mode);
1533
1534 if (r < 0) {
1535 int k;
1536
1537 if (!IN_SET(r, -EEXIST, -EROFS)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-17, -30})/sizeof(int)]; switch(r) { case
-17: case -30: _found = 1; break; default: break; } _found; }
)
)
1538 return log_error_errno(r, "Failed to create directory or subvolume \"%s\": %m", i->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1538, __func__, "Failed to create directory or subvolume \"%s\": %m"
, i->path) : -abs(_e); })
;
1539
1540 k = is_dir(i->path, false0);
1541 if (k == -ENOENT2 && r == -EROFS30)
1542 return log_error_errno(r, "%s does not exist and cannot be created as the file system is read-only.", i->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1542, __func__, "%s does not exist and cannot be created as the file system is read-only."
, i->path) : -abs(_e); })
;
1543 if (k < 0)
1544 return log_error_errno(k, "Failed to check if %s exists: %m", i->path)({ int _level = ((3)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1544, __func__, "Failed to check if %s exists: %m"
, i->path) : -abs(_e); })
;
1545 if (!k) {
1546 log_warning("\"%s\" already exists and is not a directory.", i->path)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1546, __func__, "\"%s\" already exists and is not a directory."
, i->path) : -abs(_e); })
;
1547 return 0;
1548 }
1549
1550 creation = CREATION_EXISTING;
1551 } else
1552 creation = CREATION_NORMAL;
1553
1554 log_debug("%s directory \"%s\".", creation_mode_verb_to_string(creation), i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1554, __func__, "%s directory \"%s\"."
, creation_mode_verb_to_string(creation), i->path) : -abs(
_e); })
;
1555
1556 if (IN_SET(i->type, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_SUBVOLUME_INHERIT_QUOTA)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_SUBVOLUME_NEW_QUOTA, CREATE_SUBVOLUME_INHERIT_QUOTA
})/sizeof(int)]; switch(i->type) { case CREATE_SUBVOLUME_NEW_QUOTA
: case CREATE_SUBVOLUME_INHERIT_QUOTA: _found = 1; break; default
: break; } _found; })
) {
1557 r = btrfs_subvol_auto_qgroup(i->path, 0, i->type == CREATE_SUBVOLUME_NEW_QUOTA);
1558 if (r == -ENOTTY25)
1559 log_debug_errno(r, "Couldn't adjust quota for subvolume \"%s\" (unsupported fs or dir not a subvolume): %m", i->path)({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1559, __func__, "Couldn't adjust quota for subvolume \"%s\" (unsupported fs or dir not a subvolume): %m"
, i->path) : -abs(_e); })
;
1560 else if (r == -EROFS30)
1561 log_debug_errno(r, "Couldn't adjust quota for subvolume \"%s\" (fs is read-only).", i->path)({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1561, __func__, "Couldn't adjust quota for subvolume \"%s\" (fs is read-only)."
, i->path) : -abs(_e); })
;
1562 else if (r == -ENOPROTOOPT92)
1563 log_debug_errno(r, "Couldn't adjust quota for subvolume \"%s\" (quota support is disabled).", i->path)({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1563, __func__, "Couldn't adjust quota for subvolume \"%s\" (quota support is disabled)."
, i->path) : -abs(_e); })
;
1564 else if (r < 0)
1565 q = log_error_errno(r, "Failed to adjust quota for subvolume \"%s\": %m", i->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1565, __func__, "Failed to adjust quota for subvolume \"%s\": %m"
, i->path) : -abs(_e); })
;
1566 else if (r > 0)
1567 log_debug("Adjusted quota for subvolume \"%s\".", i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1567, __func__, "Adjusted quota for subvolume \"%s\"."
, i->path) : -abs(_e); })
;
1568 else if (r == 0)
1569 log_debug("Quota for subvolume \"%s\" already in place, no change made.", i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1569, __func__, "Quota for subvolume \"%s\" already in place, no change made."
, i->path) : -abs(_e); })
;
1570 }
1571
1572 _fallthrough_;
1573 case EMPTY_DIRECTORY:
1574 r = glob_item(i, path_set_perms);
1575 if (q < 0)
1576 return q;
1577 if (r < 0)
1578 return r;
1579
1580 break;
1581
1582 case CREATE_FIFO:
1583 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
{
1584 (void) mkdir_parents_label(i->path, 0755);
1585
1586 mac_selinux_create_file_prepare(i->path, S_IFIFO0010000);
1587 r = mkfifo(i->path, i->mode);
1588 mac_selinux_create_file_clear();
1589 }
1590
1591 if (r < 0) {
1592 if (errno(*__errno_location ()) != EEXIST17)
1593 return log_error_errno(errno, "Failed to create fifo %s: %m", i->path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1593, __func__
, "Failed to create fifo %s: %m", i->path) : -abs(_e); })
;
1594
1595 if (lstat(i->path, &st) < 0)
1596 return log_error_errno(errno, "stat(%s) failed: %m", i->path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1596, __func__
, "stat(%s) failed: %m", i->path) : -abs(_e); })
;
1597
1598 if (!S_ISFIFO(st.st_mode)((((st.st_mode)) & 0170000) == (0010000))) {
1599
1600 if (i->force) {
1601 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
{
1602 mac_selinux_create_file_prepare(i->path, S_IFIFO0010000);
1603 r = mkfifo_atomic(i->path, i->mode);
1604 mac_selinux_create_file_clear();
1605 }
1606
1607 if (r < 0)
1608 return log_error_errno(r, "Failed to create fifo %s: %m", i->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1608, __func__, "Failed to create fifo %s: %m"
, i->path) : -abs(_e); })
;
1609 creation = CREATION_FORCE;
1610 } else {
1611 log_warning("\"%s\" already exists and is not a fifo.", i->path)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1611, __func__, "\"%s\" already exists and is not a fifo."
, i->path) : -abs(_e); })
;
1612 return 0;
1613 }
1614 } else
1615 creation = CREATION_EXISTING;
1616 } else
1617 creation = CREATION_NORMAL;
1618 log_debug("%s fifo \"%s\".", creation_mode_verb_to_string(creation), i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1618, __func__, "%s fifo \"%s\"."
, creation_mode_verb_to_string(creation), i->path) : -abs(
_e); })
;
1619
1620 r = path_set_perms(i, i->path);
1621 if (r < 0)
1622 return r;
1623
1624 break;
1625
1626 case CREATE_SYMLINK: {
1627 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
1628 (void) mkdir_parents_label(i->path, 0755);
1629
1630 mac_selinux_create_file_prepare(i->path, S_IFLNK0120000);
1631 r = symlink(i->argument, i->path);
1632 mac_selinux_create_file_clear();
1633
1634 if (r < 0) {
1635 _cleanup_free___attribute__((cleanup(freep))) char *x = NULL((void*)0);
1636
1637 if (errno(*__errno_location ()) != EEXIST17)
1638 return log_error_errno(errno, "symlink(%s, %s) failed: %m", i->argument, i->path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1638, __func__
, "symlink(%s, %s) failed: %m", i->argument, i->path) :
-abs(_e); })
;
1639
1640 r = readlink_malloc(i->path, &x);
1641 if (r < 0 || !streq(i->argument, x)(strcmp((i->argument),(x)) == 0)) {
1642
1643 if (i->force) {
1644 mac_selinux_create_file_prepare(i->path, S_IFLNK0120000);
1645 r = symlink_atomic(i->argument, i->path);
1646 mac_selinux_create_file_clear();
1647
1648 if (IN_SET(r, -EISDIR, -EEXIST, -ENOTEMPTY)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-21, -17, -39})/sizeof(int)]; switch(r) {
case -21: case -17: case -39: _found = 1; break; default: break
; } _found; })
) {
1649 r = rm_rf(i->path, REMOVE_ROOT|REMOVE_PHYSICAL);
1650 if (r < 0)
1651 return log_error_errno(r, "rm -fr %s failed: %m", i->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1651, __func__, "rm -fr %s failed: %m"
, i->path) : -abs(_e); })
;
1652
1653 mac_selinux_create_file_prepare(i->path, S_IFLNK0120000);
1654 r = symlink(i->argument, i->path) < 0 ? -errno(*__errno_location ()) : 0;
1655 mac_selinux_create_file_clear();
1656 }
1657 if (r < 0)
1658 return log_error_errno(r, "symlink(%s, %s) failed: %m", i->argument, i->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1658, __func__, "symlink(%s, %s) failed: %m"
, i->argument, i->path) : -abs(_e); })
;
1659
1660 creation = CREATION_FORCE;
1661 } else {
1662 log_debug("\"%s\" is not a symlink or does not point to the correct path.", i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1662, __func__, "\"%s\" is not a symlink or does not point to the correct path."
, i->path) : -abs(_e); })
;
1663 return 0;
1664 }
1665 } else
1666 creation = CREATION_EXISTING;
1667 } else
1668
1669 creation = CREATION_NORMAL;
1670 log_debug("%s symlink \"%s\".", creation_mode_verb_to_string(creation), i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1670, __func__, "%s symlink \"%s\"."
, creation_mode_verb_to_string(creation), i->path) : -abs(
_e); })
;
1671 break;
1672 }
1673
1674 case CREATE_BLOCK_DEVICE:
1675 case CREATE_CHAR_DEVICE: {
1676 mode_t file_type;
1677
1678 if (have_effective_cap(CAP_MKNOD27) == 0) {
1679 /* In a container we lack CAP_MKNOD. We
1680 shouldn't attempt to create the device node in
1681 that case to avoid noise, and we don't support
1682 virtualized devices in containers anyway. */
1683
1684 log_debug("We lack CAP_MKNOD, skipping creation of device node %s.", i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1684, __func__, "We lack CAP_MKNOD, skipping creation of device node %s."
, i->path) : -abs(_e); })
;
1685 return 0;
1686 }
1687
1688 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
1689 (void) mkdir_parents_label(i->path, 0755);
1690
1691 file_type = i->type == CREATE_BLOCK_DEVICE ? S_IFBLK0060000 : S_IFCHR0020000;
1692
1693 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
{
1694 mac_selinux_create_file_prepare(i->path, file_type);
1695 r = mknod(i->path, i->mode | file_type, i->major_minor);
1696 mac_selinux_create_file_clear();
1697 }
1698
1699 if (r < 0) {
1700 if (errno(*__errno_location ()) == EPERM1) {
1701 log_debug("We lack permissions, possibly because of cgroup configuration; "({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1702, __func__, "We lack permissions, possibly because of cgroup configuration; "
"skipping creation of device node %s.", i->path) : -abs(_e
); })
1702 "skipping creation of device node %s.", i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1702, __func__, "We lack permissions, possibly because of cgroup configuration; "
"skipping creation of device node %s.", i->path) : -abs(_e
); })
;
1703 return 0;
1704 }
1705
1706 if (errno(*__errno_location ()) != EEXIST17)
1707 return log_error_errno(errno, "Failed to create device node %s: %m", i->path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1707, __func__
, "Failed to create device node %s: %m", i->path) : -abs(_e
); })
;
1708
1709 if (lstat(i->path, &st) < 0)
1710 return log_error_errno(errno, "stat(%s) failed: %m", i->path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1710, __func__
, "stat(%s) failed: %m", i->path) : -abs(_e); })
;
1711
1712 if ((st.st_mode & S_IFMT0170000) != file_type) {
1713
1714 if (i->force) {
1715
1716 RUN_WITH_UMASK(0000)for (__attribute__((cleanup(_reset_umask_))) struct _umask_struct_
_saved_umask_ = { umask(0000), 0 }; !_saved_umask_.quit ; _saved_umask_
.quit = 1)
{
1717 mac_selinux_create_file_prepare(i->path, file_type);
1718 r = mknod_atomic(i->path, i->mode | file_type, i->major_minor);
1719 mac_selinux_create_file_clear();
1720 }
1721
1722 if (r < 0)
1723 return log_error_errno(r, "Failed to create device node \"%s\": %m", i->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1723, __func__, "Failed to create device node \"%s\": %m"
, i->path) : -abs(_e); })
;
1724 creation = CREATION_FORCE;
1725 } else {
1726 log_debug("%s is not a device node.", i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1726, __func__, "%s is not a device node."
, i->path) : -abs(_e); })
;
1727 return 0;
1728 }
1729 } else
1730 creation = CREATION_EXISTING;
1731 } else
1732 creation = CREATION_NORMAL;
1733
1734 log_debug("%s %s device node \"%s\" %u:%u.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1737, __func__, "%s %s device node \"%s\" %u:%u."
, creation_mode_verb_to_string(creation), i->type == CREATE_BLOCK_DEVICE
? "block" : "char", i->path, gnu_dev_major (i->mode), gnu_dev_minor
(i->mode)) : -abs(_e); })
1735 creation_mode_verb_to_string(creation),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1737, __func__, "%s %s device node \"%s\" %u:%u."
, creation_mode_verb_to_string(creation), i->type == CREATE_BLOCK_DEVICE
? "block" : "char", i->path, gnu_dev_major (i->mode), gnu_dev_minor
(i->mode)) : -abs(_e); })
1736 i->type == CREATE_BLOCK_DEVICE ? "block" : "char",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1737, __func__, "%s %s device node \"%s\" %u:%u."
, creation_mode_verb_to_string(creation), i->type == CREATE_BLOCK_DEVICE
? "block" : "char", i->path, gnu_dev_major (i->mode), gnu_dev_minor
(i->mode)) : -abs(_e); })
1737 i->path, major(i->mode), minor(i->mode))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1737, __func__, "%s %s device node \"%s\" %u:%u."
, creation_mode_verb_to_string(creation), i->type == CREATE_BLOCK_DEVICE
? "block" : "char", i->path, gnu_dev_major (i->mode), gnu_dev_minor
(i->mode)) : -abs(_e); })
;
1738
1739 r = path_set_perms(i, i->path);
1740 if (r < 0)
1741 return r;
1742
1743 break;
1744 }
1745
1746 case ADJUST_MODE:
1747 case RELABEL_PATH:
1748 r = glob_item(i, path_set_perms);
1749 if (r < 0)
1750 return r;
1751 break;
1752
1753 case RECURSIVE_RELABEL_PATH:
1754 r = glob_item_recursively(i, fd_set_perms);
1755 if (r < 0)
1756 return r;
1757 break;
1758
1759 case SET_XATTR:
1760 r = glob_item(i, path_set_xattrs);
1761 if (r < 0)
1762 return r;
1763 break;
1764
1765 case RECURSIVE_SET_XATTR:
1766 r = glob_item_recursively(i, fd_set_xattrs);
1767 if (r < 0)
1768 return r;
1769 break;
1770
1771 case SET_ACL:
1772 r = glob_item(i, path_set_acls);
1773 if (r < 0)
1774 return r;
1775 break;
1776
1777 case RECURSIVE_SET_ACL:
1778 r = glob_item_recursively(i, fd_set_acls);
1779 if (r < 0)
1780 return r;
1781 break;
1782
1783 case SET_ATTRIBUTE:
1784 r = glob_item(i, path_set_attribute);
1785 if (r < 0)
1786 return r;
1787 break;
1788
1789 case RECURSIVE_SET_ATTRIBUTE:
1790 r = glob_item_recursively(i, fd_set_attribute);
1791 if (r < 0)
1792 return r;
1793 break;
1794 }
1795
1796 return 0;
1797}
1798
1799static int remove_item_instance(Item *i, const char *instance) {
1800 int r;
1801
1802 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1802
, __PRETTY_FUNCTION__); } while (0)
;
1803
1804 switch (i->type) {
1805
1806 case REMOVE_PATH:
1807 if (remove(instance) < 0 && errno(*__errno_location ()) != ENOENT2)
1808 return log_error_errno(errno, "rm(%s): %m", instance)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1808, __func__
, "rm(%s): %m", instance) : -abs(_e); })
;
1809
1810 break;
1811
1812 case TRUNCATE_DIRECTORY:
1813 case RECURSIVE_REMOVE_PATH:
1814 /* FIXME: we probably should use dir_cleanup() here
1815 * instead of rm_rf() so that 'x' is honoured. */
1816 log_debug("rm -rf \"%s\"", instance)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1816, __func__, "rm -rf \"%s\""
, instance) : -abs(_e); })
;
1817 r = rm_rf(instance, (i->type == RECURSIVE_REMOVE_PATH ? REMOVE_ROOT|REMOVE_SUBVOLUME : 0) | REMOVE_PHYSICAL);
1818 if (r < 0 && r != -ENOENT2)
1819 return log_error_errno(r, "rm_rf(%s): %m", instance)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1819, __func__, "rm_rf(%s): %m"
, instance) : -abs(_e); })
;
1820
1821 break;
1822
1823 default:
1824 assert_not_reached("wut?")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, (
"wut?"), "../src/tmpfiles/tmpfiles.c", 1824, __PRETTY_FUNCTION__
); } while (0)
;
1825 }
1826
1827 return 0;
1828}
1829
1830static int remove_item(Item *i) {
1831 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1831
, __PRETTY_FUNCTION__); } while (0)
;
1832
1833 log_debug("Running remove action for entry %c %s", (char) i->type, i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1833, __func__, "Running remove action for entry %c %s"
, (char) i->type, i->path) : -abs(_e); })
;
1834
1835 switch (i->type) {
1836
1837 case REMOVE_PATH:
1838 case TRUNCATE_DIRECTORY:
1839 case RECURSIVE_REMOVE_PATH:
1840 return glob_item(i, remove_item_instance);
1841
1842 default:
1843 return 0;
1844 }
1845}
1846
1847static int clean_item_instance(Item *i, const char* instance) {
1848 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
1849 struct stat s, ps;
1850 bool_Bool mountpoint;
1851 usec_t cutoff, n;
1852 char timestamp[FORMAT_TIMESTAMP_MAX(3+1+10+1+8+1+6+1+6+1)];
1853
1854 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1854
, __PRETTY_FUNCTION__); } while (0)
;
1855
1856 if (!i->age_set)
1857 return 0;
1858
1859 n = now(CLOCK_REALTIME0);
1860 if (n < i->age)
1861 return 0;
1862
1863 cutoff = n - i->age;
1864
1865 d = opendir_nomod(instance);
1866 if (!d) {
1867 if (IN_SET(errno, ENOENT, ENOTDIR)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){2, 20})/sizeof(int)]; switch((*__errno_location
())) { case 2: case 20: _found = 1; break; default: break; }
_found; })
) {
1868 log_debug_errno(errno, "Directory \"%s\": %m", instance)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1868, __func__
, "Directory \"%s\": %m", instance) : -abs(_e); })
;
1869 return 0;
1870 }
1871
1872 return log_error_errno(errno, "Failed to open directory %s: %m", instance)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1872, __func__
, "Failed to open directory %s: %m", instance) : -abs(_e); })
;
1873 }
1874
1875 if (fstat(dirfd(d), &s) < 0)
1876 return log_error_errno(errno, "stat(%s) failed: %m", i->path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1876, __func__
, "stat(%s) failed: %m", i->path) : -abs(_e); })
;
1877
1878 if (!S_ISDIR(s.st_mode)((((s.st_mode)) & 0170000) == (0040000))) {
1879 log_error("%s is not a directory.", i->path)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1879, __func__, "%s is not a directory."
, i->path) : -abs(_e); })
;
1880 return -ENOTDIR20;
1881 }
1882
1883 if (fstatat(dirfd(d), "..", &ps, AT_SYMLINK_NOFOLLOW0x100) != 0)
1884 return log_error_errno(errno, "stat(%s/..) failed: %m", i->path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 1884, __func__
, "stat(%s/..) failed: %m", i->path) : -abs(_e); })
;
1885
1886 mountpoint = s.st_dev != ps.st_dev || s.st_ino == ps.st_ino;
1887
1888 log_debug("Cleanup threshold for %s \"%s\" is %s",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1891, __func__, "Cleanup threshold for %s \"%s\" is %s"
, mountpoint ? "mount point" : "directory", instance, format_timestamp_us
(timestamp, sizeof(timestamp), cutoff)) : -abs(_e); })
1889 mountpoint ? "mount point" : "directory",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1891, __func__, "Cleanup threshold for %s \"%s\" is %s"
, mountpoint ? "mount point" : "directory", instance, format_timestamp_us
(timestamp, sizeof(timestamp), cutoff)) : -abs(_e); })
1890 instance,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1891, __func__, "Cleanup threshold for %s \"%s\" is %s"
, mountpoint ? "mount point" : "directory", instance, format_timestamp_us
(timestamp, sizeof(timestamp), cutoff)) : -abs(_e); })
1891 format_timestamp_us(timestamp, sizeof(timestamp), cutoff))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1891, __func__, "Cleanup threshold for %s \"%s\" is %s"
, mountpoint ? "mount point" : "directory", instance, format_timestamp_us
(timestamp, sizeof(timestamp), cutoff)) : -abs(_e); })
;
1892
1893 return dir_cleanup(i, instance, d, &s, cutoff, s.st_dev, mountpoint,
1894 MAX_DEPTH256, i->keep_first_level);
1895}
1896
1897static int clean_item(Item *i) {
1898 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1898
, __PRETTY_FUNCTION__); } while (0)
;
1899
1900 log_debug("Running clean action for entry %c %s", (char) i->type, i->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 1900, __func__, "Running clean action for entry %c %s"
, (char) i->type, i->path) : -abs(_e); })
;
1901
1902 switch (i->type) {
1903 case CREATE_DIRECTORY:
1904 case CREATE_SUBVOLUME:
1905 case CREATE_SUBVOLUME_INHERIT_QUOTA:
1906 case CREATE_SUBVOLUME_NEW_QUOTA:
1907 case TRUNCATE_DIRECTORY:
1908 case IGNORE_PATH:
1909 case COPY_FILES:
1910 clean_item_instance(i, i->path);
1911 return 0;
1912 case EMPTY_DIRECTORY:
1913 case IGNORE_DIRECTORY_PATH:
1914 return glob_item(i, clean_item_instance);
1915 default:
1916 return 0;
1917 }
1918}
1919
1920static int process_item_array(ItemArray *array);
1921
1922static int process_item(Item *i) {
1923 int r, q, p, t = 0;
1924 _cleanup_free___attribute__((cleanup(freep))) char *prefix = NULL((void*)0);
1925
1926 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1926
, __PRETTY_FUNCTION__); } while (0)
;
1927
1928 if (i->done)
1929 return 0;
1930
1931 i->done = true1;
1932
1933 prefix = malloc(strlen(i->path) + 1);
1934 if (!prefix)
1935 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 1935, __func__)
;
1936
1937 PATH_FOREACH_PREFIX(prefix, i->path)for (char *_slash = ({ path_simplify(strcpy(prefix, i->path
), 0); (strcmp((prefix),("/")) == 0) ? ((void*)0) : strrchr(prefix
, '/'); }); _slash && ((*_slash = 0), 1); _slash = strrchr
((prefix), '/'))
{
1938 ItemArray *j;
1939
1940 j = ordered_hashmap_get(items, prefix);
1941 if (j) {
1942 int s;
1943
1944 s = process_item_array(j);
1945 if (s < 0 && t == 0)
1946 t = s;
1947 }
1948 }
1949
1950 if (chase_symlinks(i->path, NULL((void*)0), CHASE_NO_AUTOFS, NULL((void*)0)) == -EREMOTE66)
1951 return t;
1952
1953 r = arg_create ? create_item(i) : 0;
1954 q = arg_remove ? remove_item(i) : 0;
1955 p = arg_clean ? clean_item(i) : 0;
1956
1957 return t < 0 ? t :
1958 r < 0 ? r :
1959 q < 0 ? q :
1960 p;
1961}
1962
1963static int process_item_array(ItemArray *array) {
1964 unsigned n;
1965 int r = 0, k;
1966
1967 assert(array)do { if ((__builtin_expect(!!(!(array)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("array"), "../src/tmpfiles/tmpfiles.c", 1967
, __PRETTY_FUNCTION__); } while (0)
;
1968
1969 for (n = 0; n < array->count; n++) {
1970 k = process_item(array->items + n);
1971 if (k < 0 && r == 0)
1972 r = k;
1973 }
1974
1975 return r;
1976}
1977
1978static void item_free_contents(Item *i) {
1979 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 1979
, __PRETTY_FUNCTION__); } while (0)
;
1980 free(i->path);
1981 free(i->argument);
1982 strv_free(i->xattrs);
1983
1984#if HAVE_ACL1
1985 acl_free(i->acl_access);
1986 acl_free(i->acl_default);
1987#endif
1988}
1989
1990static void item_array_free(ItemArray *a) {
1991 unsigned n;
1992
1993 if (!a)
1994 return;
1995
1996 for (n = 0; n < a->count; n++)
1997 item_free_contents(a->items + n);
1998 free(a->items);
1999 free(a);
2000}
2001
2002static int item_compare(const void *a, const void *b) {
2003 const Item *x = a, *y = b;
2004
2005 /* Make sure that the ownership taking item is put first, so
2006 * that we first create the node, and then can adjust it */
2007
2008 if (takes_ownership(x->type) && !takes_ownership(y->type))
2009 return -1;
2010 if (!takes_ownership(x->type) && takes_ownership(y->type))
2011 return 1;
2012
2013 return (int) x->type - (int) y->type;
2014}
2015
2016static bool_Bool item_compatible(Item *a, Item *b) {
2017 assert(a)do { if ((__builtin_expect(!!(!(a)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("a"), "../src/tmpfiles/tmpfiles.c", 2017
, __PRETTY_FUNCTION__); } while (0)
;
2018 assert(b)do { if ((__builtin_expect(!!(!(b)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("b"), "../src/tmpfiles/tmpfiles.c", 2018
, __PRETTY_FUNCTION__); } while (0)
;
2019 assert(streq(a->path, b->path))do { if ((__builtin_expect(!!(!((strcmp((a->path),(b->path
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(a->path, b->path)"
), "../src/tmpfiles/tmpfiles.c", 2019, __PRETTY_FUNCTION__); }
while (0)
;
2020
2021 if (takes_ownership(a->type) && takes_ownership(b->type))
2022 /* check if the items are the same */
2023 return streq_ptr(a->argument, b->argument) &&
2024
2025 a->uid_set == b->uid_set &&
2026 a->uid == b->uid &&
2027
2028 a->gid_set == b->gid_set &&
2029 a->gid == b->gid &&
2030
2031 a->mode_set == b->mode_set &&
2032 a->mode == b->mode &&
2033
2034 a->age_set == b->age_set &&
2035 a->age == b->age &&
2036
2037 a->mask_perms == b->mask_perms &&
2038
2039 a->keep_first_level == b->keep_first_level &&
2040
2041 a->major_minor == b->major_minor;
2042
2043 return true1;
2044}
2045
2046static bool_Bool should_include_path(const char *path) {
2047 char **prefix;
2048
2049 STRV_FOREACH(prefix, arg_exclude_prefixes)for ((prefix) = (arg_exclude_prefixes); (prefix) && *
(prefix); (prefix)++)
2050 if (path_startswith(path, *prefix)) {
2051 log_debug("Entry \"%s\" matches exclude prefix \"%s\", skipping.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2052, __func__, "Entry \"%s\" matches exclude prefix \"%s\", skipping."
, path, *prefix) : -abs(_e); })
2052 path, *prefix)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2052, __func__, "Entry \"%s\" matches exclude prefix \"%s\", skipping."
, path, *prefix) : -abs(_e); })
;
2053 return false0;
2054 }
2055
2056 STRV_FOREACH(prefix, arg_include_prefixes)for ((prefix) = (arg_include_prefixes); (prefix) && *
(prefix); (prefix)++)
2057 if (path_startswith(path, *prefix)) {
2058 log_debug("Entry \"%s\" matches include prefix \"%s\".", path, *prefix)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2058, __func__, "Entry \"%s\" matches include prefix \"%s\"."
, path, *prefix) : -abs(_e); })
;
2059 return true1;
2060 }
2061
2062 /* no matches, so we should include this path only if we
2063 * have no whitelist at all */
2064 if (strv_isempty(arg_include_prefixes))
2065 return true1;
2066
2067 log_debug("Entry \"%s\" does not match any include prefix, skipping.", path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2067, __func__, "Entry \"%s\" does not match any include prefix, skipping."
, path) : -abs(_e); })
;
2068 return false0;
2069}
2070
2071static int specifier_expansion_from_arg(Item *i) {
2072 _cleanup_free___attribute__((cleanup(freep))) char *unescaped = NULL((void*)0), *resolved = NULL((void*)0);
2073 char **xattr;
2074 int r;
2075
2076 assert(i)do { if ((__builtin_expect(!!(!(i)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i"), "../src/tmpfiles/tmpfiles.c", 2076
, __PRETTY_FUNCTION__); } while (0)
;
2077
2078 if (i->argument == NULL((void*)0))
2079 return 0;
2080
2081 switch (i->type) {
2082 case COPY_FILES:
2083 case CREATE_SYMLINK:
2084 case CREATE_FILE:
2085 case TRUNCATE_FILE:
2086 case WRITE_FILE:
2087 r = cunescape(i->argument, 0, &unescaped);
2088 if (r < 0)
2089 return log_error_errno(r, "Failed to unescape parameter to write: %s", i->argument)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2089, __func__, "Failed to unescape parameter to write: %s"
, i->argument) : -abs(_e); })
;
2090
2091 r = specifier_printf(unescaped, specifier_table, NULL((void*)0), &resolved);
2092 if (r < 0)
2093 return r;
2094
2095 free_and_replace(i->argument, resolved)({ free(i->argument); (i->argument) = (resolved); (resolved
) = ((void*)0); 0; })
;
2096 break;
2097
2098 case SET_XATTR:
2099 case RECURSIVE_SET_XATTR:
2100 assert(i->xattrs)do { if ((__builtin_expect(!!(!(i->xattrs)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("i->xattrs"), "../src/tmpfiles/tmpfiles.c"
, 2100, __PRETTY_FUNCTION__); } while (0)
;
2101
2102 STRV_FOREACH (xattr, i->xattrs)for ((xattr) = (i->xattrs); (xattr) && *(xattr); (
xattr)++)
{
2103 r = specifier_printf(*xattr, specifier_table, NULL((void*)0), &resolved);
2104 if (r < 0)
2105 return r;
2106
2107 free_and_replace(*xattr, resolved)({ free(*xattr); (*xattr) = (resolved); (resolved) = ((void*)
0); 0; })
;
2108 }
2109 break;
2110
2111 default:
2112 break;
2113 }
2114 return 0;
2115}
2116
2117static int patch_var_run(const char *fname, unsigned line, char **path) {
2118 const char *k;
2119 char *n;
2120
2121 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/tmpfiles/tmpfiles.c", 2121
, __PRETTY_FUNCTION__); } while (0)
;
2122 assert(*path)do { if ((__builtin_expect(!!(!(*path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("*path"), "../src/tmpfiles/tmpfiles.c", 2122
, __PRETTY_FUNCTION__); } while (0)
;
2123
2124 /* Optionally rewrites lines referencing /var/run/, to use /run/ instead. Why bother? tmpfiles merges lines in
2125 * some cases and detects conflicts in others. If files/directories are specified through two equivalent lines
2126 * this is problematic as neither case will be detected. Ideally we'd detect these cases by resolving symlinks
2127 * early, but that's precisely not what we can do here as this code very likely is running very early on, at a
2128 * time where the paths in question are not available yet, or even more importantly, our own tmpfiles rules
2129 * might create the paths that are intermediary to the listed paths. We can't really cover the generic case,
2130 * but the least we can do is cover the specific case of /var/run vs. /run, as /var/run is a legacy name for
2131 * /run only, and we explicitly document that and require that on systemd systems the former is a symlink to
2132 * the latter. Moreover files below this path are by far the primary usecase for tmpfiles.d/. */
2133
2134 k = path_startswith(*path, "/var/run/");
2135 if (isempty(k)) /* Don't complain about other paths than /var/run, and not about /var/run itself either. */
2136 return 0;
2137
2138 n = strjoin("/run/", k)strjoin_real(("/run/"), k, ((void*)0));
2139 if (!n)
2140 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2140, __func__)
;
2141
2142 /* Also log about this briefly. We do so at LOG_NOTICE level, as we fixed up the situation automatically, hence
2143 * there's no immediate need for action by the user. However, in the interest of making things less confusing
2144 * to the user, let's still inform the user that these snippets should really be updated. */
2145
2146 log_notice("[%s:%u] Line references path below legacy directory /var/run/, updating %s → %s; please update the tmpfiles.d/ drop-in file accordingly.", fname, line, *path, n)({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2146, __func__, "[%s:%u] Line references path below legacy directory /var/run/, updating %s → %s; please update the tmpfiles.d/ drop-in file accordingly."
, fname, line, *path, n) : -abs(_e); })
;
2147
2148 free(*path);
2149 *path = n;
2150
2151 return 0;
2152}
2153
2154static int parse_line(const char *fname, unsigned line, const char *buffer, bool_Bool *invalid_config) {
2155
2156 _cleanup_free___attribute__((cleanup(freep))) char *action = NULL((void*)0), *mode = NULL((void*)0), *user = NULL((void*)0), *group = NULL((void*)0), *age = NULL((void*)0), *path = NULL((void*)0);
2157 _cleanup_(item_free_contents)__attribute__((cleanup(item_free_contents))) Item i = {};
2158 ItemArray *existing;
2159 OrderedHashmap *h;
2160 int r, pos;
2161 bool_Bool force = false0, boot = false0;
2162
2163 assert(fname)do { if ((__builtin_expect(!!(!(fname)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fname"), "../src/tmpfiles/tmpfiles.c", 2163
, __PRETTY_FUNCTION__); } while (0)
;
1
Assuming 'fname' is non-null
2
Taking false branch
3
Loop condition is false. Exiting loop
2164 assert(line >= 1)do { if ((__builtin_expect(!!(!(line >= 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("line >= 1"), "../src/tmpfiles/tmpfiles.c"
, 2164, __PRETTY_FUNCTION__); } while (0)
;
4
Assuming 'line' is >= 1
5
Taking false branch
6
Loop condition is false. Exiting loop
2165 assert(buffer)do { if ((__builtin_expect(!!(!(buffer)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("buffer"), "../src/tmpfiles/tmpfiles.c",
2165, __PRETTY_FUNCTION__); } while (0)
;
7
Assuming 'buffer' is non-null
8
Taking false branch
9
Loop condition is false. Exiting loop
2166
2167 r = extract_many_words(
2168 &buffer,
2169 NULL((void*)0),
2170 EXTRACT_QUOTES,
2171 &action,
2172 &path,
2173 &mode,
2174 &user,
2175 &group,
2176 &age,
2177 NULL((void*)0));
2178 if (r < 0) {
10
Assuming 'r' is >= 0
11
Taking false branch
2179 if (IN_SET(r, -EINVAL, -EBADSLT)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-22, -57})/sizeof(int)]; switch(r) { case
-22: case -57: _found = 1; break; default: break; } _found; }
)
)
2180 /* invalid quoting and such or an unknown specifier */
2181 *invalid_config = true1;
2182 return log_error_errno(r, "[%s:%u] Failed to parse line: %m", fname, line)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2182, __func__, "[%s:%u] Failed to parse line: %m"
, fname, line) : -abs(_e); })
;
2183 } else if (r < 2) {
12
Assuming 'r' is >= 2
13
Taking false branch
2184 *invalid_config = true1;
2185 log_error("[%s:%u] Syntax error.", fname, line)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2185, __func__, "[%s:%u] Syntax error."
, fname, line) : -abs(_e); })
;
2186 return -EIO5;
2187 }
2188
2189 if (!isempty(buffer) && !streq(buffer, "-")(strcmp((buffer),("-")) == 0)) {
14
Assuming the condition is false
15
Taking true branch
2190 i.argument = strdup(buffer);
16
Memory is allocated
2191 if (!i.argument)
17
Assuming field 'argument' is non-null
18
Taking false branch
2192 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2192, __func__)
;
2193 }
2194
2195 if (isempty(action)) {
19
Taking true branch
2196 *invalid_config = true1;
20
Potential leak of memory pointed to by 'i.argument'
2197 log_error("[%s:%u] Command too short '%s'.", fname, line, action)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2197, __func__, "[%s:%u] Command too short '%s'."
, fname, line, action) : -abs(_e); })
;
2198 return -EINVAL22;
2199 }
2200
2201 for (pos = 1; action[pos]; pos++) {
2202 if (action[pos] == '!' && !boot)
2203 boot = true1;
2204 else if (action[pos] == '+' && !force)
2205 force = true1;
2206 else {
2207 *invalid_config = true1;
2208 log_error("[%s:%u] Unknown modifiers in command '%s'",({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2209, __func__, "[%s:%u] Unknown modifiers in command '%s'"
, fname, line, action) : -abs(_e); })
2209 fname, line, action)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2209, __func__, "[%s:%u] Unknown modifiers in command '%s'"
, fname, line, action) : -abs(_e); })
;
2210 return -EINVAL22;
2211 }
2212 }
2213
2214 if (boot && !arg_boot) {
2215 log_debug("Ignoring entry %s \"%s\" because --boot is not specified.",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2216, __func__, "Ignoring entry %s \"%s\" because --boot is not specified."
, action, path) : -abs(_e); })
2216 action, path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2216, __func__, "Ignoring entry %s \"%s\" because --boot is not specified."
, action, path) : -abs(_e); })
;
2217 return 0;
2218 }
2219
2220 i.type = action[0];
2221 i.force = force;
2222
2223 r = specifier_printf(path, specifier_table, NULL((void*)0), &i.path);
2224 if (r == -ENXIO6)
2225 return log_unresolvable_specifier(fname, line);
2226 if (r < 0) {
2227 if (IN_SET(r, -EINVAL, -EBADSLT)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-22, -57})/sizeof(int)]; switch(r) { case
-22: case -57: _found = 1; break; default: break; } _found; }
)
)
2228 *invalid_config = true1;
2229 return log_error_errno(r, "[%s:%u] Failed to replace specifiers: %s", fname, line, path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2229, __func__, "[%s:%u] Failed to replace specifiers: %s"
, fname, line, path) : -abs(_e); })
;
2230 }
2231
2232 r = patch_var_run(fname, line, &i.path);
2233 if (r < 0)
2234 return r;
2235
2236 switch (i.type) {
2237
2238 case CREATE_DIRECTORY:
2239 case CREATE_SUBVOLUME:
2240 case CREATE_SUBVOLUME_INHERIT_QUOTA:
2241 case CREATE_SUBVOLUME_NEW_QUOTA:
2242 case EMPTY_DIRECTORY:
2243 case TRUNCATE_DIRECTORY:
2244 case CREATE_FIFO:
2245 case IGNORE_PATH:
2246 case IGNORE_DIRECTORY_PATH:
2247 case REMOVE_PATH:
2248 case RECURSIVE_REMOVE_PATH:
2249 case ADJUST_MODE:
2250 case RELABEL_PATH:
2251 case RECURSIVE_RELABEL_PATH:
2252 if (i.argument)
2253 log_warning("[%s:%u] %c lines don't take argument fields, ignoring.", fname, line, i.type)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2253, __func__, "[%s:%u] %c lines don't take argument fields, ignoring."
, fname, line, i.type) : -abs(_e); })
;
2254
2255 break;
2256
2257 case CREATE_FILE:
2258 case TRUNCATE_FILE:
2259 break;
2260
2261 case CREATE_SYMLINK:
2262 if (!i.argument) {
2263 i.argument = strappend("/usr/share/factory/", i.path);
2264 if (!i.argument)
2265 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2265, __func__)
;
2266 }
2267 break;
2268
2269 case WRITE_FILE:
2270 if (!i.argument) {
2271 *invalid_config = true1;
2272 log_error("[%s:%u] Write file requires argument.", fname, line)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2272, __func__, "[%s:%u] Write file requires argument."
, fname, line) : -abs(_e); })
;
2273 return -EBADMSG74;
2274 }
2275 break;
2276
2277 case COPY_FILES:
2278 if (!i.argument) {
2279 i.argument = strappend("/usr/share/factory/", i.path);
2280 if (!i.argument)
2281 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2281, __func__)
;
2282 } else if (!path_is_absolute(i.argument)) {
2283 *invalid_config = true1;
2284 log_error("[%s:%u] Source path is not absolute.", fname, line)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2284, __func__, "[%s:%u] Source path is not absolute."
, fname, line) : -abs(_e); })
;
2285 return -EBADMSG74;
2286 }
2287
2288 path_simplify(i.argument, false0);
2289 break;
2290
2291 case CREATE_CHAR_DEVICE:
2292 case CREATE_BLOCK_DEVICE: {
2293 unsigned major, minor;
2294
2295 if (!i.argument) {
2296 *invalid_config = true1;
2297 log_error("[%s:%u] Device file requires argument.", fname, line)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2297, __func__, "[%s:%u] Device file requires argument."
, fname, line) : -abs(_e); })
;
2298 return -EBADMSG74;
2299 }
2300
2301 if (sscanf(i.argument, "%u:%u", &major, &minor) != 2) {
2302 *invalid_config = true1;
2303 log_error("[%s:%u] Can't parse device file major/minor '%s'.", fname, line, i.argument)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2303, __func__, "[%s:%u] Can't parse device file major/minor '%s'."
, fname, line, i.argument) : -abs(_e); })
;
2304 return -EBADMSG74;
2305 }
2306
2307 i.major_minor = makedev(major, minor)gnu_dev_makedev (major, minor);
2308 break;
2309 }
2310
2311 case SET_XATTR:
2312 case RECURSIVE_SET_XATTR:
2313 if (!i.argument) {
2314 *invalid_config = true1;
2315 log_error("[%s:%u] Set extended attribute requires argument.", fname, line)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2315, __func__, "[%s:%u] Set extended attribute requires argument."
, fname, line) : -abs(_e); })
;
2316 return -EBADMSG74;
2317 }
2318 r = parse_xattrs_from_arg(&i);
2319 if (r < 0)
2320 return r;
2321 break;
2322
2323 case SET_ACL:
2324 case RECURSIVE_SET_ACL:
2325 if (!i.argument) {
2326 *invalid_config = true1;
2327 log_error("[%s:%u] Set ACLs requires argument.", fname, line)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2327, __func__, "[%s:%u] Set ACLs requires argument."
, fname, line) : -abs(_e); })
;
2328 return -EBADMSG74;
2329 }
2330 r = parse_acls_from_arg(&i);
2331 if (r < 0)
2332 return r;
2333 break;
2334
2335 case SET_ATTRIBUTE:
2336 case RECURSIVE_SET_ATTRIBUTE:
2337 if (!i.argument) {
2338 *invalid_config = true1;
2339 log_error("[%s:%u] Set file attribute requires argument.", fname, line)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2339, __func__, "[%s:%u] Set file attribute requires argument."
, fname, line) : -abs(_e); })
;
2340 return -EBADMSG74;
2341 }
2342 r = parse_attribute_from_arg(&i);
2343 if (IN_SET(r, -EINVAL, -EBADSLT)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-22, -57})/sizeof(int)]; switch(r) { case
-22: case -57: _found = 1; break; default: break; } _found; }
)
)
2344 *invalid_config = true1;
2345 if (r < 0)
2346 return r;
2347 break;
2348
2349 default:
2350 log_error("[%s:%u] Unknown command type '%c'.", fname, line, (char) i.type)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2350, __func__, "[%s:%u] Unknown command type '%c'."
, fname, line, (char) i.type) : -abs(_e); })
;
2351 *invalid_config = true1;
2352 return -EBADMSG74;
2353 }
2354
2355 if (!path_is_absolute(i.path)) {
2356 log_error("[%s:%u] Path '%s' not absolute.", fname, line, i.path)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2356, __func__, "[%s:%u] Path '%s' not absolute."
, fname, line, i.path) : -abs(_e); })
;
2357 *invalid_config = true1;
2358 return -EBADMSG74;
2359 }
2360
2361 path_simplify(i.path, false0);
2362
2363 if (!should_include_path(i.path))
2364 return 0;
2365
2366 r = specifier_expansion_from_arg(&i);
2367 if (r == -ENXIO6)
2368 return log_unresolvable_specifier(fname, line);
2369 if (r < 0) {
2370 if (IN_SET(r, -EINVAL, -EBADSLT)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-22, -57})/sizeof(int)]; switch(r) { case
-22: case -57: _found = 1; break; default: break; } _found; }
)
)
2371 *invalid_config = true1;
2372 return log_error_errno(r, "[%s:%u] Failed to substitute specifiers in argument: %m",({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2373, __func__, "[%s:%u] Failed to substitute specifiers in argument: %m"
, fname, line) : -abs(_e); })
2373 fname, line)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2373, __func__, "[%s:%u] Failed to substitute specifiers in argument: %m"
, fname, line) : -abs(_e); })
;
2374 }
2375
2376 if (arg_root) {
2377 char *p;
2378
2379 p = prefix_root(arg_root, i.path);
2380 if (!p)
2381 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2381, __func__)
;
2382
2383 free(i.path);
2384 i.path = p;
2385 }
2386
2387 if (!isempty(user) && !streq(user, "-")(strcmp((user),("-")) == 0)) {
2388 const char *u = user;
2389
2390 r = get_user_creds(&u, &i.uid, NULL((void*)0), NULL((void*)0), NULL((void*)0));
2391 if (r < 0) {
2392 *invalid_config = true1;
2393 return log_error_errno(r, "[%s:%u] Unknown user '%s'.", fname, line, user)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2393, __func__, "[%s:%u] Unknown user '%s'."
, fname, line, user) : -abs(_e); })
;
2394 }
2395
2396 i.uid_set = true1;
2397 }
2398
2399 if (!isempty(group) && !streq(group, "-")(strcmp((group),("-")) == 0)) {
2400 const char *g = group;
2401
2402 r = get_group_creds(&g, &i.gid);
2403 if (r < 0) {
2404 *invalid_config = true1;
2405 log_error("[%s:%u] Unknown group '%s'.", fname, line, group)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2405, __func__, "[%s:%u] Unknown group '%s'."
, fname, line, group) : -abs(_e); })
;
2406 return r;
2407 }
2408
2409 i.gid_set = true1;
2410 }
2411
2412 if (!isempty(mode) && !streq(mode, "-")(strcmp((mode),("-")) == 0)) {
2413 const char *mm = mode;
2414 unsigned m;
2415
2416 if (*mm == '~') {
2417 i.mask_perms = true1;
2418 mm++;
2419 }
2420
2421 if (parse_mode(mm, &m) < 0) {
2422 *invalid_config = true1;
2423 log_error("[%s:%u] Invalid mode '%s'.", fname, line, mode)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2423, __func__, "[%s:%u] Invalid mode '%s'."
, fname, line, mode) : -abs(_e); })
;
2424 return -EBADMSG74;
2425 }
2426
2427 i.mode = m;
2428 i.mode_set = true1;
2429 } else
2430 i.mode = IN_SET(i.type, CREATE_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME
, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA}
)/sizeof(int)]; switch(i.type) { case CREATE_DIRECTORY: case TRUNCATE_DIRECTORY
: case CREATE_SUBVOLUME: case CREATE_SUBVOLUME_INHERIT_QUOTA:
case CREATE_SUBVOLUME_NEW_QUOTA: _found = 1; break; default:
break; } _found; })
? 0755 : 0644;
2431
2432 if (!isempty(age) && !streq(age, "-")(strcmp((age),("-")) == 0)) {
2433 const char *a = age;
2434
2435 if (*a == '~') {
2436 i.keep_first_level = true1;
2437 a++;
2438 }
2439
2440 if (parse_sec(a, &i.age) < 0) {
2441 *invalid_config = true1;
2442 log_error("[%s:%u] Invalid age '%s'.", fname, line, age)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2442, __func__, "[%s:%u] Invalid age '%s'."
, fname, line, age) : -abs(_e); })
;
2443 return -EBADMSG74;
2444 }
2445
2446 i.age_set = true1;
2447 }
2448
2449 h = needs_glob(i.type) ? globs : items;
2450
2451 existing = ordered_hashmap_get(h, i.path);
2452 if (existing) {
2453 unsigned n;
2454
2455 for (n = 0; n < existing->count; n++) {
2456 if (!item_compatible(existing->items + n, &i)) {
2457 log_notice("[%s:%u] Duplicate line for path \"%s\", ignoring.",({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2458, __func__, "[%s:%u] Duplicate line for path \"%s\", ignoring."
, fname, line, i.path) : -abs(_e); })
2458 fname, line, i.path)({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2458, __func__, "[%s:%u] Duplicate line for path \"%s\", ignoring."
, fname, line, i.path) : -abs(_e); })
;
2459 return 0;
2460 }
2461 }
2462 } else {
2463 existing = new0(ItemArray, 1)((ItemArray*) calloc((1), sizeof(ItemArray)));
2464 if (!existing)
2465 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2465, __func__)
;
2466
2467 r = ordered_hashmap_put(h, i.path, existing);
2468 if (r < 0)
2469 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2469, __func__)
;
2470 }
2471
2472 if (!GREEDY_REALLOC(existing->items, existing->size, existing->count + 1)greedy_realloc((void**) &(existing->items), &(existing
->size), (existing->count + 1), sizeof((existing->items
)[0]))
)
2473 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2473, __func__)
;
2474
2475 memcpy(existing->items + existing->count++, &i, sizeof(i));
2476
2477 /* Sort item array, to enforce stable ordering of application */
2478 qsort_safe(existing->items, existing->count, sizeof(Item), item_compare);
2479
2480 zero(i)(({ size_t _l_ = (sizeof(i)); void *_x_ = (&(i)); _l_ == 0
? _x_ : memset(_x_, 0, _l_); }))
;
2481 return 0;
2482}
2483
2484static int cat_config(char **config_dirs, char **args) {
2485 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **files = NULL((void*)0);
2486 int r;
2487
2488 r = conf_files_list_with_replacement(arg_root, config_dirs, arg_replace, &files, NULL((void*)0));
2489 if (r < 0)
2490 return r;
2491
2492 return cat_files(NULL((void*)0), files, 0);
2493}
2494
2495static void help(void) {
2496 printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
2497 "Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
2498 " -h --help Show this help\n"
2499 " --user Execute user configuration\n"
2500 " --version Show package version\n"
2501 " --cat-config Show configuration files\n"
2502 " --create Create marked files/directories\n"
2503 " --clean Clean up marked directories\n"
2504 " --remove Remove marked files/directories\n"
2505 " --boot Execute actions only safe at boot\n"
2506 " --prefix=PATH Only apply rules with the specified prefix\n"
2507 " --exclude-prefix=PATH Ignore rules with the specified prefix\n"
2508 " --root=PATH Operate on an alternate filesystem root\n"
2509 " --replace=PATH Treat arguments as replacement for PATH\n"
2510 " --no-pager Do not pipe output into a pager\n"
2511 , program_invocation_short_name);
2512}
2513
2514static int parse_argv(int argc, char *argv[]) {
2515
2516 enum {
2517 ARG_VERSION = 0x100,
2518 ARG_CAT_CONFIG,
2519 ARG_USER,
2520 ARG_CREATE,
2521 ARG_CLEAN,
2522 ARG_REMOVE,
2523 ARG_BOOT,
2524 ARG_PREFIX,
2525 ARG_EXCLUDE_PREFIX,
2526 ARG_ROOT,
2527 ARG_REPLACE,
2528 ARG_NO_PAGER,
2529 };
2530
2531 static const struct option options[] = {
2532 { "help", no_argument0, NULL((void*)0), 'h' },
2533 { "user", no_argument0, NULL((void*)0), ARG_USER },
2534 { "version", no_argument0, NULL((void*)0), ARG_VERSION },
2535 { "cat-config", no_argument0, NULL((void*)0), ARG_CAT_CONFIG },
2536 { "create", no_argument0, NULL((void*)0), ARG_CREATE },
2537 { "clean", no_argument0, NULL((void*)0), ARG_CLEAN },
2538 { "remove", no_argument0, NULL((void*)0), ARG_REMOVE },
2539 { "boot", no_argument0, NULL((void*)0), ARG_BOOT },
2540 { "prefix", required_argument1, NULL((void*)0), ARG_PREFIX },
2541 { "exclude-prefix", required_argument1, NULL((void*)0), ARG_EXCLUDE_PREFIX },
2542 { "root", required_argument1, NULL((void*)0), ARG_ROOT },
2543 { "replace", required_argument1, NULL((void*)0), ARG_REPLACE },
2544 { "no-pager", no_argument0, NULL((void*)0), ARG_NO_PAGER },
2545 {}
2546 };
2547
2548 int c, r;
2549
2550 assert(argc >= 0)do { if ((__builtin_expect(!!(!(argc >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("argc >= 0"), "../src/tmpfiles/tmpfiles.c"
, 2550, __PRETTY_FUNCTION__); } while (0)
;
2551 assert(argv)do { if ((__builtin_expect(!!(!(argv)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("argv"), "../src/tmpfiles/tmpfiles.c", 2551
, __PRETTY_FUNCTION__); } while (0)
;
2552
2553 while ((c = getopt_long(argc, argv, "h", options, NULL((void*)0))) >= 0)
2554
2555 switch (c) {
2556
2557 case 'h':
2558 help();
2559 return 0;
2560
2561 case ARG_VERSION:
2562 return version();
2563
2564 case ARG_CAT_CONFIG:
2565 arg_cat_config = true1;
2566 break;
2567
2568 case ARG_USER:
2569 arg_user = true1;
2570 break;
2571
2572 case ARG_CREATE:
2573 arg_create = true1;
2574 break;
2575
2576 case ARG_CLEAN:
2577 arg_clean = true1;
2578 break;
2579
2580 case ARG_REMOVE:
2581 arg_remove = true1;
2582 break;
2583
2584 case ARG_BOOT:
2585 arg_boot = true1;
2586 break;
2587
2588 case ARG_PREFIX:
2589 if (strv_push(&arg_include_prefixes, optarg) < 0)
2590 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2590, __func__)
;
2591 break;
2592
2593 case ARG_EXCLUDE_PREFIX:
2594 if (strv_push(&arg_exclude_prefixes, optarg) < 0)
2595 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2595, __func__)
;
2596 break;
2597
2598 case ARG_ROOT:
2599 r = parse_path_argument_and_warn(optarg, true1, &arg_root);
2600 if (r < 0)
2601 return r;
2602 break;
2603
2604 case ARG_REPLACE:
2605 if (!path_is_absolute(optarg) ||
2606 !endswith(optarg, ".conf")) {
2607 log_error("The argument to --replace= must an absolute path to a config file")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2607, __func__, "The argument to --replace= must an absolute path to a config file"
) : -abs(_e); })
;
2608 return -EINVAL22;
2609 }
2610
2611 arg_replace = optarg;
2612 break;
2613
2614 case ARG_NO_PAGER:
2615 arg_no_pager = true1;
2616 break;
2617
2618 case '?':
2619 return -EINVAL22;
2620
2621 default:
2622 assert_not_reached("Unhandled option")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, (
"Unhandled option"), "../src/tmpfiles/tmpfiles.c", 2622, __PRETTY_FUNCTION__
); } while (0)
;
2623 }
2624
2625 if (!arg_clean && !arg_create && !arg_remove && !arg_cat_config) {
2626 log_error("You need to specify at least one of --clean, --create or --remove.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2626, __func__, "You need to specify at least one of --clean, --create or --remove."
) : -abs(_e); })
;
2627 return -EINVAL22;
2628 }
2629
2630 if (arg_replace && arg_cat_config) {
2631 log_error("Option --replace= is not supported with --cat-config")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2631, __func__, "Option --replace= is not supported with --cat-config"
) : -abs(_e); })
;
2632 return -EINVAL22;
2633 }
2634
2635 if (arg_replace && optind >= argc) {
2636 log_error("When --replace= is given, some configuration items must be specified")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2636, __func__, "When --replace= is given, some configuration items must be specified"
) : -abs(_e); })
;
2637 return -EINVAL22;
2638 }
2639
2640 return 1;
2641}
2642
2643static int read_config_file(char **config_dirs, const char *fn, bool_Bool ignore_enoent, bool_Bool *invalid_config) {
2644 _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *_f = NULL((void*)0);
2645 FILE *f;
2646 char line[LINE_MAX2048];
2647 Iterator iterator;
2648 unsigned v = 0;
2649 Item *i;
2650 int r = 0;
2651
2652 assert(fn)do { if ((__builtin_expect(!!(!(fn)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fn"), "../src/tmpfiles/tmpfiles.c", 2652
, __PRETTY_FUNCTION__); } while (0)
;
2653
2654 if (streq(fn, "-")(strcmp((fn),("-")) == 0)) {
2655 log_debug("Reading config from stdin…")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2655, __func__, "Reading config from stdin…"
) : -abs(_e); })
;
2656 fn = "<stdin>";
2657 f = stdinstdin;
2658 } else {
2659 r = search_and_fopen(fn, "re", arg_root, (const char**) config_dirs, &_f);
2660 if (r < 0) {
2661 if (ignore_enoent && r == -ENOENT2) {
2662 log_debug_errno(r, "Failed to open \"%s\", ignoring: %m", fn)({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2662, __func__, "Failed to open \"%s\", ignoring: %m"
, fn) : -abs(_e); })
;
2663 return 0;
2664 }
2665
2666 return log_error_errno(r, "Failed to open '%s': %m", fn)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2666, __func__, "Failed to open '%s': %m"
, fn) : -abs(_e); })
;
2667 }
2668 log_debug("Reading config file \"%s\"…", fn)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2668, __func__, "Reading config file \"%s\"…"
, fn) : -abs(_e); })
;
2669 f = _f;
2670 }
2671
2672 FOREACH_LINE(line, f, break)for (;;) if (!fgets(line, sizeof(line), f)) { if (ferror(f)) {
break; } break; } else
{
2673 char *l;
2674 int k;
2675 bool_Bool invalid_line = false0;
2676
2677 v++;
2678
2679 l = strstrip(line);
2680 if (IN_SET(*l, 0, '#')({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){0, '#'})/sizeof(int)]; switch(*l) { case
0: case '#': _found = 1; break; default: break; } _found; })
)
2681 continue;
2682
2683 k = parse_line(fn, v, l, &invalid_line);
2684 if (k < 0) {
2685 if (invalid_line)
2686 /* Allow reporting with a special code if the caller requested this */
2687 *invalid_config = true1;
2688 else if (r == 0)
2689 /* The first error becomes our return value */
2690 r = k;
2691 }
2692 }
2693
2694 /* we have to determine age parameter for each entry of type X */
2695 ORDERED_HASHMAP_FOREACH(i, globs, iterator)for ((iterator) = ((Iterator) { .idx = ((2147483647 *2U +1U) -
1), .next_key = ((void*)0) }); ordered_hashmap_iterate((globs
), &(iterator), (void**)&(i), ((void*)0)); )
{
2696 Iterator iter;
2697 Item *j, *candidate_item = NULL((void*)0);
2698
2699 if (i->type != IGNORE_DIRECTORY_PATH)
2700 continue;
2701
2702 ORDERED_HASHMAP_FOREACH(j, items, iter)for ((iter) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1)
, .next_key = ((void*)0) }); ordered_hashmap_iterate((items),
&(iter), (void**)&(j), ((void*)0)); )
{
2703 if (!IN_SET(j->type, CREATE_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){CREATE_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME
, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA}
)/sizeof(int)]; switch(j->type) { case CREATE_DIRECTORY: case
TRUNCATE_DIRECTORY: case CREATE_SUBVOLUME: case CREATE_SUBVOLUME_INHERIT_QUOTA
: case CREATE_SUBVOLUME_NEW_QUOTA: _found = 1; break; default
: break; } _found; })
)
2704 continue;
2705
2706 if (path_equal(j->path, i->path)) {
2707 candidate_item = j;
2708 break;
2709 }
2710
2711 if ((!candidate_item && path_startswith(i->path, j->path)) ||
2712 (candidate_item && path_startswith(j->path, candidate_item->path) && (fnmatch(i->path, j->path, FNM_PATHNAME(1 << 0) | FNM_PERIOD(1 << 2)) == 0)))
2713 candidate_item = j;
2714 }
2715
2716 if (candidate_item && candidate_item->age_set) {
2717 i->age = candidate_item->age;
2718 i->age_set = true1;
2719 }
2720 }
2721
2722 if (ferror(f)) {
2723 log_error_errno(errno, "Failed to read from file %s: %m", fn)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/tmpfiles/tmpfiles.c", 2723, __func__
, "Failed to read from file %s: %m", fn) : -abs(_e); })
;
2724 if (r == 0)
2725 r = -EIO5;
2726 }
2727
2728 return r;
2729}
2730
2731static int parse_arguments(char **config_dirs, char **args, bool_Bool *invalid_config) {
2732 char **arg;
2733 int r;
2734
2735 STRV_FOREACH(arg, args)for ((arg) = (args); (arg) && *(arg); (arg)++) {
2736 r = read_config_file(config_dirs, *arg, false0, invalid_config);
2737 if (r < 0)
2738 return r;
2739 }
2740
2741 return 0;
2742}
2743
2744static int read_config_files(char **config_dirs, char **args, bool_Bool *invalid_config) {
2745 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **files = NULL((void*)0);
2746 _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0);
2747 char **f;
2748 int r;
2749
2750 r = conf_files_list_with_replacement(arg_root, config_dirs, arg_replace, &files, &p);
2751 if (r < 0)
2752 return r;
2753
2754 STRV_FOREACH(f, files)for ((f) = (files); (f) && *(f); (f)++)
2755 if (p && path_equal(*f, p)) {
2756 log_debug("Parsing arguments at position \"%s\"…", *f)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2756, __func__, "Parsing arguments at position \"%s\"…"
, *f) : -abs(_e); })
;
2757
2758 r = parse_arguments(config_dirs, args, invalid_config);
2759 if (r < 0)
2760 return r;
2761 } else
2762 /* Just warn, ignore result otherwise.
2763 * read_config_file() has some debug output, so no need to print anything. */
2764 (void) read_config_file(config_dirs, *f, true1, invalid_config);
2765
2766 return 0;
2767}
2768
2769int main(int argc, char *argv[]) {
2770 int r, k, r_process = 0;
2771 ItemArray *a;
2772 Iterator iterator;
2773 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **config_dirs = NULL((void*)0);
2774 bool_Bool invalid_config = false0;
2775
2776 r = parse_argv(argc, argv);
2777 if (r <= 0)
2778 goto finish;
2779
2780 log_set_target(LOG_TARGET_AUTO);
2781 log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD);
2782 log_open();
2783
2784 if (arg_user) {
2785 r = user_config_paths(&config_dirs);
2786 if (r < 0) {
2787 log_error_errno(r, "Failed to initialize configuration directory list: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2787, __func__, "Failed to initialize configuration directory list: %m"
) : -abs(_e); })
;
2788 goto finish;
2789 }
2790 } else {
2791 config_dirs = strv_split_nulstr(CONF_PATHS_NULSTR("tmpfiles.d")"/etc/" "tmpfiles.d" "\0" "/run/" "tmpfiles.d" "\0" "/usr/local/lib/"
"tmpfiles.d" "\0" "/usr/lib/" "tmpfiles.d" "\0"
);
2792 if (!config_dirs) {
2793 r = log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2793, __func__)
;
2794 goto finish;
2795 }
2796 }
2797
2798 if (DEBUG_LOGGING(__builtin_expect(!!(log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= 7),0))
) {
2799 _cleanup_free___attribute__((cleanup(freep))) char *t = NULL((void*)0);
2800
2801 t = strv_join(config_dirs, "\n\t");
2802 if (t)
2803 log_debug("Looking for configuration files in (higher priority first):\n\t%s", t)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/tmpfiles/tmpfiles.c", 2803, __func__, "Looking for configuration files in (higher priority first):\n\t%s"
, t) : -abs(_e); })
;
2804 }
2805
2806 if (arg_cat_config) {
2807 (void) pager_open(arg_no_pager, false0);
2808
2809 r = cat_config(config_dirs, argv + optind);
2810 goto finish;
2811 }
2812
2813 umask(0022);
2814
2815 mac_selinux_init();
2816
2817 items = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
2818 globs = ordered_hashmap_new(&string_hash_ops)internal_ordered_hashmap_new(&string_hash_ops );
2819
2820 if (!items || !globs) {
2821 r = log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/tmpfiles/tmpfiles.c"
, 2821, __func__)
;
2822 goto finish;
2823 }
2824
2825 /* If command line arguments are specified along with --replace, read all
2826 * configuration files and insert the positional arguments at the specified
2827 * place. Otherwise, if command line arguments are specified, execute just
2828 * them, and finally, without --replace= or any positional arguments, just
2829 * read configuration and execute it.
2830 */
2831 if (arg_replace || optind >= argc)
2832 r = read_config_files(config_dirs, argv + optind, &invalid_config);
2833 else
2834 r = parse_arguments(config_dirs, argv + optind, &invalid_config);
2835 if (r < 0)
2836 goto finish;
2837
2838 /* The non-globbing ones usually create things, hence we apply
2839 * them first */
2840 ORDERED_HASHMAP_FOREACH(a, items, iterator)for ((iterator) = ((Iterator) { .idx = ((2147483647 *2U +1U) -
1), .next_key = ((void*)0) }); ordered_hashmap_iterate((items
), &(iterator), (void**)&(a), ((void*)0)); )
{
2841 k = process_item_array(a);
2842 if (k < 0 && r_process == 0)
2843 r_process = k;
2844 }
2845
2846 /* The globbing ones usually alter things, hence we apply them
2847 * second. */
2848 ORDERED_HASHMAP_FOREACH(a, globs, iterator)for ((iterator) = ((Iterator) { .idx = ((2147483647 *2U +1U) -
1), .next_key = ((void*)0) }); ordered_hashmap_iterate((globs
), &(iterator), (void**)&(a), ((void*)0)); )
{
2849 k = process_item_array(a);
2850 if (k < 0 && r_process == 0)
2851 r_process = k;
2852 }
2853
2854finish:
2855 pager_close();
2856
2857 ordered_hashmap_free_with_destructor(items, item_array_free)({ ({ void *_item; while ((_item = ordered_hashmap_steal_first
(items))) item_array_free(_item); }); ordered_hashmap_free(items
); })
;
2858 ordered_hashmap_free_with_destructor(globs, item_array_free)({ ({ void *_item; while ((_item = ordered_hashmap_steal_first
(globs))) item_array_free(_item); }); ordered_hashmap_free(globs
); })
;
2859
2860 free(arg_include_prefixes);
2861 free(arg_exclude_prefixes);
2862 free(arg_root);
2863
2864 set_free_free(unix_sockets);
2865
2866 mac_selinux_finish();
2867
2868 if (r < 0 || ERRNO_IS_RESOURCE(-r_process)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){12, 24, 23})/sizeof(int)]; switch(-r_process
) { case 12: case 24: case 23: _found = 1; break; default: break
; } _found; })
)
2869 return EXIT_FAILURE1;
2870 else if (invalid_config)
2871 return EX_DATAERR65;
2872 else if (r_process < 0)
2873 return EX_CANTCREAT73;
2874 else
2875 return EXIT_SUCCESS0;
2876}