Skip to content

Commit

Permalink
tree-wide: start replacing instances of syserrno() with syserror()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 25, 2021
1 parent 060aaa3 commit 2d7b089
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/lxc/af_unix.c
Expand Up @@ -198,7 +198,7 @@ static ssize_t lxc_abstract_unix_recv_fds_iov(int fd,
if (errno == EINTR)
goto again;

return syserrno(-errno, "Failed to receive response");
return syserror("Failed to receive response");
}
if (ret == 0)
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/lxc/attach.c
Expand Up @@ -512,7 +512,7 @@ static int same_ns(int dfd_pid1, int dfd_pid2, const char *ns_path)
if (ns_fd2 < 0) {
if (errno == ENOENT)
return -ENOENT;
return syserrno(-errno, "Failed to open %d(%s)", dfd_pid2, ns_path);
return syserror("Failed to open %d(%s)", dfd_pid2, ns_path);
}

ret = same_nsfd(dfd_pid1, dfd_pid2, ns_path);
Expand Down Expand Up @@ -551,7 +551,7 @@ static int __prepare_namespaces_pidfd(struct attach_context *ctx)
break;
}

return syserrno(-errno, "Failed to determine whether %s namespace is shared",
return syserror("Failed to determine whether %s namespace is shared",
ns_info[i].proc_name);
}

Expand Down
28 changes: 14 additions & 14 deletions src/lxc/cgroups/cgfsng.c
Expand Up @@ -744,20 +744,20 @@ static int __cgroup_tree_create(int dfd_base, const char *path, mode_t mode,
ret = mkdirat(dfd_cur, cur, mode);
if (ret < 0) {
if (errno != EEXIST)
return syserrno(-errno, "Failed to create %d(%s)", dfd_cur, cur);
return syserror("Failed to create %d(%s)", dfd_cur, cur);

ret = -EEXIST;
}
TRACE("%s %d(%s) cgroup", !ret ? "Created" : "Reusing", dfd_cur, cur);

dfd_final = open_at(dfd_cur, cur, PROTECT_OPATH_DIRECTORY, PROTECT_LOOKUP_BENEATH, 0);
if (dfd_final < 0)
return syserrno(-errno, "Fail to open%s directory %d(%s)",
return syserror("Fail to open%s directory %d(%s)",
!ret ? " newly created" : "", dfd_base, cur);
if (dfd_cur != dfd_base)
close(dfd_cur);
else if (cpuset_v1 && !cpuset1_initialize(dfd_base, dfd_final))
return syserrno(-EINVAL, "Failed to initialize cpuset controller in the legacy hierarchy");
return syserror_set(-EINVAL, "Failed to initialize cpuset controller in the legacy hierarchy");
/*
* Leave dfd_final pointing to the last fd we opened so
* it will be automatically zapped if we return early.
Expand Down Expand Up @@ -1695,7 +1695,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
dfd_mnt_unified = open_at(rootfs->dfd_mnt, DEFAULT_CGROUP_MOUNTPOINT_RELATIVE,
PROTECT_OPATH_DIRECTORY, PROTECT_LOOKUP_BENEATH_XDEV, 0);
if (dfd_mnt_unified < 0)
return syserrno(-errno, "Failed to open %d(%s)", rootfs->dfd_mnt,
return syserrno(false, "Failed to open %d(%s)", rootfs->dfd_mnt,
DEFAULT_CGROUP_MOUNTPOINT_RELATIVE);
/*
* If cgroup namespaces are supported but the container will
Expand Down Expand Up @@ -1798,7 +1798,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
dfd_mnt_tmpfs = open_at(rootfs->dfd_mnt, DEFAULT_CGROUP_MOUNTPOINT_RELATIVE,
PROTECT_OPATH_DIRECTORY, PROTECT_LOOKUP_BENEATH_XDEV, 0);
if (dfd_mnt_tmpfs < 0)
return syserrno(-errno, "Failed to open %d(%s)", rootfs->dfd_mnt,
return syserrno(false, "Failed to open %d(%s)", rootfs->dfd_mnt,
DEFAULT_CGROUP_MOUNTPOINT_RELATIVE);

for (int i = 0; ops->hierarchies[i]; i++) {
Expand Down Expand Up @@ -2937,13 +2937,13 @@ static bool __cgfsng_delegate_controllers(struct cgroup_ops *ops, const char *cg

ret = lxc_writeat(dfd_cur, "cgroup.subtree_control", add_controllers, full_len);
if (ret < 0)
return syserrno(-errno, "Could not enable \"%s\" controllers in the unified cgroup %d", add_controllers, dfd_cur);
return syserror("Could not enable \"%s\" controllers in the unified cgroup %d", add_controllers, dfd_cur);

TRACE("Enabled \"%s\" controllers in the unified cgroup %d", add_controllers, dfd_cur);

dfd_final = open_at(dfd_cur, cur, PROTECT_OPATH_DIRECTORY, PROTECT_LOOKUP_BENEATH, 0);
if (dfd_final < 0)
return syserrno(-errno, "Fail to open directory %d(%s)", dfd_cur, cur);
return syserror("Fail to open directory %d(%s)", dfd_cur, cur);
if (dfd_cur != unified->dfd_base)
close(dfd_cur);
/*
Expand Down Expand Up @@ -3126,7 +3126,7 @@ static int __initialize_cgroups(struct cgroup_ops *ops, bool relative,
}
if (dfd_mnt < 0) {
if (errno != ENOENT)
return syserrno(-errno, "Failed to open %d/unified", ops->dfd_mnt);
return syserror("Failed to open %d/unified", ops->dfd_mnt);

SYSTRACE("Unified cgroup not mounted");
continue;
Expand All @@ -3138,7 +3138,7 @@ static int __initialize_cgroups(struct cgroup_ops *ops, bool relative,
PROTECT_OPATH_DIRECTORY,
PROTECT_LOOKUP_BENEATH_XDEV, 0);
if (dfd_base < 0)
return syserrno(-errno, "Failed to open %d/%s", dfd_mnt, current_cgroup);
return syserror("Failed to open %d/%s", dfd_mnt, current_cgroup);
dfd = dfd_base;
}

Expand All @@ -3150,7 +3150,7 @@ static int __initialize_cgroups(struct cgroup_ops *ops, bool relative,
TRACE("No controllers are enabled for delegation in the unified hierarchy");
controller_list = list_new();
if (!controller_list)
return syserrno(-ENOMEM, "Failed to create empty controller list");
return syserror_set(-ENOMEM, "Failed to create empty controller list");
}

controllers = strdup(unified_mnt);
Expand Down Expand Up @@ -3181,7 +3181,7 @@ static int __initialize_cgroups(struct cgroup_ops *ops, bool relative,
PROTECT_LOOKUP_ABSOLUTE_XDEV, 0);
if (dfd_mnt < 0) {
if (errno != ENOENT)
return syserrno(-errno, "Failed to open %d/%s",
return syserror("Failed to open %d/%s",
ops->dfd_mnt, controllers);

SYSTRACE("%s not mounted", controllers);
Expand All @@ -3208,7 +3208,7 @@ static int __initialize_cgroups(struct cgroup_ops *ops, bool relative,
PROTECT_OPATH_DIRECTORY,
PROTECT_LOOKUP_BENEATH_XDEV, 0);
if (dfd_base < 0)
return syserrno(-errno, "Failed to open %d/%s",
return syserror("Failed to open %d/%s",
dfd_mnt, current_cgroup);
dfd = dfd_base;
}
Expand All @@ -3223,7 +3223,7 @@ static int __initialize_cgroups(struct cgroup_ops *ops, bool relative,
*/
controller_list = list_add_controllers(__controllers);
if (!controller_list)
return syserrno(-ENOMEM, "Failed to create controller list from %s", __controllers);
return syserror_set(-ENOMEM, "Failed to create controller list from %s", __controllers);

if (skip_hierarchy(ops, controller_list))
continue;
Expand Down Expand Up @@ -3280,7 +3280,7 @@ static int initialize_cgroups(struct cgroup_ops *ops, struct lxc_conf *conf)
dfd = open_at(-EBADF, DEFAULT_CGROUP_MOUNTPOINT,
PROTECT_OPATH_DIRECTORY, PROTECT_LOOKUP_ABSOLUTE_XDEV, 0);
if (dfd < 0)
return syserrno(-errno, "Failed to open " DEFAULT_CGROUP_MOUNTPOINT);
return syserror("Failed to open " DEFAULT_CGROUP_MOUNTPOINT);

controllers_use = lxc_global_config_value("lxc.cgroup.use");
if (controllers_use) {
Expand Down
6 changes: 3 additions & 3 deletions src/lxc/cgroups/cgroup2_devices.c
Expand Up @@ -369,7 +369,7 @@ static int bpf_program_cgroup_attach(struct bpf_program *prog, int type,

ret = bpf_program_load_kernel(prog);
if (ret < 0)
return syserrno(-errno, "Failed to load bpf program");
return syserror("Failed to load bpf program");

attr = &(union bpf_attr){
.attach_type = type,
Expand All @@ -380,7 +380,7 @@ static int bpf_program_cgroup_attach(struct bpf_program *prog, int type,

ret = bpf(BPF_PROG_ATTACH, attr, sizeof(*attr));
if (ret < 0)
return syserrno(-errno, "Failed to attach bpf program");
return syserror("Failed to attach bpf program");

prog->fd_cgroup = move_fd(fd_attach);
prog->attached_type = type;
Expand Down Expand Up @@ -414,7 +414,7 @@ int bpf_program_cgroup_detach(struct bpf_program *prog)

ret = bpf(BPF_PROG_DETACH, attr, sizeof(*attr));
if (ret < 0)
return syserrno(-errno, "Failed to detach bpf program from cgroup %d", fd_cgroup);
return syserror("Failed to detach bpf program from cgroup %d", fd_cgroup);

TRACE("Detached bpf program from cgroup %d", fd_cgroup);

Expand Down
4 changes: 2 additions & 2 deletions src/lxc/commands.c
Expand Up @@ -310,7 +310,7 @@ static ssize_t lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd)

bytes_recv = lxc_recv_nointr(sock, rsp->data, rsp->datalen, 0);
if (bytes_recv != rsp->datalen)
return syserrno(-errno, "Failed to receive response data for command \"%s\": %zd != %d",
return syserror("Failed to receive response data for command \"%s\": %zd != %d",
cur_cmdstr, bytes_recv, rsp->datalen);

switch (cur_cmd) {
Expand Down Expand Up @@ -347,7 +347,7 @@ static int __lxc_cmd_rsp_send(int fd, struct lxc_cmd_rsp *rsp)

ret = lxc_send_nointr(fd, rsp, sizeof(*rsp), MSG_NOSIGNAL);
if (ret < 0 || (size_t)ret != sizeof(*rsp))
return syserrno(-errno, "Failed to send command response %zd", ret);
return syserror("Failed to send command response %zd", ret);

if (!rsp->data || rsp->datalen <= 0)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/conf.c
Expand Up @@ -1842,7 +1842,7 @@ static int lxc_setup_console(const struct lxc_handler *handler,
else
ret = lxc_terminal_set_stdfds(fd_pty);
if (ret < 0)
return syserrno(-errno, "Failed to redirect std{in,out,err} to pty file descriptor %d", fd_pty);
return syserror("Failed to redirect std{in,out,err} to pty file descriptor %d", fd_pty);
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/confile_utils.c
Expand Up @@ -654,7 +654,7 @@ int set_config_path_item(char **conf_item, const char *value)

normalized = lxc_deslashify(value);
if (!normalized)
return syserrno(-errno, "Failed to normalize path config item");
return syserror_set(-ENOMEM, "Failed to normalize path config item");

return set_config_string_item_max(conf_item, normalized, PATH_MAX);
}
Expand Down

0 comments on commit 2d7b089

Please sign in to comment.