diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2014-11-28 19:57:32 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2014-11-28 19:57:32 +0100 |
commit | 4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4f (patch) | |
tree | c7a6228e7151aa74bc8e331694a1e795226550cd /src/shared | |
parent | 56f64d95763a799ba4475daf44d8e9f72a1bd474 (diff) |
treewide: another round of simplifications
Using the same scripts as in f647962d64e "treewide: yet more log_*_errno
+ return simplifications".
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/ask-password-api.c | 6 | ||||
-rw-r--r-- | src/shared/base-filesystem.c | 18 | ||||
-rw-r--r-- | src/shared/capability.c | 36 | ||||
-rw-r--r-- | src/shared/generator.c | 6 | ||||
-rw-r--r-- | src/shared/pager.c | 18 | ||||
-rw-r--r-- | src/shared/socket-util.c | 6 | ||||
-rw-r--r-- | src/shared/switch-root.c | 30 | ||||
-rw-r--r-- | src/shared/watchdog.c | 30 |
8 files changed, 50 insertions, 100 deletions
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 41049d79bd..d6589a67f6 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -258,10 +258,8 @@ static int create_socket(char **name) { assert(name); fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); - if (fd < 0) { - log_error_errno(errno, "socket() failed: %m"); - return -errno; - } + if (fd < 0) + return log_error_errno(errno, "socket() failed: %m"); snprintf(sa.un.sun_path, sizeof(sa.un.sun_path)-1, "/run/systemd/ask-password/sck.%" PRIx64, random_u64()); diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index b1f1f4190e..73907c6354 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -58,10 +58,8 @@ int base_filesystem_create(const char *root) { int r; fd = open(root, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW); - if (fd < 0) { - log_error_errno(errno, "Failed to open root file system: %m"); - return -errno; - } + if (fd < 0) + return log_error_errno(errno, "Failed to open root file system: %m"); for (i = 0; i < ELEMENTSOF(table); i ++) { if (faccessat(fd, table[i].dir, F_OK, AT_SYMLINK_NOFOLLOW) >= 0) @@ -95,19 +93,15 @@ int base_filesystem_create(const char *root) { continue; r = symlinkat(target, fd, table[i].dir); - if (r < 0 && errno != EEXIST) { - log_error_errno(errno, "Failed to create symlink at %s/%s: %m", root, table[i].dir); - return -errno; - } + if (r < 0 && errno != EEXIST) + return log_error_errno(errno, "Failed to create symlink at %s/%s: %m", root, table[i].dir); continue; } RUN_WITH_UMASK(0000) r = mkdirat(fd, table[i].dir, table[i].mode); - if (r < 0 && errno != EEXIST) { - log_error_errno(errno, "Failed to create directory at %s/%s: %m", root, table[i].dir); - return -errno; - } + if (r < 0 && errno != EEXIST) + return log_error_errno(errno, "Failed to create directory at %s/%s: %m", root, table[i].dir); } return 0; diff --git a/src/shared/capability.c b/src/shared/capability.c index e2e0dd1a33..5d156ab3cd 100644 --- a/src/shared/capability.c +++ b/src/shared/capability.c @@ -227,31 +227,21 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) { * binary has the capability configured in the file system, * which we want to avoid. */ - if (setresgid(gid, gid, gid) < 0) { - log_error_errno(errno, "Failed to change group ID: %m"); - return -errno; - } + if (setresgid(gid, gid, gid) < 0) + return log_error_errno(errno, "Failed to change group ID: %m"); - if (setgroups(0, NULL) < 0) { - log_error_errno(errno, "Failed to drop auxiliary groups list: %m"); - return -errno; - } + if (setgroups(0, NULL) < 0) + return log_error_errno(errno, "Failed to drop auxiliary groups list: %m"); - if (prctl(PR_SET_KEEPCAPS, 1) < 0) { - log_error_errno(errno, "Failed to enable keep capabilities flag: %m"); - return -errno; - } + if (prctl(PR_SET_KEEPCAPS, 1) < 0) + return log_error_errno(errno, "Failed to enable keep capabilities flag: %m"); r = setresuid(uid, uid, uid); - if (r < 0) { - log_error_errno(errno, "Failed to change user ID: %m"); - return -errno; - } + if (r < 0) + return log_error_errno(errno, "Failed to change user ID: %m"); - if (prctl(PR_SET_KEEPCAPS, 0) < 0) { - log_error_errno(errno, "Failed to disable keep capabilities flag: %m"); - return -errno; - } + if (prctl(PR_SET_KEEPCAPS, 0) < 0) + return log_error_errno(errno, "Failed to disable keep capabilities flag: %m"); r = capability_bounding_set_drop(~keep_capabilities, true); if (r < 0) @@ -276,10 +266,8 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) { } } - if (cap_set_proc(d) < 0) { - log_error_errno(errno, "Failed to increase capabilities: %m"); - return -errno; - } + if (cap_set_proc(d) < 0) + return log_error_errno(errno, "Failed to increase capabilities: %m"); return 0; } diff --git a/src/shared/generator.c b/src/shared/generator.c index 01229d8d71..465e5f6cc8 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -64,10 +64,8 @@ int generator_write_fsck_deps( lnk = strappenda(dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service"); mkdir_parents(lnk, 0755); - if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) { - log_error_errno(errno, "Failed to create symlink %s: %m", lnk); - return -errno; - } + if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) + return log_error_errno(errno, "Failed to create symlink %s: %m", lnk); } else { _cleanup_free_ char *fsck = NULL; diff --git a/src/shared/pager.c b/src/shared/pager.c index 2863940725..a9f2b7e4f4 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -67,10 +67,8 @@ int pager_open(bool jump_to_end) { * pager so that we get the value from the actual tty */ columns(); - if (pipe(fd) < 0) { - log_error_errno(errno, "Failed to create pager pipe: %m"); - return -errno; - } + if (pipe(fd) < 0) + return log_error_errno(errno, "Failed to create pager pipe: %m"); parent_pid = getpid(); @@ -126,10 +124,8 @@ int pager_open(bool jump_to_end) { } /* Return in the parent */ - if (dup2(fd[1], STDOUT_FILENO) < 0) { - log_error_errno(errno, "Failed to duplicate pager pipe: %m"); - return -errno; - } + if (dup2(fd[1], STDOUT_FILENO) < 0) + return log_error_errno(errno, "Failed to duplicate pager pipe: %m"); safe_close_pair(fd); return 1; @@ -176,10 +172,8 @@ int show_man_page(const char *desc, bool null_stdio) { args[1] = desc; pid = fork(); - if (pid < 0) { - log_error_errno(errno, "Failed to fork: %m"); - return -errno; - } + if (pid < 0) + return log_error_errno(errno, "Failed to fork: %m"); if (pid == 0) { /* Child */ diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c index b5b001a6f2..c6f64876be 100644 --- a/src/shared/socket-util.c +++ b/src/shared/socket-util.c @@ -657,10 +657,8 @@ int getnameinfo_pretty(int fd, char **ret) { assert(fd >= 0); assert(ret); - if (getsockname(fd, &sa.sa, &salen) < 0) { - log_error_errno(errno, "getsockname(%d) failed: %m", fd); - return -errno; - } + if (getsockname(fd, &sa.sa, &salen) < 0) + return log_error_errno(errno, "getsockname(%d) failed: %m", fd); return socknameinfo_pretty(&sa, salen, ret); } diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index c5b635d17d..ca3875628a 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -56,10 +56,8 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, old_root_remove = in_initrd(); - if (stat(new_root, &new_root_stat) < 0) { - log_error_errno(errno, "Failed to stat directory %s: %m", new_root); - return -errno; - } + if (stat(new_root, &new_root_stat) < 0) + return log_error_errno(errno, "Failed to stat directory %s: %m", new_root); /* Work-around for kernel design: the kernel refuses switching * root if any file systems are mounted MS_SHARED. Hence @@ -109,10 +107,8 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, * switch_root() nevertheless. */ (void) base_filesystem_create(new_root); - if (chdir(new_root) < 0) { - log_error_errno(errno, "Failed to change directory to %s: %m", new_root); - return -errno; - } + if (chdir(new_root) < 0) + return log_error_errno(errno, "Failed to change directory to %s: %m", new_root); if (old_root_remove) { old_root_fd = open("/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY|O_DIRECTORY); @@ -132,20 +128,14 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, oldroot, errno == ENOENT ? "ignoring" : "leaving it around"); - } else if (mount(new_root, "/", NULL, MS_MOVE, NULL) < 0) { - log_error_errno(errno, "Failed to mount moving %s to /: %m", new_root); - return -errno; - } + } else if (mount(new_root, "/", NULL, MS_MOVE, NULL) < 0) + return log_error_errno(errno, "Failed to mount moving %s to /: %m", new_root); - if (chroot(".") < 0) { - log_error_errno(errno, "Failed to change root: %m"); - return -errno; - } + if (chroot(".") < 0) + return log_error_errno(errno, "Failed to change root: %m"); - if (chdir("/") < 0) { - log_error_errno(errno, "Failed to change directory: %m"); - return -errno; - } + if (chdir("/") < 0) + return log_error_errno(errno, "Failed to change directory: %m"); if (old_root_fd >= 0) { struct stat rb; diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index 386751418e..2fe4eb81cf 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -44,36 +44,28 @@ static int update_timeout(void) { flags = WDIOS_DISABLECARD; r = ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags); - if (r < 0) { - log_warning_errno(errno, "Failed to disable hardware watchdog: %m"); - return -errno; - } + if (r < 0) + return log_warning_errno(errno, "Failed to disable hardware watchdog: %m"); } else { int sec, flags; char buf[FORMAT_TIMESPAN_MAX]; sec = (int) ((watchdog_timeout + USEC_PER_SEC - 1) / USEC_PER_SEC); r = ioctl(watchdog_fd, WDIOC_SETTIMEOUT, &sec); - if (r < 0) { - log_warning_errno(errno, "Failed to set timeout to %is: %m", sec); - return -errno; - } + if (r < 0) + return log_warning_errno(errno, "Failed to set timeout to %is: %m", sec); watchdog_timeout = (usec_t) sec * USEC_PER_SEC; log_info("Set hardware watchdog to %s.", format_timespan(buf, sizeof(buf), watchdog_timeout, 0)); flags = WDIOS_ENABLECARD; r = ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags); - if (r < 0) { - log_warning_errno(errno, "Failed to enable hardware watchdog: %m"); - return -errno; - } + if (r < 0) + return log_warning_errno(errno, "Failed to enable hardware watchdog: %m"); r = ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0); - if (r < 0) { - log_warning_errno(errno, "Failed to ping hardware watchdog: %m"); - return -errno; - } + if (r < 0) + return log_warning_errno(errno, "Failed to ping hardware watchdog: %m"); } return 0; @@ -127,10 +119,8 @@ int watchdog_ping(void) { } r = ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0); - if (r < 0) { - log_warning_errno(errno, "Failed to ping hardware watchdog: %m"); - return -errno; - } + if (r < 0) + return log_warning_errno(errno, "Failed to ping hardware watchdog: %m"); return 0; } |