Bug Summary

File:build-scan/../src/mount/mount-tool.c
Warning:line 1268, column 13
Null pointer passed to 1st parameter expecting 'nonnull'

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 mount-tool.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-mount.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/mount/mount-tool.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <getopt.h>
4
5#include "libudev.h"
6#include "sd-bus.h"
7
8#include "bus-error.h"
9#include "bus-unit-util.h"
10#include "bus-util.h"
11#include "dirent-util.h"
12#include "escape.h"
13#include "fd-util.h"
14#include "fileio.h"
15#include "fs-util.h"
16#include "fstab-util.h"
17#include "mount-util.h"
18#include "pager.h"
19#include "parse-util.h"
20#include "path-util.h"
21#include "spawn-polkit-agent.h"
22#include "stat-util.h"
23#include "strv.h"
24#include "udev-util.h"
25#include "unit-def.h"
26#include "unit-name.h"
27#include "user-util.h"
28#include "terminal-util.h"
29
30enum {
31 ACTION_DEFAULT,
32 ACTION_MOUNT,
33 ACTION_AUTOMOUNT,
34 ACTION_UMOUNT,
35 ACTION_LIST,
36} arg_action = ACTION_DEFAULT;
37
38static bool_Bool arg_no_block = false0;
39static bool_Bool arg_no_pager = false0;
40static bool_Bool arg_ask_password = true1;
41static bool_Bool arg_quiet = false0;
42static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
43static bool_Bool arg_user = false0;
44static const char *arg_host = NULL((void*)0);
45static bool_Bool arg_discover = false0;
46static char *arg_mount_what = NULL((void*)0);
47static char *arg_mount_where = NULL((void*)0);
48static char *arg_mount_type = NULL((void*)0);
49static char *arg_mount_options = NULL((void*)0);
50static char *arg_description = NULL((void*)0);
51static char **arg_property = NULL((void*)0);
52static usec_t arg_timeout_idle = USEC_INFINITY((usec_t) -1);
53static bool_Bool arg_timeout_idle_set = false0;
54static char **arg_automount_property = NULL((void*)0);
55static int arg_bind_device = -1;
56static uid_t arg_uid = UID_INVALID((uid_t) -1);
57static gid_t arg_gid = GID_INVALID((gid_t) -1);
58static bool_Bool arg_fsck = true1;
59static bool_Bool arg_aggressive_gc = false0;
60
61static void help(void) {
62 printf("systemd-mount [OPTIONS...] WHAT [WHERE]\n"
63 "systemd-mount [OPTIONS...] --list\n"
64 "%s [OPTIONS...] %sWHAT|WHERE...\n\n"
65 "Establish a mount or auto-mount point transiently.\n\n"
66 " -h --help Show this help\n"
67 " --version Show package version\n"
68 " --no-block Do not wait until operation finished\n"
69 " --no-pager Do not pipe output into a pager\n"
70 " --no-ask-password Do not prompt for password\n"
71 " -q --quiet Suppress information messages during runtime\n"
72 " --user Run as user unit\n"
73 " -H --host=[USER@]HOST Operate on remote host\n"
74 " -M --machine=CONTAINER Operate on local container\n"
75 " --discover Discover mount device metadata\n"
76 " -t --type=TYPE File system type\n"
77 " -o --options=OPTIONS Mount options\n"
78 " --owner=USER Add uid= and gid= options for USER\n"
79 " --fsck=no Don't run file system check before mount\n"
80 " --description=TEXT Description for unit\n"
81 " -p --property=NAME=VALUE Set mount unit property\n"
82 " -A --automount=BOOL Create an auto-mount point\n"
83 " --timeout-idle-sec=SEC Specify automount idle timeout\n"
84 " --automount-property=NAME=VALUE\n"
85 " Set automount unit property\n"
86 " --bind-device Bind automount unit to device\n"
87 " --list List mountable block devices\n"
88 " -u --umount Unmount mount points\n"
89 " -G --collect Unload unit after it stopped, even when failed\n",
90 program_invocation_short_name,
91 streq(program_invocation_short_name, "systemd-umount")(strcmp((program_invocation_short_name),("systemd-umount")) ==
0)
? "" : "--umount ");
92}
93
94static int parse_argv(int argc, char *argv[]) {
95
96 enum {
97 ARG_VERSION = 0x100,
98 ARG_NO_BLOCK,
99 ARG_NO_PAGER,
100 ARG_NO_ASK_PASSWORD,
101 ARG_USER,
102 ARG_SYSTEM,
103 ARG_DISCOVER,
104 ARG_MOUNT_TYPE,
105 ARG_MOUNT_OPTIONS,
106 ARG_OWNER,
107 ARG_FSCK,
108 ARG_DESCRIPTION,
109 ARG_TIMEOUT_IDLE,
110 ARG_AUTOMOUNT,
111 ARG_AUTOMOUNT_PROPERTY,
112 ARG_BIND_DEVICE,
113 ARG_LIST,
114 };
115
116 static const struct option options[] = {
117 { "help", no_argument0, NULL((void*)0), 'h' },
118 { "version", no_argument0, NULL((void*)0), ARG_VERSION },
119 { "no-block", no_argument0, NULL((void*)0), ARG_NO_BLOCK },
120 { "no-pager", no_argument0, NULL((void*)0), ARG_NO_PAGER },
121 { "no-ask-password", no_argument0, NULL((void*)0), ARG_NO_ASK_PASSWORD },
122 { "quiet", no_argument0, NULL((void*)0), 'q' },
123 { "user", no_argument0, NULL((void*)0), ARG_USER },
124 { "system", no_argument0, NULL((void*)0), ARG_SYSTEM },
125 { "host", required_argument1, NULL((void*)0), 'H' },
126 { "machine", required_argument1, NULL((void*)0), 'M' },
127 { "discover", no_argument0, NULL((void*)0), ARG_DISCOVER },
128 { "type", required_argument1, NULL((void*)0), 't' },
129 { "options", required_argument1, NULL((void*)0), 'o' },
130 { "owner", required_argument1, NULL((void*)0), ARG_OWNER },
131 { "fsck", required_argument1, NULL((void*)0), ARG_FSCK },
132 { "description", required_argument1, NULL((void*)0), ARG_DESCRIPTION },
133 { "property", required_argument1, NULL((void*)0), 'p' },
134 { "automount", required_argument1, NULL((void*)0), ARG_AUTOMOUNT },
135 { "timeout-idle-sec", required_argument1, NULL((void*)0), ARG_TIMEOUT_IDLE },
136 { "automount-property", required_argument1, NULL((void*)0), ARG_AUTOMOUNT_PROPERTY },
137 { "bind-device", no_argument0, NULL((void*)0), ARG_BIND_DEVICE },
138 { "list", no_argument0, NULL((void*)0), ARG_LIST },
139 { "umount", no_argument0, NULL((void*)0), 'u' },
140 { "unmount", no_argument0, NULL((void*)0), 'u' },
141 { "collect", no_argument0, NULL((void*)0), 'G' },
142 {},
143 };
144
145 int r, c;
146
147 assert(argc >= 0)do { if ((__builtin_expect(!!(!(argc >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("argc >= 0"), "../src/mount/mount-tool.c"
, 147, __PRETTY_FUNCTION__); } while (0)
;
148 assert(argv)do { if ((__builtin_expect(!!(!(argv)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("argv"), "../src/mount/mount-tool.c", 148
, __PRETTY_FUNCTION__); } while (0)
;
149
150 if (strstr(program_invocation_short_name, "systemd-umount"))
151 arg_action = ACTION_UMOUNT;
152
153 while ((c = getopt_long(argc, argv, "hqH:M:t:o:p:AuG", options, NULL((void*)0))) >= 0)
154
155 switch (c) {
156
157 case 'h':
158 help();
159 return 0;
160
161 case ARG_VERSION:
162 return version();
163
164 case ARG_NO_BLOCK:
165 arg_no_block = true1;
166 break;
167
168 case ARG_NO_PAGER:
169 arg_no_pager = true1;
170 break;
171
172 case ARG_NO_ASK_PASSWORD:
173 arg_ask_password = false0;
174 break;
175
176 case 'q':
177 arg_quiet = true1;
178 break;
179
180 case ARG_USER:
181 arg_user = true1;
182 break;
183
184 case ARG_SYSTEM:
185 arg_user = false0;
186 break;
187
188 case 'H':
189 arg_transport = BUS_TRANSPORT_REMOTE;
190 arg_host = optarg;
191 break;
192
193 case 'M':
194 arg_transport = BUS_TRANSPORT_MACHINE;
195 arg_host = optarg;
196 break;
197
198 case ARG_DISCOVER:
199 arg_discover = true1;
200 break;
201
202 case 't':
203 if (free_and_strdup(&arg_mount_type, optarg) < 0)
204 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 204, __func__)
;
205 break;
206
207 case 'o':
208 if (free_and_strdup(&arg_mount_options, optarg) < 0)
209 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 209, __func__)
;
210 break;
211
212 case ARG_OWNER: {
213 const char *user = optarg;
214
215 r = get_user_creds(&user, &arg_uid, &arg_gid, NULL((void*)0), NULL((void*)0));
216 if (r < 0)
217 return log_error_errno(r,({ 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/mount/mount-tool.c", 220, __func__, r == -74 ? "UID or GID of user %s are invalid."
: "Cannot use \"%s\" as owner: %m", optarg) : -abs(_e); })
218 r == -EBADMSG ? "UID or GID of user %s are invalid."({ 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/mount/mount-tool.c", 220, __func__, r == -74 ? "UID or GID of user %s are invalid."
: "Cannot use \"%s\" as owner: %m", optarg) : -abs(_e); })
219 : "Cannot use \"%s\" as owner: %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/mount/mount-tool.c", 220, __func__, r == -74 ? "UID or GID of user %s are invalid."
: "Cannot use \"%s\" as owner: %m", optarg) : -abs(_e); })
220 optarg)({ 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/mount/mount-tool.c", 220, __func__, r == -74 ? "UID or GID of user %s are invalid."
: "Cannot use \"%s\" as owner: %m", optarg) : -abs(_e); })
;
221 break;
222 }
223
224 case ARG_FSCK:
225 r = parse_boolean(optarg);
226 if (r < 0)
227 return log_error_errno(r, "Failed to parse --fsck= argument: %s", optarg)({ 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/mount/mount-tool.c", 227, __func__, "Failed to parse --fsck= argument: %s"
, optarg) : -abs(_e); })
;
228
229 arg_fsck = r;
230 break;
231
232 case ARG_DESCRIPTION:
233 if (free_and_strdup(&arg_description, optarg) < 0)
234 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 234, __func__)
;
235 break;
236
237 case 'p':
238 if (strv_extend(&arg_property, optarg) < 0)
239 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 239, __func__)
;
240
241 break;
242
243 case 'A':
244 arg_action = ACTION_AUTOMOUNT;
245 break;
246
247 case ARG_AUTOMOUNT:
248 r = parse_boolean(optarg);
249 if (r < 0)
250 return log_error_errno(r, "--automount= expects a valid boolean parameter: %s", optarg)({ 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/mount/mount-tool.c", 250, __func__, "--automount= expects a valid boolean parameter: %s"
, optarg) : -abs(_e); })
;
251
252 arg_action = r ? ACTION_AUTOMOUNT : ACTION_MOUNT;
253 break;
254
255 case ARG_TIMEOUT_IDLE:
256 r = parse_sec(optarg, &arg_timeout_idle);
257 if (r < 0)
258 return log_error_errno(r, "Failed to parse timeout: %s", optarg)({ 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/mount/mount-tool.c", 258, __func__, "Failed to parse timeout: %s"
, optarg) : -abs(_e); })
;
259
260 break;
261
262 case ARG_AUTOMOUNT_PROPERTY:
263 if (strv_extend(&arg_automount_property, optarg) < 0)
264 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 264, __func__)
;
265
266 break;
267
268 case ARG_BIND_DEVICE:
269 arg_bind_device = true1;
270 break;
271
272 case ARG_LIST:
273 arg_action = ACTION_LIST;
274 break;
275
276 case 'u':
277 arg_action = ACTION_UMOUNT;
278 break;
279
280 case 'G':
281 arg_aggressive_gc = true1;
282 break;
283
284 case '?':
285 return -EINVAL22;
286
287 default:
288 assert_not_reached("Unhandled option")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, (
"Unhandled option"), "../src/mount/mount-tool.c", 288, __PRETTY_FUNCTION__
); } while (0)
;
289 }
290
291 if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL) {
292 log_error("Execution in user context is not supported on non-local systems.")({ 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/mount/mount-tool.c", 292, __func__, "Execution in user context is not supported on non-local systems."
) : -abs(_e); })
;
293 return -EINVAL22;
294 }
295
296 if (arg_action == ACTION_LIST) {
297 if (optind < argc) {
298 log_error("Too many arguments.")({ 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/mount/mount-tool.c", 298, __func__, "Too many arguments."
) : -abs(_e); })
;
299 return -EINVAL22;
300 }
301
302 if (arg_transport != BUS_TRANSPORT_LOCAL) {
303 log_error("Listing devices only supported locally.")({ 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/mount/mount-tool.c", 303, __func__, "Listing devices only supported locally."
) : -abs(_e); })
;
304 return -EOPNOTSUPP95;
305 }
306 } else if (arg_action == ACTION_UMOUNT) {
307 if (optind >= argc) {
308 log_error("At least one argument required.")({ 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/mount/mount-tool.c", 308, __func__, "At least one argument required."
) : -abs(_e); })
;
309 return -EINVAL22;
310 }
311
312 if (arg_transport != BUS_TRANSPORT_LOCAL) {
313 int i;
314
315 for (i = optind; i < argc; i++)
316 if (!path_is_absolute(argv[i]) ) {
317 log_error("Only absolute path is supported: %s", argv[i])({ 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/mount/mount-tool.c", 317, __func__, "Only absolute path is supported: %s"
, argv[i]) : -abs(_e); })
;
318 return -EINVAL22;
319 }
320 }
321 } else {
322 if (optind >= argc) {
323 log_error("At least one argument required.")({ 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/mount/mount-tool.c", 323, __func__, "At least one argument required."
) : -abs(_e); })
;
324 return -EINVAL22;
325 }
326
327 if (argc > optind+2) {
328 log_error("At most two arguments required.")({ 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/mount/mount-tool.c", 328, __func__, "At most two arguments required."
) : -abs(_e); })
;
329 return -EINVAL22;
330 }
331
332 if (arg_mount_type && (fstype_is_api_vfs(arg_mount_type) || fstype_is_network(arg_mount_type))) {
333 arg_mount_what = strdup(argv[optind]);
334 if (!arg_mount_what)
335 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 335, __func__)
;
336
337 } else if (arg_transport == BUS_TRANSPORT_LOCAL) {
338 _cleanup_free___attribute__((cleanup(freep))) char *u = NULL((void*)0);
339
340 u = fstab_node_to_udev_node(argv[optind]);
341 if (!u)
342 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 342, __func__)
;
343
344 r = chase_symlinks(u, NULL((void*)0), 0, &arg_mount_what);
345 if (r < 0)
346 return log_error_errno(r, "Failed to make path %s absolute: %m", u)({ 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/mount/mount-tool.c", 346, __func__, "Failed to make path %s absolute: %m"
, u) : -abs(_e); })
;
347 } else {
348 arg_mount_what = strdup(argv[optind]);
349 if (!arg_mount_what)
350 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 350, __func__)
;
351
352 path_simplify(arg_mount_what, false0);
353
354 if (!path_is_absolute(arg_mount_what)) {
355 log_error("Only absolute path is supported: %s", arg_mount_what)({ 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/mount/mount-tool.c", 355, __func__, "Only absolute path is supported: %s"
, arg_mount_what) : -abs(_e); })
;
356 return -EINVAL22;
357 }
358 }
359
360 if (argc > optind+1) {
361 if (arg_transport == BUS_TRANSPORT_LOCAL) {
362 r = chase_symlinks(argv[optind+1], NULL((void*)0), CHASE_NONEXISTENT, &arg_mount_where);
363 if (r < 0)
364 return log_error_errno(r, "Failed to make path %s absolute: %m", argv[optind+1])({ 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/mount/mount-tool.c", 364, __func__, "Failed to make path %s absolute: %m"
, argv[optind+1]) : -abs(_e); })
;
365 } else {
366 arg_mount_where = strdup(argv[optind+1]);
367 if (!arg_mount_where)
368 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 368, __func__)
;
369
370 path_simplify(arg_mount_where, false0);
371
372 if (!path_is_absolute(arg_mount_where)) {
373 log_error("Only absolute path is supported: %s", arg_mount_where)({ 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/mount/mount-tool.c", 373, __func__, "Only absolute path is supported: %s"
, arg_mount_where) : -abs(_e); })
;
374 return -EINVAL22;
375 }
376 }
377 } else
378 arg_discover = true1;
379
380 if (arg_discover && arg_transport != BUS_TRANSPORT_LOCAL) {
381 log_error("Automatic mount location discovery is only supported locally.")({ 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/mount/mount-tool.c", 381, __func__, "Automatic mount location discovery is only supported locally."
) : -abs(_e); })
;
382 return -EOPNOTSUPP95;
383 }
384 }
385
386 return 1;
387}
388
389static int transient_unit_set_properties(sd_bus_message *m, UnitType t, char **properties) {
390 int r;
391
392 if (!isempty(arg_description)) {
393 r = sd_bus_message_append(m, "(sv)", "Description", "s", arg_description);
394 if (r < 0)
395 return r;
396 }
397
398 if (arg_bind_device && is_device_path(arg_mount_what)) {
399 _cleanup_free___attribute__((cleanup(freep))) char *device_unit = NULL((void*)0);
400
401 r = unit_name_from_path(arg_mount_what, ".device", &device_unit);
402 if (r < 0)
403 return r;
404
405 r = sd_bus_message_append(m, "(sv)(sv)",
406 "After", "as", 1, device_unit,
407 "BindsTo", "as", 1, device_unit);
408 if (r < 0)
409 return r;
410 }
411
412 if (arg_aggressive_gc) {
413 r = sd_bus_message_append(m, "(sv)", "CollectMode", "s", "inactive-or-failed");
414 if (r < 0)
415 return r;
416 }
417
418 r = bus_append_unit_property_assignment_many(m, t, properties);
419 if (r < 0)
420 return r;
421
422 return 0;
423}
424
425static int transient_mount_set_properties(sd_bus_message *m) {
426 _cleanup_free___attribute__((cleanup(freep))) char *options = NULL((void*)0);
427 int r;
428
429 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/mount/mount-tool.c", 429, __PRETTY_FUNCTION__
); } while (0)
;
430
431 r = transient_unit_set_properties(m, UNIT_MOUNT, arg_property);
432 if (r < 0)
433 return r;
434
435 if (arg_mount_what) {
436 r = sd_bus_message_append(m, "(sv)", "What", "s", arg_mount_what);
437 if (r < 0)
438 return r;
439 }
440
441 if (arg_mount_type) {
442 r = sd_bus_message_append(m, "(sv)", "Type", "s", arg_mount_type);
443 if (r < 0)
444 return r;
445 }
446
447 /* Prepend uid=…,gid=… if arg_uid is set */
448 if (arg_uid != UID_INVALID((uid_t) -1)) {
449 r = asprintf(&options,
450 "uid=" UID_FMT"%" "u" ",gid=" GID_FMT"%" "u" "%s%s",
451 arg_uid, arg_gid,
452 arg_mount_options ? "," : "", strempty(arg_mount_options));
453 if (r < 0)
454 return -ENOMEM12;
455 }
456
457 if (options || arg_mount_options) {
458 log_debug("Using mount options: %s", options ?: arg_mount_options)({ 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/mount/mount-tool.c", 458, __func__, "Using mount options: %s"
, options ?: arg_mount_options) : -abs(_e); })
;
459
460 r = sd_bus_message_append(m, "(sv)", "Options", "s", options ?: arg_mount_options);
461 if (r < 0)
462 return r;
463 } else
464 log_debug("Not using any mount options")({ 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/mount/mount-tool.c", 464, __func__, "Not using any mount options"
) : -abs(_e); })
;
465
466 if (arg_fsck) {
467 _cleanup_free___attribute__((cleanup(freep))) char *fsck = NULL((void*)0);
468
469 r = unit_name_from_path_instance("systemd-fsck", arg_mount_what, ".service", &fsck);
470 if (r < 0)
471 return r;
472
473 r = sd_bus_message_append(m,
474 "(sv)(sv)",
475 "Requires", "as", 1, fsck,
476 "After", "as", 1, fsck);
477 if (r < 0)
478 return r;
479 }
480
481 return 0;
482}
483
484static int transient_automount_set_properties(sd_bus_message *m) {
485 int r;
486
487 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/mount/mount-tool.c", 487, __PRETTY_FUNCTION__
); } while (0)
;
488
489 r = transient_unit_set_properties(m, UNIT_AUTOMOUNT, arg_automount_property);
490 if (r < 0)
491 return r;
492
493 if (arg_timeout_idle != USEC_INFINITY((usec_t) -1)) {
494 r = sd_bus_message_append(m, "(sv)", "TimeoutIdleUSec", "t", arg_timeout_idle);
495 if (r < 0)
496 return r;
497 }
498
499 return 0;
500}
501
502static int start_transient_mount(
503 sd_bus *bus,
504 char **argv) {
505
506 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *m = NULL((void*)0), *reply = NULL((void*)0);
507 _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0});
508 _cleanup_(bus_wait_for_jobs_freep)__attribute__((cleanup(bus_wait_for_jobs_freep))) BusWaitForJobs *w = NULL((void*)0);
509 _cleanup_free___attribute__((cleanup(freep))) char *mount_unit = NULL((void*)0);
510 int r;
511
512 if (!arg_no_block) {
513 r = bus_wait_for_jobs_new(bus, &w);
514 if (r < 0)
515 return log_error_errno(r, "Could not watch jobs: %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/mount/mount-tool.c", 515, __func__, "Could not watch jobs: %m"
) : -abs(_e); })
;
516 }
517
518 r = unit_name_from_path(arg_mount_where, ".mount", &mount_unit);
519 if (r < 0)
520 return log_error_errno(r, "Failed to make mount unit name: %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/mount/mount-tool.c", 520, __func__, "Failed to make mount unit name: %m"
) : -abs(_e); })
;
521
522 r = sd_bus_message_new_method_call(
523 bus,
524 &m,
525 "org.freedesktop.systemd1",
526 "/org/freedesktop/systemd1",
527 "org.freedesktop.systemd1.Manager",
528 "StartTransientUnit");
529 if (r < 0)
530 return bus_log_create_error(r);
531
532 r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
533 if (r < 0)
534 return bus_log_create_error(r);
535
536 /* Name and mode */
537 r = sd_bus_message_append(m, "ss", mount_unit, "fail");
538 if (r < 0)
539 return bus_log_create_error(r);
540
541 /* Properties */
542 r = sd_bus_message_open_container(m, 'a', "(sv)");
543 if (r < 0)
544 return bus_log_create_error(r);
545
546 r = transient_mount_set_properties(m);
547 if (r < 0)
548 return bus_log_create_error(r);
549
550 r = sd_bus_message_close_container(m);
551 if (r < 0)
552 return bus_log_create_error(r);
553
554 /* Auxiliary units */
555 r = sd_bus_message_append(m, "a(sa(sv))", 0);
556 if (r < 0)
557 return bus_log_create_error(r);
558
559 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
560
561 r = sd_bus_call(bus, m, 0, &error, &reply);
562 if (r < 0)
563 return log_error_errno(r, "Failed to start transient mount unit: %s", bus_error_message(&error, r))({ 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/mount/mount-tool.c", 563, __func__, "Failed to start transient mount unit: %s"
, bus_error_message(&error, r)) : -abs(_e); })
;
564
565 if (w) {
566 const char *object;
567
568 r = sd_bus_message_read(reply, "o", &object);
569 if (r < 0)
570 return bus_log_parse_error(r);
571
572 r = bus_wait_for_jobs_one(w, object, arg_quiet);
573 if (r < 0)
574 return r;
575 }
576
577 if (!arg_quiet)
578 log_info("Started unit %s%s%s for mount point: %s%s%s",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 580, __func__, "Started unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), mount_unit, ansi_normal(), ansi_highlight
(), arg_mount_where, ansi_normal()) : -abs(_e); })
579 ansi_highlight(), mount_unit, ansi_normal(),({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 580, __func__, "Started unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), mount_unit, ansi_normal(), ansi_highlight
(), arg_mount_where, ansi_normal()) : -abs(_e); })
580 ansi_highlight(), arg_mount_where, ansi_normal())({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 580, __func__, "Started unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), mount_unit, ansi_normal(), ansi_highlight
(), arg_mount_where, ansi_normal()) : -abs(_e); })
;
581
582 return 0;
583}
584
585static int start_transient_automount(
586 sd_bus *bus,
587 char **argv) {
588
589 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *m = NULL((void*)0), *reply = NULL((void*)0);
590 _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0});
591 _cleanup_(bus_wait_for_jobs_freep)__attribute__((cleanup(bus_wait_for_jobs_freep))) BusWaitForJobs *w = NULL((void*)0);
592 _cleanup_free___attribute__((cleanup(freep))) char *automount_unit = NULL((void*)0), *mount_unit = NULL((void*)0);
593 int r;
594
595 if (!arg_no_block) {
596 r = bus_wait_for_jobs_new(bus, &w);
597 if (r < 0)
598 return log_error_errno(r, "Could not watch jobs: %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/mount/mount-tool.c", 598, __func__, "Could not watch jobs: %m"
) : -abs(_e); })
;
599 }
600
601 r = unit_name_from_path(arg_mount_where, ".automount", &automount_unit);
602 if (r < 0)
603 return log_error_errno(r, "Failed to make automount unit name: %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/mount/mount-tool.c", 603, __func__, "Failed to make automount unit name: %m"
) : -abs(_e); })
;
604
605 r = unit_name_from_path(arg_mount_where, ".mount", &mount_unit);
606 if (r < 0)
607 return log_error_errno(r, "Failed to make mount unit name: %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/mount/mount-tool.c", 607, __func__, "Failed to make mount unit name: %m"
) : -abs(_e); })
;
608
609 r = sd_bus_message_new_method_call(
610 bus,
611 &m,
612 "org.freedesktop.systemd1",
613 "/org/freedesktop/systemd1",
614 "org.freedesktop.systemd1.Manager",
615 "StartTransientUnit");
616 if (r < 0)
617 return bus_log_create_error(r);
618
619 r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
620 if (r < 0)
621 return bus_log_create_error(r);
622
623 /* Name and mode */
624 r = sd_bus_message_append(m, "ss", automount_unit, "fail");
625 if (r < 0)
626 return bus_log_create_error(r);
627
628 /* Properties */
629 r = sd_bus_message_open_container(m, 'a', "(sv)");
630 if (r < 0)
631 return bus_log_create_error(r);
632
633 r = transient_automount_set_properties(m);
634 if (r < 0)
635 return bus_log_create_error(r);
636
637 r = sd_bus_message_close_container(m);
638 if (r < 0)
639 return bus_log_create_error(r);
640
641 /* Auxiliary units */
642 r = sd_bus_message_open_container(m, 'a', "(sa(sv))");
643 if (r < 0)
644 return bus_log_create_error(r);
645
646 r = sd_bus_message_open_container(m, 'r', "sa(sv)");
647 if (r < 0)
648 return bus_log_create_error(r);
649
650 r = sd_bus_message_append(m, "s", mount_unit);
651 if (r < 0)
652 return bus_log_create_error(r);
653
654 r = sd_bus_message_open_container(m, 'a', "(sv)");
655 if (r < 0)
656 return bus_log_create_error(r);
657
658 r = transient_mount_set_properties(m);
659 if (r < 0)
660 return bus_log_create_error(r);
661
662 r = sd_bus_message_close_container(m);
663 if (r < 0)
664 return bus_log_create_error(r);
665
666 r = sd_bus_message_close_container(m);
667 if (r < 0)
668 return bus_log_create_error(r);
669
670 r = sd_bus_message_close_container(m);
671 if (r < 0)
672 return bus_log_create_error(r);
673
674 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
675
676 r = sd_bus_call(bus, m, 0, &error, &reply);
677 if (r < 0)
678 return log_error_errno(r, "Failed to start transient automount unit: %s", bus_error_message(&error, r))({ 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/mount/mount-tool.c", 678, __func__, "Failed to start transient automount unit: %s"
, bus_error_message(&error, r)) : -abs(_e); })
;
679
680 if (w) {
681 const char *object;
682
683 r = sd_bus_message_read(reply, "o", &object);
684 if (r < 0)
685 return bus_log_parse_error(r);
686
687 r = bus_wait_for_jobs_one(w, object, arg_quiet);
688 if (r < 0)
689 return r;
690 }
691
692 if (!arg_quiet)
693 log_info("Started unit %s%s%s for mount point: %s%s%s",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 695, __func__, "Started unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), automount_unit, ansi_normal(), ansi_highlight
(), arg_mount_where, ansi_normal()) : -abs(_e); })
694 ansi_highlight(), automount_unit, ansi_normal(),({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 695, __func__, "Started unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), automount_unit, ansi_normal(), ansi_highlight
(), arg_mount_where, ansi_normal()) : -abs(_e); })
695 ansi_highlight(), arg_mount_where, ansi_normal())({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 695, __func__, "Started unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), automount_unit, ansi_normal(), ansi_highlight
(), arg_mount_where, ansi_normal()) : -abs(_e); })
;
696
697 return 0;
698}
699
700static int find_mount_points(const char *what, char ***list) {
701 _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *proc_self_mountinfo = NULL((void*)0);
702 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0);
703 size_t bufsize = 0, n = 0;
704
705 assert(what)do { if ((__builtin_expect(!!(!(what)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("what"), "../src/mount/mount-tool.c", 705
, __PRETTY_FUNCTION__); } while (0)
;
706 assert(list)do { if ((__builtin_expect(!!(!(list)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("list"), "../src/mount/mount-tool.c", 706
, __PRETTY_FUNCTION__); } while (0)
;
707
708 /* Returns all mount points obtained from /proc/self/mountinfo in *list,
709 * and the number of mount points as return value. */
710
711 proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
712 if (!proc_self_mountinfo)
713 return log_error_errno(errno, "Can't open /proc/self/mountinfo: %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/mount/mount-tool.c", 713, __func__
, "Can't open /proc/self/mountinfo: %m") : -abs(_e); })
;
714
715 for (;;) {
716 _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0), *where = NULL((void*)0), *dev = NULL((void*)0);
717 int r;
718
719 r = fscanf(proc_self_mountinfo,
720 "%*s " /* (1) mount id */
721 "%*s " /* (2) parent id */
722 "%*s " /* (3) major:minor */
723 "%*s " /* (4) root */
724 "%ms " /* (5) mount point */
725 "%*s" /* (6) mount options */
726 "%*[^-]" /* (7) optional fields */
727 "- " /* (8) separator */
728 "%*s " /* (9) file system type */
729 "%ms" /* (10) mount source */
730 "%*s" /* (11) mount options 2 */
731 "%*[^\n]", /* some rubbish at the end */
732 &path, &dev);
733 if (r != 2) {
734 if (r == EOF(-1))
735 break;
736
737 continue;
738 }
739
740 if (!streq(what, dev)(strcmp((what),(dev)) == 0))
741 continue;
742
743 r = cunescape(path, UNESCAPE_RELAX, &where);
744 if (r < 0)
745 continue;
746
747 /* one extra slot is needed for the terminating NULL */
748 if (!GREEDY_REALLOC(l, bufsize, n + 2)greedy_realloc((void**) &(l), &(bufsize), (n + 2), sizeof
((l)[0]))
)
749 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 749, __func__)
;
750
751 l[n++] = TAKE_PTR(where)({ typeof(where) _ptr_ = (where); (where) = ((void*)0); _ptr_
; })
;
752 }
753
754 if (!GREEDY_REALLOC(l, bufsize, n + 1)greedy_realloc((void**) &(l), &(bufsize), (n + 1), sizeof
((l)[0]))
)
755 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 755, __func__)
;
756
757 l[n] = NULL((void*)0);
758 *list = TAKE_PTR(l)({ typeof(l) _ptr_ = (l); (l) = ((void*)0); _ptr_; });
759
760 return n;
761}
762
763static int find_loop_device(const char *backing_file, char **loop_dev) {
764 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
765 struct dirent *de;
766 _cleanup_free___attribute__((cleanup(freep))) char *l = NULL((void*)0);
767
768 assert(backing_file)do { if ((__builtin_expect(!!(!(backing_file)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("backing_file"), "../src/mount/mount-tool.c"
, 768, __PRETTY_FUNCTION__); } while (0)
;
8
Taking false branch
9
Loop condition is false. Exiting loop
769 assert(loop_dev)do { if ((__builtin_expect(!!(!(loop_dev)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("loop_dev"), "../src/mount/mount-tool.c"
, 769, __PRETTY_FUNCTION__); } while (0)
;
10
Taking false branch
11
Loop condition is false. Exiting loop
770
771 d = opendir("/sys/devices/virtual/block");
772 if (!d)
12
Assuming 'd' is null
13
Taking true branch
773 return -errno(*__errno_location ());
14
Returning without writing to '*loop_dev'
774
775 FOREACH_DIRENT(de, d, return -errno)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location
()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location (
)) > 0) { return -(*__errno_location ()); } break; } else if
(hidden_or_backup_file((de)->d_name)) continue; else
{
776 _cleanup_free___attribute__((cleanup(freep))) char *sys = NULL((void*)0), *fname = NULL((void*)0);
777 int r;
778
779 dirent_ensure_type(d, de);
780
781 if (de->d_type != DT_DIRDT_DIR)
782 continue;
783
784 if (!startswith(de->d_name, "loop"))
785 continue;
786
787 sys = strjoin("/sys/devices/virtual/block/", de->d_name, "/loop/backing_file")strjoin_real(("/sys/devices/virtual/block/"), de->d_name, "/loop/backing_file"
, ((void*)0))
;
788 if (!sys)
789 return -ENOMEM12;
790
791 r = read_one_line_file(sys, &fname);
792 if (r < 0) {
793 log_debug_errno(r, "Failed to read %s, ignoring: %m", sys)({ 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/mount/mount-tool.c", 793, __func__, "Failed to read %s, ignoring: %m"
, sys) : -abs(_e); })
;
794 continue;
795 }
796
797 if (files_same(fname, backing_file, 0) <= 0)
798 continue;
799
800 l = strjoin("/dev/", de->d_name)strjoin_real(("/dev/"), de->d_name, ((void*)0));
801 if (!l)
802 return -ENOMEM12;
803
804 break;
805 }
806
807 if (!l)
808 return -ENXIO6;
809
810 *loop_dev = TAKE_PTR(l)({ typeof(l) _ptr_ = (l); (l) = ((void*)0); _ptr_; });
811
812 return 0;
813}
814
815static int stop_mount(
816 sd_bus *bus,
817 const char *where,
818 const char *suffix) {
819
820 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *m = NULL((void*)0), *reply = NULL((void*)0);
821 _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0});
822 _cleanup_(bus_wait_for_jobs_freep)__attribute__((cleanup(bus_wait_for_jobs_freep))) BusWaitForJobs *w = NULL((void*)0);
823 _cleanup_free___attribute__((cleanup(freep))) char *mount_unit = NULL((void*)0);
824 int r;
825
826 if (!arg_no_block) {
827 r = bus_wait_for_jobs_new(bus, &w);
828 if (r < 0)
829 return log_error_errno(r, "Could not watch jobs: %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/mount/mount-tool.c", 829, __func__, "Could not watch jobs: %m"
) : -abs(_e); })
;
830 }
831
832 r = unit_name_from_path(where, suffix, &mount_unit);
833 if (r < 0)
834 return log_error_errno(r, "Failed to make %s unit name from path %s: %m", suffix + 1, where)({ 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/mount/mount-tool.c", 834, __func__, "Failed to make %s unit name from path %s: %m"
, suffix + 1, where) : -abs(_e); })
;
835
836 r = sd_bus_message_new_method_call(
837 bus,
838 &m,
839 "org.freedesktop.systemd1",
840 "/org/freedesktop/systemd1",
841 "org.freedesktop.systemd1.Manager",
842 "StopUnit");
843 if (r < 0)
844 return bus_log_create_error(r);
845
846 r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
847 if (r < 0)
848 return bus_log_create_error(r);
849
850 /* Name and mode */
851 r = sd_bus_message_append(m, "ss", mount_unit, "fail");
852 if (r < 0)
853 return bus_log_create_error(r);
854
855 polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
856
857 r = sd_bus_call(bus, m, 0, &error, &reply);
858 if (r < 0) {
859 if (streq(suffix, ".automount")(strcmp((suffix),(".automount")) == 0) &&
860 sd_bus_error_has_name(&error, "org.freedesktop.systemd1.NoSuchUnit"))
861 return 0;
862 return log_error_errno(r, "Failed to stop %s unit: %s", suffix + 1, bus_error_message(&error, r))({ 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/mount/mount-tool.c", 862, __func__, "Failed to stop %s unit: %s"
, suffix + 1, bus_error_message(&error, r)) : -abs(_e); }
)
;
863 }
864
865 if (w) {
866 const char *object;
867
868 r = sd_bus_message_read(reply, "o", &object);
869 if (r < 0)
870 return bus_log_parse_error(r);
871
872 r = bus_wait_for_jobs_one(w, object, arg_quiet);
873 if (r < 0)
874 return r;
875 }
876
877 if (!arg_quiet)
878 log_info("Stopped unit %s%s%s for mount point: %s%s%s",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 880, __func__, "Stopped unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), mount_unit, ansi_normal(), ansi_highlight
(), where, ansi_normal()) : -abs(_e); })
879 ansi_highlight(), mount_unit, ansi_normal(),({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 880, __func__, "Stopped unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), mount_unit, ansi_normal(), ansi_highlight
(), where, ansi_normal()) : -abs(_e); })
880 ansi_highlight(), where, ansi_normal())({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 880, __func__, "Stopped unit %s%s%s for mount point: %s%s%s"
, ansi_highlight(), mount_unit, ansi_normal(), ansi_highlight
(), where, ansi_normal()) : -abs(_e); })
;
881
882 return 0;
883}
884
885static int stop_mounts(
886 sd_bus *bus,
887 const char *where) {
888
889 int r;
890
891 if (path_equal(where, "/")) {
892 log_error("Refusing to operate on root directory: %s", where)({ 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/mount/mount-tool.c", 892, __func__, "Refusing to operate on root directory: %s"
, where) : -abs(_e); })
;
893 return -EINVAL22;
894 }
895
896 if (!path_is_normalized(where)) {
897 log_error("Path contains non-normalized components: %s", where)({ 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/mount/mount-tool.c", 897, __func__, "Path contains non-normalized components: %s"
, where) : -abs(_e); })
;
898 return -EINVAL22;
899 }
900
901 r = stop_mount(bus, where, ".mount");
902 if (r < 0)
903 return r;
904
905 r = stop_mount(bus, where, ".automount");
906 if (r < 0)
907 return r;
908
909 return 0;
910}
911
912static int umount_by_device(sd_bus *bus, const char *what) {
913 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
914 _cleanup_(udev_unrefp)__attribute__((cleanup(udev_unrefp))) struct udev *udev = NULL((void*)0);
915 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **list = NULL((void*)0);
916 struct stat st;
917 const char *v;
918 char **l;
919 int r, r2 = 0;
920
921 assert(what)do { if ((__builtin_expect(!!(!(what)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("what"), "../src/mount/mount-tool.c", 921
, __PRETTY_FUNCTION__); } while (0)
;
922
923 if (stat(what, &st) < 0)
924 return log_error_errno(errno, "Can't stat %s: %m", what)({ 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/mount/mount-tool.c", 924, __func__
, "Can't stat %s: %m", what) : -abs(_e); })
;
925
926 if (!S_ISBLK(st.st_mode)((((st.st_mode)) & 0170000) == (0060000))) {
927 log_error("Not a block device: %s", what)({ 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/mount/mount-tool.c", 927, __func__, "Not a block device: %s"
, what) : -abs(_e); })
;
928 return -ENOTBLK15;
929 }
930
931 udev = udev_new();
932 if (!udev)
933 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 933, __func__)
;
934
935 d = udev_device_new_from_devnum(udev, 'b', st.st_rdev);
936 if (!d)
937 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 937, __func__)
;
938
939 v = udev_device_get_property_value(d, "ID_FS_USAGE");
940 if (!streq_ptr(v, "filesystem")) {
941 log_error("%s does not contain a known file system.", what)({ 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/mount/mount-tool.c", 941, __func__, "%s does not contain a known file system."
, what) : -abs(_e); })
;
942 return -EINVAL22;
943 }
944
945 v = udev_device_get_property_value(d, "SYSTEMD_MOUNT_WHERE");
946 if (!isempty(v))
947 r2 = stop_mounts(bus, v);
948
949 r = find_mount_points(what, &list);
950 if (r < 0)
951 return r;
952
953 for (l = list; *l; l++) {
954 r = stop_mounts(bus, *l);
955 if (r < 0)
956 r2 = r;
957 }
958
959 return r2;
960}
961
962static int umount_loop(sd_bus *bus, const char *backing_file) {
963 _cleanup_free___attribute__((cleanup(freep))) char *loop_dev = NULL((void*)0);
964 int r;
965
966 assert(backing_file)do { if ((__builtin_expect(!!(!(backing_file)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("backing_file"), "../src/mount/mount-tool.c"
, 966, __PRETTY_FUNCTION__); } while (0)
;
967
968 r = find_loop_device(backing_file, &loop_dev);
969 if (r < 0)
970 return log_error_errno(r, r == -ENXIO ? "File %s is not mounted." : "Can't get loop device for %s: %m", backing_file)({ 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/mount/mount-tool.c", 970, __func__, r == -6 ? "File %s is not mounted."
: "Can't get loop device for %s: %m", backing_file) : -abs(_e
); })
;
971
972 return umount_by_device(bus, loop_dev);
973}
974
975static int action_umount(
976 sd_bus *bus,
977 int argc,
978 char **argv) {
979
980 int i, r, r2 = 0;
981
982 if (arg_transport != BUS_TRANSPORT_LOCAL) {
983 for (i = optind; i < argc; i++) {
984 _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0);
985
986 p = strdup(argv[i]);
987 if (!p)
988 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 988, __func__)
;
989
990 path_simplify(p, false0);
991
992 r = stop_mounts(bus, p);
993 if (r < 0)
994 r2 = r;
995 }
996 return r2;
997 }
998
999 for (i = optind; i < argc; i++) {
1000 _cleanup_free___attribute__((cleanup(freep))) char *u = NULL((void*)0), *p = NULL((void*)0);
1001 struct stat st;
1002
1003 u = fstab_node_to_udev_node(argv[i]);
1004 if (!u)
1005 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1005, __func__)
;
1006
1007 r = chase_symlinks(u, NULL((void*)0), 0, &p);
1008 if (r < 0) {
1009 r2 = log_error_errno(r, "Failed to make path %s absolute: %m", argv[i])({ 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/mount/mount-tool.c", 1009, __func__, "Failed to make path %s absolute: %m"
, argv[i]) : -abs(_e); })
;
1010 continue;
1011 }
1012
1013 if (stat(p, &st) < 0)
1014 return log_error_errno(errno, "Can't stat %s (from %s): %m", p, argv[i])({ 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/mount/mount-tool.c", 1014, __func__
, "Can't stat %s (from %s): %m", p, argv[i]) : -abs(_e); })
;
1015
1016 if (S_ISBLK(st.st_mode)((((st.st_mode)) & 0170000) == (0060000)))
1017 r = umount_by_device(bus, p);
1018 else if (S_ISREG(st.st_mode)((((st.st_mode)) & 0170000) == (0100000)))
1019 r = umount_loop(bus, p);
1020 else if (S_ISDIR(st.st_mode)((((st.st_mode)) & 0170000) == (0040000)))
1021 r = stop_mounts(bus, p);
1022 else {
1023 log_error("Invalid file type: %s (from %s)", p, argv[i])({ 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/mount/mount-tool.c", 1023, __func__, "Invalid file type: %s (from %s)"
, p, argv[i]) : -abs(_e); })
;
1024 r = -EINVAL22;
1025 }
1026
1027 if (r < 0)
1028 r2 = r;
1029 }
1030
1031 return r2;
1032}
1033
1034static int acquire_mount_type(struct udev_device *d) {
1035 const char *v;
1036
1037 assert(d)do { if ((__builtin_expect(!!(!(d)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("d"), "../src/mount/mount-tool.c", 1037,
__PRETTY_FUNCTION__); } while (0)
;
1038
1039 if (arg_mount_type)
1040 return 0;
1041
1042 v = udev_device_get_property_value(d, "ID_FS_TYPE");
1043 if (isempty(v))
1044 return 0;
1045
1046 arg_mount_type = strdup(v);
1047 if (!arg_mount_type)
1048 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1048, __func__)
;
1049
1050 log_debug("Discovered type=%s", arg_mount_type)({ 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/mount/mount-tool.c", 1050, __func__, "Discovered type=%s"
, arg_mount_type) : -abs(_e); })
;
1051 return 1;
1052}
1053
1054static int acquire_mount_options(struct udev_device *d) {
1055 const char *v;
1056
1057 if (arg_mount_options)
1058 return 0;
1059
1060 v = udev_device_get_property_value(d, "SYSTEMD_MOUNT_OPTIONS");
1061 if (isempty(v))
1062 return 0;
1063
1064 arg_mount_options = strdup(v);
1065 if (!arg_mount_options)
1066 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1066, __func__)
;
1067
1068 log_debug("Discovered options=%s", arg_mount_options)({ 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/mount/mount-tool.c", 1068, __func__, "Discovered options=%s"
, arg_mount_options) : -abs(_e); })
;
1069 return 1;
1070}
1071
1072static const char *get_model(struct udev_device *d) {
1073 const char *model;
1074
1075 assert(d)do { if ((__builtin_expect(!!(!(d)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("d"), "../src/mount/mount-tool.c", 1075,
__PRETTY_FUNCTION__); } while (0)
;
1076
1077 model = udev_device_get_property_value(d, "ID_MODEL_FROM_DATABASE");
1078 if (model)
1079 return model;
1080
1081 return udev_device_get_property_value(d, "ID_MODEL");
1082}
1083
1084static const char* get_label(struct udev_device *d) {
1085 const char *label;
1086
1087 assert(d)do { if ((__builtin_expect(!!(!(d)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("d"), "../src/mount/mount-tool.c", 1087,
__PRETTY_FUNCTION__); } while (0)
;
1088
1089 label = udev_device_get_property_value(d, "ID_FS_LABEL");
1090 if (label)
1091 return label;
1092
1093 return udev_device_get_property_value(d, "ID_PART_ENTRY_NAME");
1094}
1095
1096static int acquire_mount_where(struct udev_device *d) {
1097 const char *v;
1098
1099 if (arg_mount_where)
1100 return 0;
1101
1102 v = udev_device_get_property_value(d, "SYSTEMD_MOUNT_WHERE");
1103 if (isempty(v)) {
1104 _cleanup_free___attribute__((cleanup(freep))) char *escaped = NULL((void*)0);
1105 const char *name;
1106
1107 name = get_label(d);
1108 if (!name)
1109 name = get_model(d);
1110 if (!name) {
1111 const char *dn;
1112
1113 dn = udev_device_get_devnode(d);
1114 if (!dn)
1115 return 0;
1116
1117 name = basename(dn);
1118 }
1119
1120 escaped = xescape(name, "\\");
1121 if (!escaped)
1122 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1122, __func__)
;
1123 if (!filename_is_valid(escaped))
1124 return 0;
1125
1126 arg_mount_where = strjoin("/run/media/system/", escaped)strjoin_real(("/run/media/system/"), escaped, ((void*)0));
1127 } else
1128 arg_mount_where = strdup(v);
1129
1130 if (!arg_mount_where)
1131 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1131, __func__)
;
1132
1133 log_debug("Discovered where=%s", arg_mount_where)({ 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/mount/mount-tool.c", 1133, __func__, "Discovered where=%s"
, arg_mount_where) : -abs(_e); })
;
1134 return 1;
1135}
1136
1137static int acquire_mount_where_for_loop_dev(const char *loop_dev) {
1138 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **list = NULL((void*)0);
1139 int r;
1140
1141 if (arg_mount_where)
1142 return 0;
1143
1144 r = find_mount_points(loop_dev, &list);
1145 if (r < 0)
1146 return r;
1147 else if (r == 0) {
1148 log_error("Can't find mount point of %s. It is expected that %s is already mounted on a place.", loop_dev, loop_dev)({ 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/mount/mount-tool.c", 1148, __func__, "Can't find mount point of %s. It is expected that %s is already mounted on a place."
, loop_dev, loop_dev) : -abs(_e); })
;
1149 return -EINVAL22;
1150 } else if (r >= 2) {
1151 log_error("%s is mounted on %d places. It is expected that %s is mounted on a place.", loop_dev, r, loop_dev)({ 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/mount/mount-tool.c", 1151, __func__, "%s is mounted on %d places. It is expected that %s is mounted on a place."
, loop_dev, r, loop_dev) : -abs(_e); })
;
1152 return -EINVAL22;
1153 }
1154
1155 arg_mount_where = strdup(list[0]);
1156 if (!arg_mount_where)
1157 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1157, __func__)
;
1158
1159 log_debug("Discovered where=%s", arg_mount_where)({ 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/mount/mount-tool.c", 1159, __func__, "Discovered where=%s"
, arg_mount_where) : -abs(_e); })
;
1160 return 1;
1161}
1162
1163static int acquire_description(struct udev_device *d) {
1164 const char *model, *label;
1165
1166 if (arg_description)
1167 return 0;
1168
1169 model = get_model(d);
1170
1171 label = get_label(d);
1172 if (!label)
1173 label = udev_device_get_property_value(d, "ID_PART_ENTRY_NUMBER");
1174
1175 if (model && label)
1176 arg_description = strjoin(model, " ", label)strjoin_real((model), " ", label, ((void*)0));
1177 else if (label)
1178 arg_description = strdup(label);
1179 else if (model)
1180 arg_description = strdup(model);
1181 else
1182 return 0;
1183
1184 if (!arg_description)
1185 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1185, __func__)
;
1186
1187 log_debug("Discovered description=%s", arg_description)({ 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/mount/mount-tool.c", 1187, __func__, "Discovered description=%s"
, arg_description) : -abs(_e); })
;
1188 return 1;
1189}
1190
1191static int acquire_removable(struct udev_device *d) {
1192 const char *v;
1193
1194 /* Shortcut this if there's no reason to check it */
1195 if (arg_action != ACTION_DEFAULT && arg_timeout_idle_set && arg_bind_device >= 0)
1196 return 0;
1197
1198 for (;;) {
1199 v = udev_device_get_sysattr_value(d, "removable");
1200 if (v)
1201 break;
1202
1203 d = udev_device_get_parent(d);
1204 if (!d)
1205 return 0;
1206
1207 if (!streq_ptr(udev_device_get_subsystem(d), "block"))
1208 return 0;
1209 }
1210
1211 if (parse_boolean(v) <= 0)
1212 return 0;
1213
1214 log_debug("Discovered removable device.")({ 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/mount/mount-tool.c", 1214, __func__, "Discovered removable device."
) : -abs(_e); })
;
1215
1216 if (arg_action == ACTION_DEFAULT) {
1217 log_debug("Automatically turning on automount.")({ 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/mount/mount-tool.c", 1217, __func__, "Automatically turning on automount."
) : -abs(_e); })
;
1218 arg_action = ACTION_AUTOMOUNT;
1219 }
1220
1221 if (!arg_timeout_idle_set) {
1222 log_debug("Setting idle timeout to 1s.")({ 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/mount/mount-tool.c", 1222, __func__, "Setting idle timeout to 1s."
) : -abs(_e); })
;
1223 arg_timeout_idle = USEC_PER_SEC((usec_t) 1000000ULL);
1224 }
1225
1226 if (arg_bind_device < 0) {
1227 log_debug("Binding automount unit to device.")({ 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/mount/mount-tool.c", 1227, __func__, "Binding automount unit to device."
) : -abs(_e); })
;
1228 arg_bind_device = true1;
1229 }
1230
1231 return 1;
1232}
1233
1234static int discover_loop_backing_file(void) {
1235 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
1236 _cleanup_(udev_unrefp)__attribute__((cleanup(udev_unrefp))) struct udev *udev = NULL((void*)0);
1237 _cleanup_free___attribute__((cleanup(freep))) char *loop_dev = NULL((void*)0);
6
'loop_dev' initialized to a null pointer value
1238 struct stat st;
1239 const char *v;
1240 int r;
1241
1242 r = find_loop_device(arg_mount_what, &loop_dev);
7
Calling 'find_loop_device'
15
Returning from 'find_loop_device'
1243 if (r < 0 && r != -ENXIO6)
16
Assuming 'r' is >= 0
1244 return log_error_errno(errno, "Can't get loop device for %s: %m", arg_mount_what)({ 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/mount/mount-tool.c", 1244, __func__
, "Can't get loop device for %s: %m", arg_mount_what) : -abs(
_e); })
;
1245
1246 if (r == -ENXIO6) {
17
Taking false branch
1247 _cleanup_free___attribute__((cleanup(freep))) char *escaped = NULL((void*)0);
1248
1249 if (arg_mount_where)
1250 return 0;
1251
1252 escaped = xescape(basename(arg_mount_what), "\\");
1253 if (!escaped)
1254 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1254, __func__)
;
1255 if (!filename_is_valid(escaped)) {
1256 log_error("Escaped name %s is not a valid filename.", escaped)({ 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/mount/mount-tool.c", 1256, __func__, "Escaped name %s is not a valid filename."
, escaped) : -abs(_e); })
;
1257 return -EINVAL22;
1258 }
1259
1260 arg_mount_where = strjoin("/run/media/system/", escaped)strjoin_real(("/run/media/system/"), escaped, ((void*)0));
1261 if (!arg_mount_where)
1262 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1262, __func__)
;
1263
1264 log_debug("Discovered where=%s", arg_mount_where)({ 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/mount/mount-tool.c", 1264, __func__, "Discovered where=%s"
, arg_mount_where) : -abs(_e); })
;
1265 return 0;
1266 }
1267
1268 if (stat(loop_dev, &st) < 0)
18
Null pointer passed to 1st parameter expecting 'nonnull'
1269 return log_error_errno(errno, "Can't stat %s: %m", loop_dev)({ 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/mount/mount-tool.c", 1269, __func__
, "Can't stat %s: %m", loop_dev) : -abs(_e); })
;
1270
1271 if (!S_ISBLK(st.st_mode)((((st.st_mode)) & 0170000) == (0060000))) {
1272 log_error("Invalid file type: %s", loop_dev)({ 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/mount/mount-tool.c", 1272, __func__, "Invalid file type: %s"
, loop_dev) : -abs(_e); })
;
1273 return -EINVAL22;
1274 }
1275
1276 udev = udev_new();
1277 if (!udev)
1278 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1278, __func__)
;
1279
1280 d = udev_device_new_from_devnum(udev, 'b', st.st_rdev);
1281 if (!d)
1282 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1282, __func__)
;
1283
1284 v = udev_device_get_property_value(d, "ID_FS_USAGE");
1285 if (!streq_ptr(v, "filesystem")) {
1286 log_error("%s does not contain a known file system.", arg_mount_what)({ 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/mount/mount-tool.c", 1286, __func__, "%s does not contain a known file system."
, arg_mount_what) : -abs(_e); })
;
1287 return -EINVAL22;
1288 }
1289
1290 r = acquire_mount_type(d);
1291 if (r < 0)
1292 return r;
1293
1294 r = acquire_mount_options(d);
1295 if (r < 0)
1296 return r;
1297
1298 r = acquire_mount_where_for_loop_dev(loop_dev);
1299 if (r < 0)
1300 return r;
1301
1302 r = acquire_description(d);
1303 if (r < 0)
1304 return r;
1305
1306 return 0;
1307}
1308
1309static int discover_device(void) {
1310 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
1311 _cleanup_(udev_unrefp)__attribute__((cleanup(udev_unrefp))) struct udev *udev = NULL((void*)0);
1312 struct stat st;
1313 const char *v;
1314 int r;
1315
1316 if (stat(arg_mount_what, &st) < 0)
1
Assuming the condition is false
2
Taking false branch
1317 return log_error_errno(errno, "Can't stat %s: %m", arg_mount_what)({ 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/mount/mount-tool.c", 1317, __func__
, "Can't stat %s: %m", arg_mount_what) : -abs(_e); })
;
1318
1319 if (S_ISREG(st.st_mode)((((st.st_mode)) & 0170000) == (0100000)))
3
Assuming the condition is true
4
Taking true branch
1320 return discover_loop_backing_file();
5
Calling 'discover_loop_backing_file'
1321
1322 if (!S_ISBLK(st.st_mode)((((st.st_mode)) & 0170000) == (0060000))) {
1323 log_error("Invalid file type: %s", arg_mount_what)({ 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/mount/mount-tool.c", 1323, __func__, "Invalid file type: %s"
, arg_mount_what) : -abs(_e); })
;
1324 return -EINVAL22;
1325 }
1326
1327 udev = udev_new();
1328 if (!udev)
1329 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1329, __func__)
;
1330
1331 d = udev_device_new_from_devnum(udev, 'b', st.st_rdev);
1332 if (!d)
1333 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1333, __func__)
;
1334
1335 v = udev_device_get_property_value(d, "ID_FS_USAGE");
1336 if (!streq_ptr(v, "filesystem")) {
1337 log_error("%s does not contain a known file system.", arg_mount_what)({ 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/mount/mount-tool.c", 1337, __func__, "%s does not contain a known file system."
, arg_mount_what) : -abs(_e); })
;
1338 return -EINVAL22;
1339 }
1340
1341 r = acquire_mount_type(d);
1342 if (r < 0)
1343 return r;
1344
1345 r = acquire_mount_options(d);
1346 if (r < 0)
1347 return r;
1348
1349 r = acquire_mount_where(d);
1350 if (r < 0)
1351 return r;
1352
1353 r = acquire_description(d);
1354 if (r < 0)
1355 return r;
1356
1357 r = acquire_removable(d);
1358 if (r < 0)
1359 return r;
1360
1361 return 0;
1362}
1363
1364enum {
1365 COLUMN_NODE,
1366 COLUMN_PATH,
1367 COLUMN_MODEL,
1368 COLUMN_WWN,
1369 COLUMN_FSTYPE,
1370 COLUMN_LABEL,
1371 COLUMN_UUID,
1372 _COLUMN_MAX,
1373};
1374
1375struct item {
1376 char* columns[_COLUMN_MAX];
1377};
1378
1379static int compare_item(const void *a, const void *b) {
1380 const struct item *x = a, *y = b;
1381
1382 if (x->columns[COLUMN_NODE] == y->columns[COLUMN_NODE])
1383 return 0;
1384 if (!x->columns[COLUMN_NODE])
1385 return 1;
1386 if (!y->columns[COLUMN_NODE])
1387 return -1;
1388
1389 return path_compare(x->columns[COLUMN_NODE], y->columns[COLUMN_NODE]);
1390}
1391
1392static int list_devices(void) {
1393
1394 static const char * const titles[_COLUMN_MAX] = {
1395 [COLUMN_NODE] = "NODE",
1396 [COLUMN_PATH] = "PATH",
1397 [COLUMN_MODEL] = "MODEL",
1398 [COLUMN_WWN] = "WWN",
1399 [COLUMN_FSTYPE] = "TYPE",
1400 [COLUMN_LABEL] = "LABEL",
1401 [COLUMN_UUID] = "UUID"
1402 };
1403
1404 _cleanup_(udev_enumerate_unrefp)__attribute__((cleanup(udev_enumerate_unrefp))) struct udev_enumerate *e = NULL((void*)0);
1405 _cleanup_(udev_unrefp)__attribute__((cleanup(udev_unrefp))) struct udev *udev = NULL((void*)0);
1406 struct udev_list_entry *item = NULL((void*)0), *first = NULL((void*)0);
1407 size_t n_allocated = 0, n = 0, i;
1408 size_t column_width[_COLUMN_MAX];
1409 struct item *items = NULL((void*)0);
1410 unsigned c;
1411 int r;
1412
1413 for (c = 0; c < _COLUMN_MAX; c++)
1414 column_width[c] = strlen(titles[c]);
1415
1416 udev = udev_new();
1417 if (!udev)
1418 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1418, __func__)
;
1419
1420 e = udev_enumerate_new(udev);
1421 if (!e)
1422 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1422, __func__)
;
1423
1424 r = udev_enumerate_add_match_subsystem(e, "block");
1425 if (r < 0)
1426 return log_error_errno(r, "Failed to add block match: %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/mount/mount-tool.c", 1426, __func__, "Failed to add block match: %m"
) : -abs(_e); })
;
1427
1428 r = udev_enumerate_add_match_property(e, "ID_FS_USAGE", "filesystem");
1429 if (r < 0)
1430 return log_error_errno(r, "Failed to add property match: %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/mount/mount-tool.c", 1430, __func__, "Failed to add property match: %m"
) : -abs(_e); })
;
1431
1432 r = udev_enumerate_scan_devices(e);
1433 if (r < 0)
1434 return log_error_errno(r, "Failed to scan devices: %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/mount/mount-tool.c", 1434, __func__, "Failed to scan devices: %m"
) : -abs(_e); })
;
1435
1436 first = udev_enumerate_get_list_entry(e);
1437 udev_list_entry_foreach(item, first)for (item = first; item != ((void*)0); item = udev_list_entry_get_next
(item))
{
1438 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d;
1439 struct item *j;
1440
1441 d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
1442 if (!d) {
1443 r = log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1443, __func__)
;
1444 goto finish;
1445 }
1446
1447 if (!GREEDY_REALLOC0(items, n_allocated, n+1)greedy_realloc0((void**) &(items), &(n_allocated), (n
+1), sizeof((items)[0]))
) {
1448 r = log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1448, __func__)
;
1449 goto finish;
1450 }
1451
1452 j = items + n++;
1453
1454 for (c = 0; c < _COLUMN_MAX; c++) {
1455 const char *x = NULL((void*)0);
1456 size_t k;
1457
1458 switch (c) {
1459
1460 case COLUMN_NODE:
1461 x = udev_device_get_devnode(d);
1462 break;
1463
1464 case COLUMN_PATH:
1465 x = udev_device_get_property_value(d, "ID_PATH");
1466 break;
1467
1468 case COLUMN_MODEL:
1469 x = get_model(d);
1470 break;
1471
1472 case COLUMN_WWN:
1473 x = udev_device_get_property_value(d, "ID_WWN");
1474 break;
1475
1476 case COLUMN_FSTYPE:
1477 x = udev_device_get_property_value(d, "ID_FS_TYPE");
1478 break;
1479
1480 case COLUMN_LABEL:
1481 x = get_label(d);
1482 break;
1483
1484 case COLUMN_UUID:
1485 x = udev_device_get_property_value(d, "ID_FS_UUID");
1486 break;
1487 }
1488
1489 if (isempty(x))
1490 continue;
1491
1492 j->columns[c] = strdup(x);
1493 if (!j->columns[c]) {
1494 r = log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/mount/mount-tool.c"
, 1494, __func__)
;
1495 goto finish;
1496 }
1497
1498 k = strlen(x);
1499 if (k > column_width[c])
1500 column_width[c] = k;
1501 }
1502 }
1503
1504 if (n == 0) {
1505 log_info("No devices found.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/mount/mount-tool.c", 1505, __func__, "No devices found."
) : -abs(_e); })
;
1506 goto finish;
1507 }
1508
1509 qsort_safe(items, n, sizeof(struct item), compare_item);
1510
1511 (void) pager_open(arg_no_pager, false0);
1512
1513 fputs(ansi_underline(), stdoutstdout);
1514 for (c = 0; c < _COLUMN_MAX; c++) {
1515 if (c > 0)
1516 fputc(' ', stdoutstdout);
1517
1518 printf("%-*s", (int) column_width[c], titles[c]);
1519 }
1520 fputs(ansi_normal(), stdoutstdout);
1521 fputc('\n', stdoutstdout);
1522
1523 for (i = 0; i < n; i++) {
1524 for (c = 0; c < _COLUMN_MAX; c++) {
1525 if (c > 0)
1526 fputc(' ', stdoutstdout);
1527
1528 printf("%-*s", (int) column_width[c], strna(items[i].columns[c]));
1529 }
1530 fputc('\n', stdoutstdout);
1531 }
1532
1533 r = 0;
1534
1535finish:
1536 for (i = 0; i < n; i++)
1537 for (c = 0; c < _COLUMN_MAX; c++)
1538 free(items[i].columns[c]);
1539
1540 free(items);
1541 return r;
1542}
1543
1544int main(int argc, char* argv[]) {
1545 sd_bus *bus = NULL((void*)0);
1546 int r;
1547
1548 log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD);
1549 log_open();
1550
1551 r = parse_argv(argc, argv);
1552 if (r <= 0)
1553 goto finish;
1554
1555 if (arg_action == ACTION_LIST) {
1556 r = list_devices();
1557 goto finish;
1558 }
1559
1560 r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus);
1561 if (r < 0) {
1562 log_error_errno(r, "Failed to create bus connection: %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/mount/mount-tool.c", 1562, __func__, "Failed to create bus connection: %m"
) : -abs(_e); })
;
1563 goto finish;
1564 }
1565
1566 if (arg_action == ACTION_UMOUNT) {
1567 r = action_umount(bus, argc, argv);
1568 goto finish;
1569 }
1570
1571 if (!path_is_normalized(arg_mount_what)) {
1572 log_error("Path contains non-normalized components: %s", arg_mount_what)({ 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/mount/mount-tool.c", 1572, __func__, "Path contains non-normalized components: %s"
, arg_mount_what) : -abs(_e); })
;
1573 r = -EINVAL22;
1574 goto finish;
1575 }
1576
1577 if (arg_discover) {
1578 r = discover_device();
1579 if (r < 0)
1580 goto finish;
1581 }
1582
1583 if (!arg_mount_where) {
1584 log_error("Can't figure out where to mount %s.", arg_mount_what)({ 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/mount/mount-tool.c", 1584, __func__, "Can't figure out where to mount %s."
, arg_mount_what) : -abs(_e); })
;
1585 r = -EINVAL22;
1586 goto finish;
1587 }
1588
1589 if (path_equal(arg_mount_where, "/")) {
1590 log_error("Refusing to operate on root directory.")({ 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/mount/mount-tool.c", 1590, __func__, "Refusing to operate on root directory."
) : -abs(_e); })
;
1591 r = -EINVAL22;
1592 goto finish;
1593 }
1594
1595 if (!path_is_normalized(arg_mount_where)) {
1596 log_error("Path contains non-normalized components: %s", arg_mount_where)({ 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/mount/mount-tool.c", 1596, __func__, "Path contains non-normalized components: %s"
, arg_mount_where) : -abs(_e); })
;
1597 r = -EINVAL22;
1598 goto finish;
1599 }
1600
1601 if (streq_ptr(arg_mount_type, "auto"))
1602 arg_mount_type = mfree(arg_mount_type);
1603 if (streq_ptr(arg_mount_options, "defaults"))
1604 arg_mount_options = mfree(arg_mount_options);
1605
1606 if (!is_device_path(arg_mount_what))
1607 arg_fsck = false0;
1608
1609 if (arg_fsck && arg_mount_type && arg_transport == BUS_TRANSPORT_LOCAL) {
1610 r = fsck_exists(arg_mount_type);
1611 if (r < 0)
1612 log_warning_errno(r, "Couldn't determine whether fsck for %s exists, proceeding anyway.", arg_mount_type)({ 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/mount/mount-tool.c", 1612, __func__, "Couldn't determine whether fsck for %s exists, proceeding anyway."
, arg_mount_type) : -abs(_e); })
;
1613 else if (r == 0) {
1614 log_debug("Disabling file system check as fsck for %s doesn't exist.", arg_mount_type)({ 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/mount/mount-tool.c", 1614, __func__, "Disabling file system check as fsck for %s doesn't exist."
, arg_mount_type) : -abs(_e); })
;
1615 arg_fsck = false0; /* fsck doesn't exist, let's not attempt it */
1616 }
1617 }
1618
1619 /* The kernel (properly) refuses mounting file systems with unknown uid=,gid= options,
1620 * but not for all filesystem types. Let's try to catch the cases where the option
1621 * would be used if the file system does not support it. It is also possible to
1622 * autodetect the file system, but that's only possible with disk-based file systems
1623 * which incidentally seem to be implemented more carefully and reject unknown options,
1624 * so it's probably OK that we do the check only when the type is specified.
1625 */
1626 if (arg_mount_type &&
1627 !streq(arg_mount_type, "auto")(strcmp((arg_mount_type),("auto")) == 0) &&
1628 arg_uid != UID_INVALID((uid_t) -1) &&
1629 !fstype_can_uid_gid(arg_mount_type)) {
1630 log_error("File system type %s is not known to support uid=/gid=, refusing.",({ 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/mount/mount-tool.c", 1631, __func__, "File system type %s is not known to support uid=/gid=, refusing."
, arg_mount_type) : -abs(_e); })
1631 arg_mount_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/mount/mount-tool.c", 1631, __func__, "File system type %s is not known to support uid=/gid=, refusing."
, arg_mount_type) : -abs(_e); })
;
1632 r = -EOPNOTSUPP95;
1633 goto finish;
1634 }
1635
1636 switch (arg_action) {
1637
1638 case ACTION_MOUNT:
1639 case ACTION_DEFAULT:
1640 r = start_transient_mount(bus, argv + optind);
1641 break;
1642
1643 case ACTION_AUTOMOUNT:
1644 r = start_transient_automount(bus, argv + optind);
1645 break;
1646
1647 default:
1648 assert_not_reached("Unexpected action.")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, (
"Unexpected action."), "../src/mount/mount-tool.c", 1648, __PRETTY_FUNCTION__
); } while (0)
;
1649 }
1650
1651finish:
1652 /* make sure we terminate the bus connection first, and then close the
1653 * pager, see issue #3543 for the details. */
1654 bus = sd_bus_flush_close_unref(bus);
1655 pager_close();
1656
1657 free(arg_mount_what);
1658 free(arg_mount_where);
1659 free(arg_mount_type);
1660 free(arg_mount_options);
1661 free(arg_description);
1662 strv_free(arg_property);
1663 strv_free(arg_automount_property);
1664
1665 return r < 0 ? EXIT_FAILURE1 : EXIT_SUCCESS0;
1666}