mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
treewide: apply errno.cocci
with small manual cleanups for style.
This commit is contained in:
parent
b3e3bb19a0
commit
e1427b138f
@ -278,10 +278,8 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
|
||||
assert(keep_capabilities & (1ULL << (i - 1)));
|
||||
|
||||
if (cap_set_flag(d, CAP_EFFECTIVE, j, bits, CAP_SET) < 0 ||
|
||||
cap_set_flag(d, CAP_PERMITTED, j, bits, CAP_SET) < 0) {
|
||||
log_error_errno(errno, "Failed to enable capabilities bits: %m");
|
||||
return -errno;
|
||||
}
|
||||
cap_set_flag(d, CAP_PERMITTED, j, bits, CAP_SET) < 0)
|
||||
return log_error_errno(errno, "Failed to enable capabilities bits: %m");
|
||||
|
||||
if (cap_set_proc(d) < 0)
|
||||
return log_error_errno(errno, "Failed to increase capabilities: %m");
|
||||
|
@ -94,8 +94,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
|
||||
if (feof(f))
|
||||
break;
|
||||
|
||||
log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
|
||||
}
|
||||
|
||||
p = strstrip(l);
|
||||
|
@ -227,8 +227,7 @@ static int parse_dbus_fragments(const char *path, const char *type) {
|
||||
if (errno == -ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to enumerate D-Bus activated services: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to enumerate D-Bus activated services: %m");
|
||||
}
|
||||
|
||||
r = 0;
|
||||
@ -246,8 +245,7 @@ static int parse_dbus_fragments(const char *path, const char *type) {
|
||||
return r;
|
||||
|
||||
fail:
|
||||
log_error_errno(errno, "Failed to read D-Bus services directory: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to read D-Bus services directory: %m");
|
||||
}
|
||||
|
||||
static int link_busnames_target(const char *units) {
|
||||
|
@ -319,8 +319,7 @@ static int enumerate_dir(Hashmap *top, Hashmap *bottom, Hashmap *drops, const ch
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to open %s: %m", path);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to open %s: %m", path);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
|
@ -554,8 +554,7 @@ static int process_root_password(void) {
|
||||
if (!errno)
|
||||
errno = EIO;
|
||||
|
||||
log_error_errno(errno, "Failed to find shadow entry for root: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to find shadow entry for root: %m");
|
||||
}
|
||||
|
||||
r = write_root_shadow(etc_shadow, p);
|
||||
@ -592,8 +591,7 @@ static int process_root_password(void) {
|
||||
if (!errno)
|
||||
errno = EINVAL;
|
||||
|
||||
log_error_errno(errno, "Failed to encrypt password: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to encrypt password: %m");
|
||||
}
|
||||
|
||||
item.sp_lstchg = (long) (now(CLOCK_REALTIME) / USEC_PER_DAY);
|
||||
|
@ -302,8 +302,7 @@ static int probe_and_add_mount(
|
||||
if (!b) {
|
||||
if (errno == 0)
|
||||
return log_oom();
|
||||
log_error_errno(errno, "Failed to allocate prober: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to allocate prober: %m");
|
||||
}
|
||||
|
||||
blkid_probe_enable_superblocks(b, 1);
|
||||
@ -502,8 +501,7 @@ static int add_boot(const char *what) {
|
||||
if (!b) {
|
||||
if (errno == 0)
|
||||
return log_oom();
|
||||
log_error_errno(errno, "Failed to allocate prober: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to allocate prober: %m");
|
||||
}
|
||||
|
||||
blkid_probe_enable_partitions(b, 1);
|
||||
|
@ -212,8 +212,7 @@ static int fifo_process(Fifo *f) {
|
||||
if (errno == EAGAIN)
|
||||
return 0;
|
||||
|
||||
log_warning_errno(errno, "Failed to read from fifo: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to read from fifo: %m");
|
||||
}
|
||||
|
||||
f->bytes_read += l;
|
||||
|
@ -221,8 +221,7 @@ int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) {
|
||||
if (feof(f))
|
||||
break;
|
||||
|
||||
log_error_errno(errno, "Failed to read file %s: %m", path);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to read file %s: %m", path);
|
||||
}
|
||||
|
||||
n++;
|
||||
|
@ -347,8 +347,7 @@ static int server_read_dev_kmsg(Server *s) {
|
||||
if (errno == EAGAIN || errno == EINTR || errno == EPIPE)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to read from kernel: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to read from kernel: %m");
|
||||
}
|
||||
|
||||
dev_kmsg_record(s, buffer, l);
|
||||
|
@ -538,8 +538,7 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
|
||||
if (errno == EAGAIN)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to accept stdout connection: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to accept stdout connection: %m");
|
||||
}
|
||||
|
||||
if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) {
|
||||
|
@ -414,10 +414,8 @@ _public_ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor)
|
||||
|
||||
if (err >= 0)
|
||||
monitor_set_nl_address(udev_monitor);
|
||||
else {
|
||||
log_debug_errno(errno, "bind failed: %m");
|
||||
return -errno;
|
||||
}
|
||||
else
|
||||
return log_debug_errno(errno, "bind failed: %m");
|
||||
|
||||
/* enable receiving of sender credentials */
|
||||
err = setsockopt(udev_monitor->sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
|
||||
|
@ -297,8 +297,7 @@ static int manager_enumerate_seats(Manager *m) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to open /run/systemd/seats: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to open /run/systemd/seats: %m");
|
||||
}
|
||||
|
||||
FOREACH_DIRENT(de, d, return -errno) {
|
||||
@ -334,8 +333,7 @@ static int manager_enumerate_linger_users(Manager *m) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m");
|
||||
}
|
||||
|
||||
FOREACH_DIRENT(de, d, return -errno) {
|
||||
@ -370,8 +368,7 @@ static int manager_enumerate_users(Manager *m) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to open /run/systemd/users: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to open /run/systemd/users: %m");
|
||||
}
|
||||
|
||||
FOREACH_DIRENT(de, d, return -errno) {
|
||||
@ -411,8 +408,7 @@ static int manager_enumerate_sessions(Manager *m) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to open /run/systemd/sessions: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to open /run/systemd/sessions: %m");
|
||||
}
|
||||
|
||||
FOREACH_DIRENT(de, d, return -errno) {
|
||||
@ -458,8 +454,7 @@ static int manager_enumerate_inhibitors(Manager *m) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m");
|
||||
}
|
||||
|
||||
FOREACH_DIRENT(de, d, return -errno) {
|
||||
@ -749,8 +744,7 @@ static int manager_connect_console(Manager *m) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m");
|
||||
}
|
||||
|
||||
r = sd_event_add_io(m->event, &m->console_active_event_source, m->console_active_fd, 0, manager_dispatch_console, m);
|
||||
|
@ -150,8 +150,7 @@ int manager_enumerate_machines(Manager *m) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to open /run/systemd/machines: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to open /run/systemd/machines: %m");
|
||||
}
|
||||
|
||||
FOREACH_DIRENT(de, d, return -errno) {
|
||||
|
@ -151,8 +151,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
|
||||
if (feof(f))
|
||||
break;
|
||||
|
||||
log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
|
||||
}
|
||||
|
||||
l = strstrip(line);
|
||||
|
@ -441,8 +441,7 @@ static int mount_bind(const char *dest, CustomMount *m) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to make parents of %s: %m", where);
|
||||
} else {
|
||||
log_error_errno(errno, "Failed to stat %s: %m", where);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to stat %s: %m", where);
|
||||
}
|
||||
|
||||
/* Create the mount point. Any non-directory file can be
|
||||
|
@ -1754,8 +1754,7 @@ static int dissect_image(
|
||||
if (errno == 0)
|
||||
return log_oom();
|
||||
|
||||
log_error_errno(errno, "Failed to set device on blkid probe: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to set device on blkid probe: %m");
|
||||
}
|
||||
|
||||
blkid_probe_enable_partitions(b, 1);
|
||||
@ -1771,8 +1770,7 @@ static int dissect_image(
|
||||
} else if (r != 0) {
|
||||
if (errno == 0)
|
||||
errno = EIO;
|
||||
log_error_errno(errno, "Failed to probe: %m");
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to probe: %m");
|
||||
}
|
||||
|
||||
(void) blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
|
||||
@ -1895,8 +1893,7 @@ static int dissect_image(
|
||||
if (!errno)
|
||||
errno = ENOMEM;
|
||||
|
||||
log_error_errno(errno, "Failed to get partition device of %s: %m", arg_image);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to get partition device of %s: %m", arg_image);
|
||||
}
|
||||
|
||||
qn = udev_device_get_devnum(q);
|
||||
@ -2103,8 +2100,7 @@ static int mount_device(const char *what, const char *where, const char *directo
|
||||
if (!b) {
|
||||
if (errno == 0)
|
||||
return log_oom();
|
||||
log_error_errno(errno, "Failed to allocate prober for %s: %m", what);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to allocate prober for %s: %m", what);
|
||||
}
|
||||
|
||||
blkid_probe_enable_superblocks(b, 1);
|
||||
@ -2118,8 +2114,7 @@ static int mount_device(const char *what, const char *where, const char *directo
|
||||
} else if (r != 0) {
|
||||
if (errno == 0)
|
||||
errno = EIO;
|
||||
log_error_errno(errno, "Failed to probe %s: %m", what);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to probe %s: %m", what);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
|
@ -62,8 +62,7 @@ static int add_symlink(const char *service, const char *where) {
|
||||
if (errno == EEXIST)
|
||||
return 0;
|
||||
|
||||
log_error_errno(errno, "Failed to create symlink %s: %m", to);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to create symlink %s: %m", to);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -48,8 +48,7 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_warning_errno(errno, "Failed to open /proc/sysvipc/shm: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to open /proc/sysvipc/shm: %m");
|
||||
}
|
||||
|
||||
FOREACH_LINE(line, f, goto fail) {
|
||||
@ -91,8 +90,7 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
|
||||
return ret;
|
||||
|
||||
fail:
|
||||
log_warning_errno(errno, "Failed to read /proc/sysvipc/shm: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to read /proc/sysvipc/shm: %m");
|
||||
}
|
||||
|
||||
static int clean_sysvipc_sem(uid_t delete_uid) {
|
||||
@ -106,8 +104,7 @@ static int clean_sysvipc_sem(uid_t delete_uid) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_warning_errno(errno, "Failed to open /proc/sysvipc/sem: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to open /proc/sysvipc/sem: %m");
|
||||
}
|
||||
|
||||
FOREACH_LINE(line, f, goto fail) {
|
||||
@ -144,8 +141,7 @@ static int clean_sysvipc_sem(uid_t delete_uid) {
|
||||
return ret;
|
||||
|
||||
fail:
|
||||
log_warning_errno(errno, "Failed to read /proc/sysvipc/sem: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to read /proc/sysvipc/sem: %m");
|
||||
}
|
||||
|
||||
static int clean_sysvipc_msg(uid_t delete_uid) {
|
||||
@ -159,8 +155,7 @@ static int clean_sysvipc_msg(uid_t delete_uid) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_warning_errno(errno, "Failed to open /proc/sysvipc/msg: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to open /proc/sysvipc/msg: %m");
|
||||
}
|
||||
|
||||
FOREACH_LINE(line, f, goto fail) {
|
||||
@ -198,8 +193,7 @@ static int clean_sysvipc_msg(uid_t delete_uid) {
|
||||
return ret;
|
||||
|
||||
fail:
|
||||
log_warning_errno(errno, "Failed to read /proc/sysvipc/msg: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to read /proc/sysvipc/msg: %m");
|
||||
}
|
||||
|
||||
static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
|
||||
@ -277,8 +271,7 @@ static int clean_posix_shm(uid_t uid) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_warning_errno(errno, "Failed to open /dev/shm: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to open /dev/shm: %m");
|
||||
}
|
||||
|
||||
return clean_posix_shm_internal(dir, uid);
|
||||
@ -294,8 +287,7 @@ static int clean_posix_mq(uid_t uid) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
log_warning_errno(errno, "Failed to open /dev/mqueue: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to open /dev/mqueue: %m");
|
||||
}
|
||||
|
||||
FOREACH_DIRENT(de, dir, goto fail) {
|
||||
@ -334,8 +326,7 @@ static int clean_posix_mq(uid_t uid) {
|
||||
return ret;
|
||||
|
||||
fail:
|
||||
log_warning_errno(errno, "Failed to read /dev/mqueue: %m");
|
||||
return -errno;
|
||||
return log_warning_errno(errno, "Failed to read /dev/mqueue: %m");
|
||||
}
|
||||
|
||||
int clean_ipc(uid_t uid) {
|
||||
|
@ -88,8 +88,7 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
|
||||
if (feof(f))
|
||||
break;
|
||||
|
||||
log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
|
||||
return -errno;
|
||||
return log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
|
||||
}
|
||||
|
||||
p = strstrip(l);
|
||||
|
@ -441,9 +441,7 @@ static int spawn_exec(struct udev_event *event,
|
||||
execve(argv[0], argv, envp);
|
||||
|
||||
/* exec failed */
|
||||
log_error_errno(errno, "failed to execute '%s' '%s': %m", argv[0], cmd);
|
||||
|
||||
return -errno;
|
||||
return log_error_errno(errno, "failed to execute '%s' '%s': %m", argv[0], cmd);
|
||||
}
|
||||
|
||||
static void spawn_read(struct udev_event *event,
|
||||
|
@ -263,8 +263,7 @@ static int node_permissions_apply(struct udev_device *dev, bool apply,
|
||||
mode |= S_IFCHR;
|
||||
|
||||
if (lstat(devnode, &stats) != 0) {
|
||||
err = -errno;
|
||||
log_debug_errno(errno, "can not stat() node '%s' (%m)", devnode);
|
||||
err = log_debug_errno(errno, "can not stat() node '%s' (%m)", devnode);
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user