summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-24 19:45:16 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-31 14:36:12 -0400
commite62d8c3944745ed276e6d4f33153009860e5cfc5 (patch)
treee7f70ed3b80581017b6340723ab6f1d6b9c30bad /src/core
parent3c8bed4ee061f96acb4d70a591a9849bddd2a659 (diff)
Modernization
Use _cleanup_ and wrap lines to ~80 chars and such.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/dbus-execute.c3
-rw-r--r--src/core/execute.c38
-rw-r--r--src/core/loopback-setup.c28
-rw-r--r--src/core/main.c22
-rw-r--r--src/core/manager.c22
-rw-r--r--src/core/mount.c6
-rw-r--r--src/core/umount.c8
7 files changed, 71 insertions, 56 deletions
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index 53394c25f4..0a53207e59 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -161,11 +161,12 @@ int bus_execute_append_cpu_sched_priority(DBusMessageIter *i, const char *proper
n = c->cpu_sched_priority;
else {
struct sched_param p;
- n = 0;
zero(p);
if (sched_getparam(0, &p) >= 0)
n = p.sched_priority;
+ else
+ n = 0;
}
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
diff --git a/src/core/execute.c b/src/core/execute.c
index 85edca17e3..f7353579e9 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1215,8 +1215,12 @@ int exec_spawn(ExecCommand *command,
zero(param);
param.sched_priority = context->cpu_sched_priority;
- if (sched_setscheduler(0, context->cpu_sched_policy |
- (context->cpu_sched_reset_on_fork ? SCHED_RESET_ON_FORK : 0), &param) < 0) {
+ r = sched_setscheduler(0,
+ context->cpu_sched_policy |
+ (context->cpu_sched_reset_on_fork ?
+ SCHED_RESET_ON_FORK : 0),
+ &param);
+ if (r < 0) {
err = -errno;
r = EXIT_SETSCHEDULER;
goto fail_child;
@@ -1437,7 +1441,8 @@ int exec_spawn(ExecCommand *command,
}
}
- if (!(our_env = new0(char*, 7))) {
+ our_env = new0(char*, 7);
+ if (!our_env) {
err = -ENOMEM;
r = EXIT_MEMORY;
goto fail_child;
@@ -1477,20 +1482,21 @@ int exec_spawn(ExecCommand *command,
assert(n_env <= 7);
- if (!(final_env = strv_env_merge(
- 5,
- environment,
- our_env,
- context->environment,
- files_env,
- pam_env,
- NULL))) {
+ final_env = strv_env_merge(5,
+ environment,
+ our_env,
+ context->environment,
+ files_env,
+ pam_env,
+ NULL);
+ if (!final_env) {
err = -ENOMEM;
r = EXIT_MEMORY;
goto fail_child;
}
- if (!(final_argv = replace_env_argv(argv, final_env))) {
+ final_argv = replace_env_argv(argv, final_env);
+ if (!final_argv) {
err = -ENOMEM;
r = EXIT_MEMORY;
goto fail_child;
@@ -1519,10 +1525,10 @@ int exec_spawn(ExecCommand *command,
}
log_struct_unit(LOG_DEBUG,
- unit_id,
- "MESSAGE=Forked %s as %lu",
- command->path, (unsigned long) pid,
- NULL);
+ unit_id,
+ "MESSAGE=Forked %s as %lu",
+ command->path, (unsigned long) pid,
+ NULL);
/* We add the new process to the cgroup both in the child (so
* that we can be sure that no user code is ever executed
diff --git a/src/core/loopback-setup.c b/src/core/loopback-setup.c
index 065b75a6e3..bfd0d93204 100644
--- a/src/core/loopback-setup.c
+++ b/src/core/loopback-setup.c
@@ -229,7 +229,8 @@ static int read_response(int fd, unsigned requests_max) {
}
static int check_loopback(void) {
- int r, fd;
+ int r;
+ int _cleanup_close_ fd;
union {
struct sockaddr sa;
struct sockaddr_in in;
@@ -251,8 +252,6 @@ static int check_loopback(void) {
else
r = errno == EADDRNOTAVAIL ? 0 : -errno;
- close_nointr_nofail(fd);
-
return r;
}
@@ -263,7 +262,7 @@ int loopback_setup(void) {
struct sockaddr_nl nl;
} sa;
unsigned requests = 0, i;
- int fd;
+ int _cleanup_close_ fd = -1;
bool eperm = false;
errno = 0;
@@ -279,16 +278,16 @@ int loopback_setup(void) {
sa.nl.nl_family = AF_NETLINK;
if (bind(fd, &sa.sa, sizeof(sa)) < 0) {
r = -errno;
- goto finish;
+ goto error;
}
r = add_adresses(fd, if_loopback, &requests);
if (r < 0)
- goto finish;
+ goto error;
r = start_interface(fd, if_loopback, &requests);
if (r < 0)
- goto finish;
+ goto error;
for (i = 0; i < requests; i++) {
r = read_response(fd, requests);
@@ -296,22 +295,17 @@ int loopback_setup(void) {
if (r == -EPERM)
eperm = true;
else if (r < 0)
- goto finish;
+ goto error;
}
if (eperm && check_loopback() < 0) {
r = -EPERM;
- goto finish;
+ goto error;
}
- r = 0;
-
-finish:
- if (r < 0)
- log_warning("Failed to configure loopback device: %s", strerror(-r));
-
- if (fd >= 0)
- close_nointr_nofail(fd);
+ return 0;
+error:
+ log_warning("Failed to configure loopback device: %s", strerror(-r));
return r;
}
diff --git a/src/core/main.c b/src/core/main.c
index 25f55fced2..bd7fc468b4 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -116,8 +116,10 @@ _noreturn_ static void crash(int sig) {
sa.sa_flags = SA_NOCLDSTOP|SA_RESTART;
assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
- if ((pid = fork()) < 0)
- log_error("Caught <%s>, cannot fork for core dump: %s", signal_to_string(sig), strerror(errno));
+ pid = fork();
+ if (pid < 0)
+ log_error("Caught <%s>, cannot fork for core dump: %s",
+ signal_to_string(sig), strerror(errno));
else if (pid == 0) {
struct rlimit rl;
@@ -147,12 +149,17 @@ _noreturn_ static void crash(int sig) {
int r;
/* Order things nicely. */
- if ((r = wait_for_terminate(pid, &status)) < 0)
- log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(-r));
+ r = wait_for_terminate(pid, &status);
+ if (r < 0)
+ log_error("Caught <%s>, waitpid() failed: %s",
+ signal_to_string(sig), strerror(-r));
else if (status.si_code != CLD_DUMPED)
- log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
+ log_error("Caught <%s>, core dump failed.",
+ signal_to_string(sig));
else
- log_error("Caught <%s>, dumped core as pid %lu.", signal_to_string(sig), (unsigned long) pid);
+ log_error("Caught <%s>, dumped core as pid %lu.",
+ signal_to_string(sig),
+ (unsigned long) pid);
}
}
@@ -183,7 +190,8 @@ _noreturn_ static void crash(int sig) {
_exit(1);
}
- log_info("Successfully spawned crash shell as pid %lu.", (unsigned long) pid);
+ log_info("Successfully spawned crash shell as pid %lu.",
+ (unsigned long) pid);
}
log_info("Freezing execution.");
diff --git a/src/core/manager.c b/src/core/manager.c
index a01710f445..8f4eb0b9c5 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -95,7 +95,7 @@ static int manager_setup_notify(Manager *m) {
struct sockaddr_un un;
} sa;
struct epoll_event ev;
- int one = 1;
+ int one = 1, r;
assert(m);
@@ -116,12 +116,15 @@ static int manager_setup_notify(Manager *m) {
sa.un.sun_path[0] = 0;
- if (bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
+ r = bind(m->notify_watch.fd, &sa.sa,
+ offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1));
+ if (r < 0) {
log_error("bind() failed: %m");
return -errno;
}
- if (setsockopt(m->notify_watch.fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) {
+ r = setsockopt(m->notify_watch.fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
+ if (r < 0) {
log_error("SO_PASSCRED failed: %m");
return -errno;
}
@@ -130,7 +133,8 @@ static int manager_setup_notify(Manager *m) {
ev.events = EPOLLIN;
ev.data.ptr = &m->notify_watch;
- if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev) < 0) {
+ r = epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev);
+ if (r < 0) {
log_error("Failed to add notification socket fd to epoll: %m");
return -errno;
}
@@ -1188,7 +1192,7 @@ static int manager_process_notify_fd(Manager *m) {
uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
} control;
Unit *u;
- char **tags;
+ char _cleanup_strv_free_ **tags = NULL;
zero(iovec);
iovec.iov_base = buf;
@@ -1226,7 +1230,8 @@ static int manager_process_notify_fd(Manager *m) {
if (!u) {
u = cgroup_unit_by_pid(m, ucred->pid);
if (!u) {
- log_warning("Cannot find unit for notify message of PID %lu.", (unsigned long) ucred->pid);
+ log_warning("Cannot find unit for notify message of PID %lu.",
+ (unsigned long) ucred->pid);
continue;
}
}
@@ -1241,8 +1246,6 @@ static int manager_process_notify_fd(Manager *m) {
if (UNIT_VTABLE(u)->notify_message)
UNIT_VTABLE(u)->notify_message(u, ucred->pid, tags);
-
- strv_free(tags);
}
return 0;
@@ -1898,7 +1901,8 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
/* We set SOCK_NONBLOCK here so that we rather drop the
* message then wait for plymouth */
- if ((fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) < 0) {
+ fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
+ if (fd < 0) {
log_error("socket() failed: %m");
return;
}
diff --git a/src/core/mount.c b/src/core/mount.c
index 7839300110..130dc39795 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -1710,7 +1710,8 @@ static int mount_enumerate(Manager *m) {
assert(m);
if (!m->proc_self_mountinfo) {
- if (!(m->proc_self_mountinfo = fopen("/proc/self/mountinfo", "re")))
+ m->proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
+ if (!m->proc_self_mountinfo)
return -errno;
m->mount_watch.type = WATCH_MOUNT;
@@ -1724,7 +1725,8 @@ static int mount_enumerate(Manager *m) {
return -errno;
}
- if ((r = mount_load_proc_self_mountinfo(m, false)) < 0)
+ r = mount_load_proc_self_mountinfo(m, false);
+ if (r < 0)
goto fail;
return 0;
diff --git a/src/core/umount.c b/src/core/umount.c
index 3fcb90eca4..95e47e3c5a 100644
--- a/src/core/umount.c
+++ b/src/core/umount.c
@@ -379,12 +379,14 @@ static int delete_loopback(const char *device) {
}
static int delete_dm(dev_t devnum) {
- int fd, r;
+ int _cleanup_close_ fd = -1;
+ int r;
struct dm_ioctl dm;
assert(major(devnum) != 0);
- if ((fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC)) < 0)
+ fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC);
+ if (fd < 0)
return -errno;
zero(dm);
@@ -396,8 +398,6 @@ static int delete_dm(dev_t devnum) {
dm.dev = devnum;
r = ioctl(fd, DM_DEV_REMOVE, &dm);
- close_nointr_nofail(fd);
-
return r >= 0 ? 0 : -errno;
}