Unverified Commit 32d40452 by Stéphane Graber Committed by GitHub

Merge pull request #3698 from brauner/2021-02-25/fixes

tree-wide: some more logging fixes
parents cca31bf0 815c378b
......@@ -198,7 +198,7 @@ again:
if (errno == EINTR)
goto again;
return syserrno(-errno, "Failed to receive response");
return syserror("Failed to receive response");
}
if (ret == 0)
return 0;
......@@ -228,14 +228,14 @@ again:
for (idx = 0; idx < num_raw; idx++)
close(fds_raw[idx]);
return syserrno_set(-EFBIG, "Received excessive number of file descriptors");
return syserror_set(-EFBIG, "Received excessive number of file descriptors");
}
if (msg.msg_flags & MSG_CTRUNC) {
for (idx = 0; idx < num_raw; idx++)
close(fds_raw[idx]);
return syserrno_set(-EFBIG, "Control message was truncated; closing all fds and rejecting incomplete message");
return syserror_set(-EFBIG, "Control message was truncated; closing all fds and rejecting incomplete message");
}
if (ret_fds->fd_count_max > num_raw) {
......@@ -243,7 +243,7 @@ again:
for (idx = 0; idx < num_raw; idx++)
close(fds_raw[idx]);
return syserrno_set(-EINVAL, "Received fewer file descriptors than we expected %u != %u",
return syserror_set(-EINVAL, "Received fewer file descriptors than we expected %u != %u",
ret_fds->fd_count_max, num_raw);
}
......@@ -261,7 +261,7 @@ again:
for (idx = 0; idx < num_raw; idx++)
close(fds_raw[idx]);
return syserrno_set(-EINVAL, "Received more file descriptors than we expected %u != %u",
return syserror_set(-EINVAL, "Received more file descriptors than we expected %u != %u",
ret_fds->fd_count_max, num_raw);
}
......@@ -280,7 +280,7 @@ again:
for (idx = 0; idx < num_raw; idx++)
close(fds_raw[idx]);
return syserrno_set(-EINVAL, "Invalid flag combination; closing to not risk leaking fds %u != %u",
return syserror_set(-EINVAL, "Invalid flag combination; closing to not risk leaking fds %u != %u",
ret_fds->fd_count_max, num_raw);
}
......@@ -296,7 +296,7 @@ again:
/* We expected to receive file descriptors. */
if ((ret_fds->flags & UNIX_FDS_ACCEPT_MASK) &&
!(ret_fds->flags & UNIX_FDS_ACCEPT_NONE))
return syserrno_set(-EINVAL, "Received no file descriptors");
return syserror_set(-EINVAL, "Received no file descriptors");
}
return ret;
......
......@@ -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);
......@@ -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);
}
......
......@@ -352,7 +352,7 @@ static int bpf_program_cgroup_attach(struct bpf_program *prog, int type,
return ret_errno(EBADF);
if (flags & ~(BPF_F_ALLOW_OVERRIDE | BPF_F_ALLOW_MULTI | BPF_F_REPLACE))
return syserrno_set(-EINVAL, "Invalid flags for bpf program");
return syserror_set(-EINVAL, "Invalid flags for bpf program");
/*
* Don't allow the bpf program to be overwritten for now. If we ever
......@@ -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,
......@@ -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;
......@@ -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);
......@@ -513,11 +513,11 @@ int bpf_list_add_device(struct bpf_devices *bpf_devices,
list_elem = malloc(sizeof(*list_elem));
if (!list_elem)
return syserrno_set(ENOMEM, "Failed to allocate new device list");
return syserror_set(ENOMEM, "Failed to allocate new device list");
new_device = memdup(device, sizeof(struct device_item));
if (!new_device)
return syserrno_set(ENOMEM, "Failed to allocate new device item");
return syserror_set(ENOMEM, "Failed to allocate new device item");
lxc_list_add_elem(list_elem, move_ptr(new_device));
lxc_list_add_tail(&bpf_devices->device_item, move_ptr(list_elem));
......@@ -565,11 +565,11 @@ static struct bpf_program *__bpf_cgroup_devices(struct bpf_devices *bpf_devices)
prog = bpf_program_new(BPF_PROG_TYPE_CGROUP_DEVICE);
if (!prog)
return syserrno(NULL, "Failed to create new bpf program");
return syserror_ret(NULL, "Failed to create new bpf program");
ret = bpf_program_init(prog);
if (ret)
return syserrno(NULL, "Failed to initialize bpf program");
return syserror_ret(NULL, "Failed to initialize bpf program");
prog->device_list_type = bpf_devices->list_type;
TRACE("Device cgroup %s all devices by default",
......@@ -586,14 +586,14 @@ static struct bpf_program *__bpf_cgroup_devices(struct bpf_devices *bpf_devices)
ret = bpf_program_append_device(prog, cur);
if (ret)
return syserrno(NULL, "Failed adding new device rule");
return syserror_ret(NULL, "Failed adding new device rule");
TRACE("Added new device rule");
}
ret = bpf_program_finalize(prog);
if (ret)
return syserrno(NULL, "Failed to finalize device program");
return syserror_ret(NULL, "Failed to finalize device program");
return move_ptr(prog);
}
......@@ -606,13 +606,13 @@ bool bpf_cgroup_devices_attach(struct cgroup_ops *ops,
prog = __bpf_cgroup_devices(bpf_devices);
if (!prog)
return syserrno(false, "Failed to create bpf program");
return syserror_ret(false, "Failed to create bpf program");
ret = bpf_program_cgroup_attach(prog, BPF_CGROUP_DEVICE,
ops->unified->dfd_lim,
BPF_F_ALLOW_MULTI);
if (ret)
return syserrno(false, "Failed to attach bpf program");
return syserror_ret(false, "Failed to attach bpf program");
/* Replace old bpf program. */
swap(prog, ops->cgroup2_devices);
......@@ -657,11 +657,11 @@ bool bpf_cgroup_devices_update(struct cgroup_ops *ops,
prog = __bpf_cgroup_devices(bpf_devices);
if (!prog)
return syserrno(false, "Failed to create bpf program");
return syserror_ret(false, "Failed to create bpf program");
ret = bpf_program_load_kernel(prog);
if (ret < 0)
return syserrno(false, "Failed to load bpf program");
return syserror_ret(false, "Failed to load bpf program");
attr = &(union bpf_attr){
.attach_type = prog_old->attached_type,
......@@ -693,7 +693,7 @@ bool bpf_cgroup_devices_update(struct cgroup_ops *ops,
break;
}
if (ret < 0)
return syserrno(false, "Failed to update bpf program");
return syserror_ret(false, "Failed to update bpf program");
if (can_use_bpf_replace > 0) {
/* The old program was automatically detached by the kernel. */
......
......@@ -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;
......
......@@ -1825,10 +1825,10 @@ static int set_config_cgroup_dir(const char *key, const char *value,
return clr_config_cgroup_dir(key, lxc_conf, NULL);
if (abspath(value))
return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
return syserror_set(-EINVAL, "%s paths may not be absolute", key);
if (dotdot(value))
return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
return syserror_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
return set_config_path_item(&lxc_conf->cgroup_meta.dir, value);
}
......@@ -1840,10 +1840,10 @@ static int set_config_cgroup_monitor_dir(const char *key, const char *value,
return clr_config_cgroup_monitor_dir(key, lxc_conf, NULL);
if (abspath(value))
return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
return syserror_set(-EINVAL, "%s paths may not be absolute", key);
if (dotdot(value))
return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
return syserror_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
return set_config_path_item(&lxc_conf->cgroup_meta.monitor_dir, value);
}
......@@ -1855,10 +1855,10 @@ static int set_config_cgroup_monitor_pivot_dir(const char *key, const char *valu
return clr_config_cgroup_monitor_pivot_dir(key, lxc_conf, NULL);
if (abspath(value))
return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
return syserror_set(-EINVAL, "%s paths may not be absolute", key);
if (dotdot(value))
return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
return syserror_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
return set_config_path_item(&lxc_conf->cgroup_meta.monitor_pivot_dir, value);
}
......@@ -1871,10 +1871,10 @@ static int set_config_cgroup_container_dir(const char *key, const char *value,
return clr_config_cgroup_container_dir(key, lxc_conf, NULL);
if (abspath(value))
return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
return syserror_set(-EINVAL, "%s paths may not be absolute", key);
if (dotdot(value))
return syserrno_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
return syserror_set(-EINVAL, "%s paths may not walk upwards via \"../\"", key);
return set_config_path_item(&lxc_conf->cgroup_meta.container_dir, value);
}
......@@ -1888,7 +1888,7 @@ static int set_config_cgroup_container_inner_dir(const char *key,
return clr_config_cgroup_container_inner_dir(key, lxc_conf, NULL);
if (abspath(value))
return syserrno_set(-EINVAL, "%s paths may not be absolute", key);
return syserror_set(-EINVAL, "%s paths may not be absolute", key);
if (strchr(value, '/') || strequal(value, ".") || strequal(value, ".."))
return log_error_errno(-EINVAL, EINVAL, "lxc.cgroup.dir.container.inner must be a single directory name");
......
......@@ -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);
}
......
......@@ -494,142 +494,176 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
__internal_ret__; \
})
#define syserrno(__ret__, format, ...) \
#define log_error(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
SYSERROR(format, ##__VA_ARGS__); \
ERROR(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define syswarn(__ret__, format, ...) \
#define log_trace_errno(__ret__, __errno__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
SYSWARN(format, ##__VA_ARGS__); \
errno = __errno__; \
SYSTRACE(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define systrace(__ret__, format, ...) \
#define log_trace(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
SYSTRACE(format, ##__VA_ARGS__); \
TRACE(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define sysinfo(__ret__, format, ...) \
#define log_warn_errno(__ret__, __errno__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
SYSINFO(format, ##__VA_ARGS__); \
errno = __errno__; \
SYSWARN(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define syserrno_set(__ret__, format, ...) \
#define log_warn(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
errno = labs(__ret__); \
SYSERROR(format, ##__VA_ARGS__); \
WARN(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define syswarn_set(__ret__, format, ...) \
#define log_debug_errno(__ret__, __errno__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
errno = labs(__ret__); \
SYSWARN(format, ##__VA_ARGS__); \
errno = __errno__; \
SYSDEBUG(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define syserror(format, ...) \
({ \
SYSERROR(format, ##__VA_ARGS__); \
(-errno); \
#define log_debug(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
DEBUG(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define syserror_set(__ret__, format, ...) \
#define log_info_errno(__ret__, __errno__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
errno = labs(__ret__); \
SYSERROR(format, ##__VA_ARGS__); \
errno = __errno__; \
SYSINFO(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define sysdebug(format, ...) \
#define log_info(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
INFO(format, ##__VA_ARGS__); \
__internal_ret__; \
})
/* These are the logging return helpers to be used. */
#define syserror(format, ...) \
({ \
SYSDEBUG(format, ##__VA_ARGS__); \
SYSERROR(format, ##__VA_ARGS__); \
(-errno); \
})
#define sysdebug_set(__ret__, format, ...) \
#define syserror_set(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
errno = labs(__ret__); \
SYSDEBUG(format, ##__VA_ARGS__); \
SYSERROR(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_error(__ret__, format, ...) \
#define syserror_ret(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
ERROR(format, ##__VA_ARGS__); \
SYSERROR(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_trace_errno(__ret__, __errno__, format, ...) \
#define syswarn(format, ...) \
({ \
SYSWARN(format, ##__VA_ARGS__); \
(-errno); \
})
#define syswarn_set(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
errno = __errno__; \
SYSTRACE(format, ##__VA_ARGS__); \
errno = labs(__ret__); \
SYSWARN(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_trace(__ret__, format, ...) \
#define syswarn_ret(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
TRACE(format, ##__VA_ARGS__); \
SYSWARN(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_warn_errno(__ret__, __errno__, format, ...) \
#define sysinfo(format, ...) \
({ \
SYSINFO(format, ##__VA_ARGS__); \
(-errno); \
})
#define sysinfo_set(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
errno = __errno__; \
SYSWARN(format, ##__VA_ARGS__); \
errno = labs(__ret__); \
SYSINFO(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_warn(__ret__, format, ...) \
#define sysinfo_ret(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
WARN(format, ##__VA_ARGS__); \
SYSINFO(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_debug_errno(__ret__, __errno__, format, ...) \
#define sysdebug(format, ...) \
({ \
SYSDEBUG(format, ##__VA_ARGS__); \
(-errno); \
})
#define sysdebug_set(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
errno = __errno__; \
errno = labs(__ret__); \
SYSDEBUG(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_debug(__ret__, format, ...) \
#define sysdebug_ret(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
DEBUG(format, ##__VA_ARGS__); \
SYSDEBUG(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_info_errno(__ret__, __errno__, format, ...) \
#define systrace(format, ...) \
({ \
SYSTRACE(format, ##__VA_ARGS__); \
(-errno); \
})
#define systrace_set(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
errno = __errno__; \
SYSINFO(format, ##__VA_ARGS__); \
errno = labs(__ret__); \
SYSTRACE(format, ##__VA_ARGS__); \
__internal_ret__; \
})
#define log_info(__ret__, format, ...) \
#define systrace_ret(__ret__, format, ...) \
({ \
typeof(__ret__) __internal_ret__ = (__ret__); \
INFO(format, ##__VA_ARGS__); \
SYSTRACE(format, ##__VA_ARGS__); \
__internal_ret__; \
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment