treewide: use the negative error codes returned by our functions
Our functions return negative error codes. Do not rely on errno being set after calling our own functions.
This commit is contained in:
parent
c3753458fc
commit
709f6e46a3
|
@ -61,8 +61,9 @@ int hostname_setup(void) {
|
|||
hn = "localhost";
|
||||
}
|
||||
|
||||
if (sethostname_idempotent(hn) < 0)
|
||||
return log_warning_errno(errno, "Failed to set hostname to <%s>: %m", hn);
|
||||
r = sethostname_idempotent(hn);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to set hostname to <%s>: %m", hn);
|
||||
|
||||
log_info("Set hostname to <%s>.", hn);
|
||||
return 0;
|
||||
|
|
|
@ -199,7 +199,7 @@ static int raw_import_maybe_convert_qcow2(RawImport *i) {
|
|||
|
||||
r = chattr_fd(converted_fd, FS_NOCOW_FL, FS_NOCOW_FL);
|
||||
if (r < 0)
|
||||
log_warning_errno(errno, "Failed to set file attributes on %s: %m", t);
|
||||
log_warning_errno(r, "Failed to set file attributes on %s: %m", t);
|
||||
|
||||
log_info("Unpacking QCOW2 file.");
|
||||
|
||||
|
@ -287,7 +287,7 @@ static int raw_import_open_disk(RawImport *i) {
|
|||
|
||||
r = chattr_fd(i->output_fd, FS_NOCOW_FL, FS_NOCOW_FL);
|
||||
if (r < 0)
|
||||
log_warning_errno(errno, "Failed to set file attributes on %s: %m", i->temp_path);
|
||||
log_warning_errno(r, "Failed to set file attributes on %s: %m", i->temp_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ static int tar_import_fork_tar(TarImport *i) {
|
|||
if (mkdir(i->temp_path, 0755) < 0)
|
||||
return log_error_errno(errno, "Failed to create directory %s: %m", i->temp_path);
|
||||
} else if (r < 0)
|
||||
return log_error_errno(errno, "Failed to create subvolume %s: %m", i->temp_path);
|
||||
return log_error_errno(r, "Failed to create subvolume %s: %m", i->temp_path);
|
||||
else
|
||||
(void) import_assign_pool_quota_and_warn(i->temp_path);
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ static int raw_pull_maybe_convert_qcow2(RawPull *i) {
|
|||
|
||||
r = chattr_fd(converted_fd, FS_NOCOW_FL, FS_NOCOW_FL);
|
||||
if (r < 0)
|
||||
log_warning_errno(errno, "Failed to set file attributes on %s: %m", t);
|
||||
log_warning_errno(r, "Failed to set file attributes on %s: %m", t);
|
||||
|
||||
log_info("Unpacking QCOW2 file.");
|
||||
|
||||
|
@ -320,7 +320,7 @@ static int raw_pull_make_local_copy(RawPull *i) {
|
|||
* writes. */
|
||||
r = chattr_fd(dfd, FS_NOCOW_FL, FS_NOCOW_FL);
|
||||
if (r < 0)
|
||||
log_warning_errno(errno, "Failed to set file attributes on %s: %m", tp);
|
||||
log_warning_errno(r, "Failed to set file attributes on %s: %m", tp);
|
||||
|
||||
r = copy_bytes(i->raw_job->disk_fd, dfd, (uint64_t) -1, true);
|
||||
if (r < 0) {
|
||||
|
@ -511,7 +511,7 @@ static int raw_pull_job_on_open_disk_raw(PullJob *j) {
|
|||
|
||||
r = chattr_fd(j->disk_fd, FS_NOCOW_FL, FS_NOCOW_FL);
|
||||
if (r < 0)
|
||||
log_warning_errno(errno, "Failed to set file attributes on %s: %m", i->temp_path);
|
||||
log_warning_errno(r, "Failed to set file attributes on %s: %m", i->temp_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -416,7 +416,7 @@ static int tar_pull_job_on_open_disk_tar(PullJob *j) {
|
|||
if (mkdir(i->temp_path, 0755) < 0)
|
||||
return log_error_errno(errno, "Failed to create directory %s: %m", i->temp_path);
|
||||
} else if (r < 0)
|
||||
return log_error_errno(errno, "Failed to create subvolume %s: %m", i->temp_path);
|
||||
return log_error_errno(r, "Failed to create subvolume %s: %m", i->temp_path);
|
||||
else
|
||||
(void) import_assign_pool_quota_and_warn(i->temp_path);
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ static int spawn_curl(const char* url) {
|
|||
|
||||
r = spawn_child("curl", argv);
|
||||
if (r < 0)
|
||||
log_error_errno(errno, "Failed to spawn curl: %m");
|
||||
log_error_errno(r, "Failed to spawn curl: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ static int spawn_getter(const char *getter, const char *url) {
|
|||
|
||||
r = spawn_child(words[0], words);
|
||||
if (r < 0)
|
||||
log_error_errno(errno, "Failed to spawn getter %s: %m", getter);
|
||||
log_error_errno(r, "Failed to spawn getter %s: %m", getter);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) {
|
|||
|
||||
r = catalog_file_lang(path, &deflang);
|
||||
if (r < 0)
|
||||
log_error_errno(errno, "Failed to determine language for file %s: %m", path);
|
||||
log_error_errno(r, "Failed to determine language for file %s: %m", path);
|
||||
if (r == 1)
|
||||
log_debug("File %s has language %s.", path, deflang);
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ static int fix_acl(int fd, uid_t uid) {
|
|||
_cleanup_(acl_freep) acl_t acl = NULL;
|
||||
acl_entry_t entry;
|
||||
acl_permset_t permset;
|
||||
int r;
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
|
@ -160,11 +161,12 @@ static int fix_acl(int fd, uid_t uid) {
|
|||
}
|
||||
|
||||
if (acl_get_permset(entry, &permset) < 0 ||
|
||||
acl_add_perm(permset, ACL_READ) < 0 ||
|
||||
calc_acl_mask_if_needed(&acl) < 0) {
|
||||
log_warning_errno(errno, "Failed to patch ACL: %m");
|
||||
return -errno;
|
||||
}
|
||||
acl_add_perm(permset, ACL_READ) < 0)
|
||||
return log_warning_errno(errno, "Failed to patch ACL: %m");
|
||||
|
||||
r = calc_acl_mask_if_needed(&acl);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to patch ACL: %m");
|
||||
|
||||
if (acl_set_fd(fd, acl) < 0)
|
||||
return log_error_errno(errno, "Failed to apply ACL: %m");
|
||||
|
|
|
@ -617,7 +617,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) {
|
|||
|
||||
fdt = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC);
|
||||
if (fdt < 0)
|
||||
return log_error_errno(errno, "Failed to create temporary file: %m");
|
||||
return log_error_errno(fdt, "Failed to create temporary file: %m");
|
||||
log_debug("Created temporary file %s", temp);
|
||||
|
||||
fd = fdt;
|
||||
|
@ -776,7 +776,7 @@ static int run_gdb(sd_journal *j) {
|
|||
|
||||
r = wait_for_terminate(pid, &st);
|
||||
if (r < 0) {
|
||||
log_error_errno(errno, "Failed to wait for gdb: %m");
|
||||
log_error_errno(r, "Failed to wait for gdb: %m");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -842,19 +842,19 @@ int journal_file_verify(
|
|||
|
||||
data_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC);
|
||||
if (data_fd < 0) {
|
||||
r = log_error_errno(errno, "Failed to create data file: %m");
|
||||
r = log_error_errno(data_fd, "Failed to create data file: %m");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
entry_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC);
|
||||
if (entry_fd < 0) {
|
||||
r = log_error_errno(errno, "Failed to create entry file: %m");
|
||||
r = log_error_errno(entry_fd, "Failed to create entry file: %m");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
entry_array_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC);
|
||||
if (entry_array_fd < 0) {
|
||||
r = log_error_errno(errno,
|
||||
r = log_error_errno(entry_array_fd,
|
||||
"Failed to create entry array file: %m");
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -1483,7 +1483,7 @@ static int setup_keys(void) {
|
|||
safe_close(fd);
|
||||
fd = mkostemp_safe(k, O_WRONLY|O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
r = log_error_errno(errno, "Failed to open %s: %m", k);
|
||||
r = log_error_errno(fd, "Failed to open %s: %m", k);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -1491,7 +1491,7 @@ static int setup_keys(void) {
|
|||
* writing and in-place updating */
|
||||
r = chattr_fd(fd, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL);
|
||||
if (r < 0)
|
||||
log_warning_errno(errno, "Failed to set file attributes: %m");
|
||||
log_warning_errno(r, "Failed to set file attributes: %m");
|
||||
|
||||
zero(h);
|
||||
memcpy(h.signature, "KSHHRHLP", 8);
|
||||
|
|
|
@ -106,7 +106,7 @@ void server_forward_console(
|
|||
|
||||
fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
log_debug_errno(errno, "Failed to open %s for logging: %m", tty);
|
||||
log_debug_errno(fd, "Failed to open %s for logging: %m", tty);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -344,7 +344,7 @@ void server_process_native_file(
|
|||
|
||||
r = readlink_malloc(sl, &k);
|
||||
if (r < 0) {
|
||||
log_error_errno(errno, "readlink(%s) failed: %m", sl);
|
||||
log_error_errno(r, "readlink(%s) failed: %m", sl);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -240,12 +240,17 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
|
|||
/* We do not recalculate the mask unconditionally here,
|
||||
* so that the fchmod() mask above stays intact. */
|
||||
if (acl_get_permset(entry, &permset) < 0 ||
|
||||
acl_add_perm(permset, ACL_READ) < 0 ||
|
||||
calc_acl_mask_if_needed(&acl) < 0) {
|
||||
acl_add_perm(permset, ACL_READ) < 0) {
|
||||
log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
|
||||
return;
|
||||
}
|
||||
|
||||
r = calc_acl_mask_if_needed(&acl);
|
||||
if (r < 0) {
|
||||
log_warning_errno(r, "Failed to patch ACL on %s, ignoring: %m", f->path);
|
||||
return;
|
||||
}
|
||||
|
||||
if (acl_set_fd(f->fd, acl) < 0)
|
||||
log_warning_errno(errno, "Failed to set ACL on %s, ignoring: %m", f->path);
|
||||
|
||||
|
|
|
@ -996,7 +996,7 @@ static int session_open_vt(Session *s) {
|
|||
sprintf(path, "/dev/tty%u", s->vtnr);
|
||||
s->vtfd = open_terminal(path, O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
|
||||
if (s->vtfd < 0)
|
||||
return log_error_errno(errno, "cannot open VT %s of session %s: %m", path, s->id);
|
||||
return log_error_errno(s->vtfd, "cannot open VT %s of session %s: %m", path, s->id);
|
||||
|
||||
return s->vtfd;
|
||||
}
|
||||
|
|
|
@ -1177,6 +1177,7 @@ static int copy_devnodes(const char *dest) {
|
|||
static int setup_pts(const char *dest) {
|
||||
_cleanup_free_ char *options = NULL;
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
#ifdef HAVE_SELINUX
|
||||
if (arg_selinux_apifs_context)
|
||||
|
@ -1199,20 +1200,23 @@ static int setup_pts(const char *dest) {
|
|||
return log_error_errno(errno, "Failed to create /dev/pts: %m");
|
||||
if (mount("devpts", p, "devpts", MS_NOSUID|MS_NOEXEC, options) < 0)
|
||||
return log_error_errno(errno, "Failed to mount /dev/pts: %m");
|
||||
if (userns_lchown(p, 0, 0) < 0)
|
||||
return log_error_errno(errno, "Failed to chown /dev/pts: %m");
|
||||
r = userns_lchown(p, 0, 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to chown /dev/pts: %m");
|
||||
|
||||
/* Create /dev/ptmx symlink */
|
||||
p = prefix_roota(dest, "/dev/ptmx");
|
||||
if (symlink("pts/ptmx", p) < 0)
|
||||
return log_error_errno(errno, "Failed to create /dev/ptmx symlink: %m");
|
||||
if (userns_lchown(p, 0, 0) < 0)
|
||||
return log_error_errno(errno, "Failed to chown /dev/ptmx: %m");
|
||||
r = userns_lchown(p, 0, 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to chown /dev/ptmx: %m");
|
||||
|
||||
/* And fix /dev/pts/ptmx ownership */
|
||||
p = prefix_roota(dest, "/dev/pts/ptmx");
|
||||
if (userns_lchown(p, 0, 0) < 0)
|
||||
return log_error_errno(errno, "Failed to chown /dev/pts/ptmx: %m");
|
||||
r = userns_lchown(p, 0, 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to chown /dev/pts/ptmx: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1394,7 +1398,7 @@ static int setup_journal(const char *directory) {
|
|||
|
||||
r = userns_mkdir(directory, p, 0755, 0, 0);
|
||||
if (r < 0)
|
||||
log_warning_errno(errno, "Failed to create directory %s: %m", q);
|
||||
log_warning_errno(r, "Failed to create directory %s: %m", q);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1414,7 +1418,7 @@ static int setup_journal(const char *directory) {
|
|||
}
|
||||
}
|
||||
} else if (r != -ENOENT) {
|
||||
log_error_errno(errno, "readlink(%s) failed: %m", p);
|
||||
log_error_errno(r, "readlink(%s) failed: %m", p);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -1432,7 +1436,7 @@ static int setup_journal(const char *directory) {
|
|||
|
||||
r = userns_mkdir(directory, p, 0755, 0, 0);
|
||||
if (r < 0)
|
||||
log_warning_errno(errno, "Failed to create directory %s: %m", q);
|
||||
log_warning_errno(r, "Failed to create directory %s: %m", q);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1457,10 +1461,8 @@ static int setup_journal(const char *directory) {
|
|||
log_warning("%s is not empty, proceeding anyway.", q);
|
||||
|
||||
r = userns_mkdir(directory, p, 0755, 0, 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(errno, "Failed to create %s: %m", q);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create %s: %m", q);
|
||||
|
||||
if (mount(p, q, NULL, MS_BIND, NULL) < 0)
|
||||
return log_error_errno(errno, "Failed to bind mount journal from host into guest: %m");
|
||||
|
@ -1601,20 +1603,24 @@ finish:
|
|||
|
||||
static int setup_propagate(const char *root) {
|
||||
const char *p, *q;
|
||||
int r;
|
||||
|
||||
(void) mkdir_p("/run/systemd/nspawn/", 0755);
|
||||
(void) mkdir_p("/run/systemd/nspawn/propagate", 0600);
|
||||
p = strjoina("/run/systemd/nspawn/propagate/", arg_machine);
|
||||
(void) mkdir_p(p, 0600);
|
||||
|
||||
if (userns_mkdir(root, "/run/systemd", 0755, 0, 0) < 0)
|
||||
return log_error_errno(errno, "Failed to create /run/systemd: %m");
|
||||
r = userns_mkdir(root, "/run/systemd", 0755, 0, 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create /run/systemd: %m");
|
||||
|
||||
if (userns_mkdir(root, "/run/systemd/nspawn", 0755, 0, 0) < 0)
|
||||
return log_error_errno(errno, "Failed to create /run/systemd/nspawn: %m");
|
||||
r = userns_mkdir(root, "/run/systemd/nspawn", 0755, 0, 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create /run/systemd/nspawn: %m");
|
||||
|
||||
if (userns_mkdir(root, "/run/systemd/nspawn/incoming", 0600, 0, 0) < 0)
|
||||
return log_error_errno(errno, "Failed to create /run/systemd/nspawn/incoming: %m");
|
||||
r = userns_mkdir(root, "/run/systemd/nspawn/incoming", 0600, 0, 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create /run/systemd/nspawn/incoming: %m");
|
||||
|
||||
q = prefix_roota(root, "/run/systemd/nspawn/incoming");
|
||||
if (mount(p, q, NULL, MS_BIND, NULL) < 0)
|
||||
|
@ -2485,8 +2491,9 @@ static int inner_child(
|
|||
rtnl_socket = safe_close(rtnl_socket);
|
||||
}
|
||||
|
||||
if (drop_capabilities() < 0)
|
||||
return log_error_errno(errno, "drop_capabilities() failed: %m");
|
||||
r = drop_capabilities();
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "drop_capabilities() failed: %m");
|
||||
|
||||
setup_hostname();
|
||||
|
||||
|
|
|
@ -472,7 +472,7 @@ int ask_password_agent(
|
|||
|
||||
fd = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
r = -errno;
|
||||
r = fd;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ static int builtin_uaccess(struct udev_device *dev, int argc, char *argv[], bool
|
|||
|
||||
r = devnode_acl(path, true, false, 0, true, uid);
|
||||
if (r < 0) {
|
||||
log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, r, "Failed to apply ACL on %s: %m", path);
|
||||
log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, "Failed to apply ACL on %s: %m", path);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -1558,7 +1558,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg
|
|||
|
||||
r = sd_event_default(&manager->event);
|
||||
if (r < 0)
|
||||
return log_error_errno(errno, "could not allocate event loop: %m");
|
||||
return log_error_errno(r, "could not allocate event loop: %m");
|
||||
|
||||
r = sd_event_add_signal(manager->event, NULL, SIGINT, on_sigterm, manager);
|
||||
if (r < 0)
|
||||
|
|
|
@ -275,7 +275,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
fd = open_terminal(vc, O_RDWR|O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
log_error_errno(errno, "Failed to open %s: %m", vc);
|
||||
log_error_errno(fd, "Failed to open %s: %m", vc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue