diff options
author | Frantisek Sumsal <frantisek@sumsal.cz> | 2020-10-09 14:59:44 +0200 |
---|---|---|
committer | Frantisek Sumsal <frantisek@sumsal.cz> | 2020-10-09 15:02:23 +0200 |
commit | d7a0f1f4f9910a1a2d290e31b2ba8cfa7126fbdd (patch) | |
tree | f519b20cb0835f71bd553abeca761882cad3299b /src/mount/mount-tool.c | |
parent | 44e66de0f25e65d5bd8b2f7f848e0fc7b98199ed (diff) | |
download | systemd-d7a0f1f4f9910a1a2d290e31b2ba8cfa7126fbdd.tar.gz |
tree-wide: assorted coccinelle fixes
Diffstat (limited to 'src/mount/mount-tool.c')
-rw-r--r-- | src/mount/mount-tool.c | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index 22da189684..9e57033999 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -923,10 +923,9 @@ static int umount_by_device(sd_bus *bus, const char *what) { if (stat(what, &st) < 0) return log_error_errno(errno, "Can't stat %s: %m", what); - if (!S_ISBLK(st.st_mode)) { - log_error("Not a block device: %s", what); - return -ENOTBLK; - } + if (!S_ISBLK(st.st_mode)) + return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK), + "Not a block device: %s", what); r = sd_device_new_from_devnum(&d, 'b', st.st_rdev); if (r < 0) @@ -1249,10 +1248,10 @@ static int discover_loop_backing_file(void) { escaped = xescape(basename(arg_mount_what), "\\"); if (!escaped) return log_oom(); - if (!filename_is_valid(escaped)) { - log_error("Escaped name %s is not a valid filename.", escaped); - return -EINVAL; - } + if (!filename_is_valid(escaped)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Escaped name %s is not a valid filename.", + escaped); arg_mount_where = path_join("/run/media/system", escaped); if (!arg_mount_where) @@ -1265,10 +1264,9 @@ static int discover_loop_backing_file(void) { if (stat(loop_dev, &st) < 0) return log_error_errno(errno, "Can't stat %s: %m", loop_dev); - if (!S_ISBLK(st.st_mode)) { - log_error("Invalid file type: %s", loop_dev); - return -EINVAL; - } + if (!S_ISBLK(st.st_mode)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid file type: %s", loop_dev); r = sd_device_new_from_devnum(&d, 'b', st.st_rdev); if (r < 0) @@ -1309,19 +1307,19 @@ static int discover_device(void) { if (S_ISREG(st.st_mode)) return discover_loop_backing_file(); - if (!S_ISBLK(st.st_mode)) { - log_error("Invalid file type: %s", arg_mount_what); - return -EINVAL; - } + if (!S_ISBLK(st.st_mode)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid file type: %s", + arg_mount_what); r = sd_device_new_from_devnum(&d, 'b', st.st_rdev); if (r < 0) return log_error_errno(r, "Failed to get device from device number: %m"); - if (sd_device_get_property_value(d, "ID_FS_USAGE", &v) < 0 || !streq(v, "filesystem")) { - log_error("%s does not contain a known file system.", arg_mount_what); - return -EINVAL; - } + if (sd_device_get_property_value(d, "ID_FS_USAGE", &v) < 0 || !streq(v, "filesystem")) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "%s does not contain a known file system.", + arg_mount_what); r = acquire_mount_type(d); if (r < 0) @@ -1462,10 +1460,10 @@ static int run(int argc, char* argv[]) { return action_umount(bus, argc, argv); if ((!arg_mount_type || fstype_is_blockdev_backed(arg_mount_type)) - && !path_is_normalized(arg_mount_what)) { - log_error("Path contains non-normalized components: %s", arg_mount_what); - return -EINVAL; - } + && !path_is_normalized(arg_mount_what)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Path contains non-normalized components: %s", + arg_mount_what); if (arg_discover) { r = discover_device(); @@ -1473,20 +1471,19 @@ static int run(int argc, char* argv[]) { return r; } - if (!arg_mount_where) { - log_error("Can't figure out where to mount %s.", arg_mount_what); - return -EINVAL; - } + if (!arg_mount_where) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Can't figure out where to mount %s.", + arg_mount_what); - if (path_equal(arg_mount_where, "/")) { - log_error("Refusing to operate on root directory."); - return -EINVAL; - } + if (path_equal(arg_mount_where, "/")) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Refusing to operate on root directory."); - if (!path_is_normalized(arg_mount_where)) { - log_error("Path contains non-normalized components: %s", arg_mount_where); - return -EINVAL; - } + if (!path_is_normalized(arg_mount_where)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Path contains non-normalized components: %s", + arg_mount_where); if (streq_ptr(arg_mount_type, "auto")) arg_mount_type = mfree(arg_mount_type); @@ -1516,11 +1513,10 @@ static int run(int argc, char* argv[]) { if (arg_mount_type && !streq(arg_mount_type, "auto") && arg_uid != UID_INVALID && - !fstype_can_uid_gid(arg_mount_type)) { - log_error("File system type %s is not known to support uid=/gid=, refusing.", - arg_mount_type); - return -EOPNOTSUPP; - } + !fstype_can_uid_gid(arg_mount_type)) + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), + "File system type %s is not known to support uid=/gid=, refusing.", + arg_mount_type); switch (arg_action) { |