summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-11-28 19:57:32 +0100
committerMichal Schmidt <mschmidt@redhat.com>2014-11-28 19:57:32 +0100
commit4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4f (patch)
treec7a6228e7151aa74bc8e331694a1e795226550cd /src/core
parent56f64d95763a799ba4475daf44d8e9f72a1bd474 (diff)
treewide: another round of simplifications
Using the same scripts as in f647962d64e "treewide: yet more log_*_errno + return simplifications".
Diffstat (limited to 'src/core')
-rw-r--r--src/core/automount.c6
-rw-r--r--src/core/cgroup.c18
-rw-r--r--src/core/dbus.c18
-rw-r--r--src/core/hostname-setup.c6
-rw-r--r--src/core/machine-id-setup.c6
-rw-r--r--src/core/main.c12
-rw-r--r--src/core/manager.c30
-rw-r--r--src/core/mount-setup.c6
-rw-r--r--src/core/namespace.c6
-rw-r--r--src/core/path.c12
-rw-r--r--src/core/selinux-access.c6
-rw-r--r--src/core/shutdown.c12
12 files changed, 46 insertions, 92 deletions
diff --git a/src/core/automount.c b/src/core/automount.c
index 8814d4c4f..f79548713 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -300,10 +300,8 @@ static int open_dev_autofs(Manager *m) {
label_fix("/dev/autofs", false, false);
m->dev_autofs_fd = open("/dev/autofs", O_CLOEXEC|O_RDONLY);
- if (m->dev_autofs_fd < 0) {
- log_error_errno(errno, "Failed to open /dev/autofs: %m");
- return -errno;
- }
+ if (m->dev_autofs_fd < 0)
+ return log_error_errno(errno, "Failed to open /dev/autofs: %m");
init_autofs_dev_ioctl(&param);
if (ioctl(m->dev_autofs_fd, AUTOFS_DEV_IOCTL_VERSION, &param) < 0) {
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 382e6a6cc..70fc925b4 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -153,10 +153,8 @@ static int lookup_blkio_device(const char *p, dev_t *dev) {
assert(dev);
r = stat(p, &st);
- if (r < 0) {
- log_warning_errno(errno, "Couldn't stat device %s: %m", p);
- return -errno;
- }
+ if (r < 0)
+ return log_warning_errno(errno, "Couldn't stat device %s: %m", p);
if (S_ISBLK(st.st_mode))
*dev = st.st_rdev;
@@ -218,10 +216,8 @@ static int whitelist_major(const char *path, const char *name, char type, const
assert(type == 'b' || type == 'c');
f = fopen("/proc/devices", "re");
- if (!f) {
- log_warning_errno(errno, "Cannot open /proc/devices to resolve %s (%c): %m", name, type);
- return -errno;
- }
+ if (!f)
+ return log_warning_errno(errno, "Cannot open /proc/devices to resolve %s (%c): %m", name, type);
FOREACH_LINE(line, f, goto fail) {
char buf[2+DECIMAL_STR_MAX(unsigned)+3+4], *p, *w;
@@ -905,10 +901,8 @@ int manager_setup_cgroup(Manager *m) {
safe_close(m->pin_cgroupfs_fd);
m->pin_cgroupfs_fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY|O_NONBLOCK);
- if (m->pin_cgroupfs_fd < 0) {
- log_error_errno(errno, "Failed to open pin file: %m");
- return -errno;
- }
+ if (m->pin_cgroupfs_fd < 0)
+ return log_error_errno(errno, "Failed to open pin file: %m");
/* 6. Always enable hierarchial support if it exists... */
cg_set_attribute("memory", "/", "memory.use_hierarchy", "1");
diff --git a/src/core/dbus.c b/src/core/dbus.c
index 925fac96b..79cf414ee 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -958,22 +958,16 @@ static int bus_init_private(Manager *m) {
(void) unlink(sa.un.sun_path);
fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
- if (fd < 0) {
- log_error_errno(errno, "Failed to allocate private socket: %m");
- return -errno;
- }
+ if (fd < 0)
+ return log_error_errno(errno, "Failed to allocate private socket: %m");
r = bind(fd, &sa.sa, salen);
- if (r < 0) {
- log_error_errno(errno, "Failed to bind private socket: %m");
- return -errno;
- }
+ if (r < 0)
+ return log_error_errno(errno, "Failed to bind private socket: %m");
r = listen(fd, SOMAXCONN);
- if (r < 0) {
- log_error_errno(errno, "Failed to make private socket listening: %m");
- return -errno;
- }
+ if (r < 0)
+ return log_error_errno(errno, "Failed to make private socket listening: %m");
r = sd_event_add_io(m->event, &s, fd, EPOLLIN, bus_on_connection, m);
if (r < 0)
diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c
index 72e4c539e..6664e8952 100644
--- a/src/core/hostname-setup.c
+++ b/src/core/hostname-setup.c
@@ -82,10 +82,8 @@ int hostname_setup(void) {
hn = "localhost";
}
- if (sethostname_idempotent(hn) < 0) {
- log_warning_errno(errno, "Failed to set hostname to <%s>: %m", hn);
- return -errno;
- }
+ if (sethostname_idempotent(hn) < 0)
+ return log_warning_errno(errno, "Failed to set hostname to <%s>: %m", hn);
log_info("Set hostname to <%s>.", hn);
return 0;
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index f31e357f1..671003820 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -204,10 +204,8 @@ int machine_id_setup(const char *root) {
}
}
- if (fstat(fd, &st) < 0) {
- log_error_errno(errno, "fstat() failed: %m");
- return -errno;
- }
+ if (fstat(fd, &st) < 0)
+ return log_error_errno(errno, "fstat() failed: %m");
if (S_ISREG(st.st_mode))
if (loop_read(fd, id, 33, false) == 33 && id[32] == '\n') {
diff --git a/src/core/main.c b/src/core/main.c
index d8a1ab9d4..c9fd56232 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -884,10 +884,8 @@ static int parse_argv(int argc, char *argv[]) {
fd_cloexec(fd, true);
f = fdopen(fd, "r");
- if (!f) {
- log_error_errno(errno, "Failed to open serialization fd: %m");
- return -errno;
- }
+ if (!f)
+ return log_error_errno(errno, "Failed to open serialization fd: %m");
if (arg_serialization)
fclose(arg_serialization);
@@ -1045,10 +1043,8 @@ static int bump_rlimit_nofile(struct rlimit *saved_rlimit) {
/* Save the original RLIMIT_NOFILE so that we can reset it
* later when transitioning from the initrd to the main
* systemd or suchlike. */
- if (getrlimit(RLIMIT_NOFILE, saved_rlimit) < 0) {
- log_error_errno(errno, "Reading RLIMIT_NOFILE failed: %m");
- return -errno;
- }
+ if (getrlimit(RLIMIT_NOFILE, saved_rlimit) < 0)
+ return log_error_errno(errno, "Reading RLIMIT_NOFILE failed: %m");
/* Make sure forked processes get the default kernel setting */
if (!arg_default_rlimit[RLIMIT_NOFILE]) {
diff --git a/src/core/manager.c b/src/core/manager.c
index 3798ab2d5..3e1728f92 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -262,10 +262,8 @@ static int manager_check_ask_password(Manager *m) {
mkdir_p_label("/run/systemd/ask-password", 0755);
m->ask_password_inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
- if (m->ask_password_inotify_fd < 0) {
- log_error_errno(errno, "inotify_init1() failed: %m");
- return -errno;
- }
+ if (m->ask_password_inotify_fd < 0)
+ return log_error_errno(errno, "inotify_init1() failed: %m");
if (inotify_add_watch(m->ask_password_inotify_fd, "/run/systemd/ask-password", IN_CREATE|IN_DELETE|IN_MOVE) < 0) {
log_error_errno(errno, "Failed to add watch on /run/systemd/ask-password: %m");
@@ -334,10 +332,8 @@ static int manager_setup_time_change(Manager *m) {
* CLOCK_REALTIME makes a jump relative to CLOCK_MONOTONIC */
m->time_change_fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC);
- if (m->time_change_fd < 0) {
- log_error_errno(errno, "Failed to create timerfd: %m");
- return -errno;
- }
+ if (m->time_change_fd < 0)
+ return log_error_errno(errno, "Failed to create timerfd: %m");
if (timerfd_settime(m->time_change_fd, TFD_TIMER_ABSTIME|TFD_TIMER_CANCEL_ON_SET, &its, NULL) < 0) {
log_debug_errno(errno, "Failed to set up TFD_TIMER_CANCEL_ON_SET, ignoring: %m");
@@ -647,10 +643,8 @@ static int manager_setup_notify(Manager *m) {
m->notify_event_source = sd_event_source_unref(m->notify_event_source);
fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
- if (fd < 0) {
- log_error_errno(errno, "Failed to allocate notification socket: %m");
- return -errno;
- }
+ if (fd < 0)
+ return log_error_errno(errno, "Failed to allocate notification socket: %m");
if (m->running_as == SYSTEMD_SYSTEM)
m->notify_socket = strdup("/run/systemd/notify");
@@ -673,16 +667,12 @@ static int manager_setup_notify(Manager *m) {
strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path)-1);
r = bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
- if (r < 0) {
- log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
- return -errno;
- }
+ if (r < 0)
+ return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
r = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
- if (r < 0) {
- log_error_errno(errno, "SO_PASSCRED failed: %m");
- return -errno;
- }
+ if (r < 0)
+ return log_error_errno(errno, "SO_PASSCRED failed: %m");
m->notify_fd = fd;
fd = -1;
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index d319a1518..342f5520c 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -340,10 +340,8 @@ int mount_cgroup_controllers(char ***join_controllers) {
return log_oom();
r = symlink(options, t);
- if (r < 0 && errno != EEXIST) {
- log_error_errno(errno, "Failed to create symlink %s: %m", t);
- return -errno;
- }
+ if (r < 0 && errno != EEXIST)
+ return log_error_errno(errno, "Failed to create symlink %s: %m", t);
}
}
}
diff --git a/src/core/namespace.c b/src/core/namespace.c
index 32338cdc6..4c411096a 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -276,10 +276,8 @@ static int mount_kdbus(BindMount *m) {
u = umask(0000);
- if (!mkdtemp(temporary_mount)) {
- log_error_errno(errno, "Failed create temp dir: %m");
- return -errno;
- }
+ if (!mkdtemp(temporary_mount))
+ return log_error_errno(errno, "Failed create temp dir: %m");
root = strappenda(temporary_mount, "/kdbus");
(void)mkdir(root, 0755);
diff --git a/src/core/path.c b/src/core/path.c
index ed03635a4..3624bfcac 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -168,10 +168,8 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) {
return -EINVAL;
}
- if (ioctl(s->inotify_fd, FIONREAD, &l) < 0) {
- log_error_errno(errno, "FIONREAD failed: %m");
- return -errno;
- }
+ if (ioctl(s->inotify_fd, FIONREAD, &l) < 0)
+ return log_error_errno(errno, "FIONREAD failed: %m");
assert(l > 0);
@@ -180,10 +178,8 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) {
return log_oom();
k = read(s->inotify_fd, buf, l);
- if (k < 0) {
- log_error_errno(errno, "Failed to read inotify event: %m");
- return -errno;
- }
+ if (k < 0)
+ return log_error_errno(errno, "Failed to read inotify event: %m");
e = (struct inotify_event*) buf;
diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
index 0ec80a1b3..b45a4513e 100644
--- a/src/core/selinux-access.c
+++ b/src/core/selinux-access.c
@@ -126,10 +126,8 @@ _printf_(2, 3) static int log_callback(int type, const char *fmt, ...) {
static int access_init(void) {
int r = 0;
- if (avc_open(NULL, 0)) {
- log_error_errno(errno, "avc_open() failed: %m");
- return -errno;
- }
+ if (avc_open(NULL, 0))
+ return log_error_errno(errno, "avc_open() failed: %m");
selinux_set_callback(SELINUX_CB_AUDIT, (union selinux_callback) audit_callback);
selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback) log_callback);
diff --git a/src/core/shutdown.c b/src/core/shutdown.c
index 10455fa30..2cd0bce2f 100644
--- a/src/core/shutdown.c
+++ b/src/core/shutdown.c
@@ -138,15 +138,11 @@ static int parse_argv(int argc, char *argv[]) {
}
static int switch_root_initramfs(void) {
- if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) {
- log_error_errno(errno, "Failed to mount bind /run/initramfs on /run/initramfs: %m");
- return -errno;
- }
+ if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0)
+ return log_error_errno(errno, "Failed to mount bind /run/initramfs on /run/initramfs: %m");
- if (mount(NULL, "/run/initramfs", NULL, MS_PRIVATE, NULL) < 0) {
- log_error_errno(errno, "Failed to make /run/initramfs private mount: %m");
- return -errno;
- }
+ if (mount(NULL, "/run/initramfs", NULL, MS_PRIVATE, NULL) < 0)
+ return log_error_errno(errno, "Failed to make /run/initramfs private mount: %m");
/* switch_root with MS_BIND, because there might still be processes lurking around, which have open file desriptors.
* /run/initramfs/shutdown will take care of these.