summaryrefslogtreecommitdiff
path: root/src/coredump
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-12-19 13:07:42 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-12-19 15:00:57 +0100
commit254d1313ae5a69c08c9b93032aaaf3d6083cfc07 (patch)
tree067102a36abe6bf597c26a42d79018a1060c9007 /src/coredump
parentcbff793ffb280d9d11e5d7b1dc3964276491bee8 (diff)
downloadsystemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.tar.gz
tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
Diffstat (limited to 'src/coredump')
-rw-r--r--src/coredump/coredump.c16
-rw-r--r--src/coredump/coredumpctl.c6
2 files changed, 11 insertions, 11 deletions
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index 50220c5ec7..4ca19370f3 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -344,7 +344,7 @@ static int save_external_coredump(
_cleanup_(unlink_and_freep) char *tmp = NULL;
_cleanup_free_ char *fn = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint64_t rlimit, process_limit, max_size;
bool truncated, storage_on_tmpfs;
struct stat st;
@@ -458,7 +458,7 @@ static int save_external_coredump(
if (arg_compress) {
_cleanup_(unlink_and_freep) char *tmp_compressed = NULL;
_cleanup_free_ char *fn_compressed = NULL;
- _cleanup_close_ int fd_compressed = -1;
+ _cleanup_close_ int fd_compressed = -EBADF;
uint64_t uncompressed_size = 0;
if (lseek(fd, 0, SEEK_SET) == (off_t) -1)
@@ -584,7 +584,7 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
*/
static int compose_open_fds(pid_t pid, char **open_fds) {
_cleanup_closedir_ DIR *proc_fd_dir = NULL;
- _cleanup_close_ int proc_fdinfo_fd = -1;
+ _cleanup_close_ int proc_fdinfo_fd = -EBADF;
_cleanup_free_ char *buffer = NULL;
_cleanup_fclose_ FILE *stream = NULL;
const char *fddelim = "", *path;
@@ -610,7 +610,7 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
FOREACH_DIRENT(de, proc_fd_dir, return -errno) {
_cleanup_fclose_ FILE *fdinfo = NULL;
_cleanup_free_ char *fdname = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
r = readlinkat_malloc(dirfd(proc_fd_dir), de->d_name, &fdname);
if (r < 0)
@@ -656,7 +656,7 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
static int get_process_ns(pid_t pid, const char *namespace, ino_t *ns) {
const char *p;
struct stat stbuf;
- _cleanup_close_ int proc_ns_dir_fd = -1;
+ _cleanup_close_ int proc_ns_dir_fd = -EBADF;
p = procfs_file_alloca(pid, "ns");
@@ -771,7 +771,7 @@ static int submit_coredump(
int input_fd) {
_cleanup_(json_variant_unrefp) JsonVariant *json_metadata = NULL;
- _cleanup_close_ int coredump_fd = -1, coredump_node_fd = -1;
+ _cleanup_close_ int coredump_fd = -EBADF, coredump_node_fd = -EBADF;
_cleanup_free_ char *filename = NULL, *coredump_data = NULL;
_cleanup_free_ char *stacktrace = NULL;
char *core_message;
@@ -976,7 +976,7 @@ static int save_context(Context *context, const struct iovec_wrapper *iovw) {
}
static int process_socket(int fd) {
- _cleanup_close_ int input_fd = -1;
+ _cleanup_close_ int input_fd = -EBADF;
Context context = {};
struct iovec_wrapper iovw = {};
struct iovec iovec;
@@ -1074,7 +1074,7 @@ finish:
}
static int send_iovec(const struct iovec_wrapper *iovw, int input_fd) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(iovw);
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c
index 6a6a968149..8a4f31aa62 100644
--- a/src/coredump/coredumpctl.c
+++ b/src/coredump/coredumpctl.c
@@ -451,7 +451,7 @@ static void analyze_coredump_file(
const char **ret_color,
uint64_t *ret_size) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
int r;
@@ -965,7 +965,7 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
_cleanup_free_ char *filename = NULL;
size_t len;
int r, fd;
- _cleanup_close_ int fdt = -1;
+ _cleanup_close_ int fdt = -EBADF;
char *temp = NULL;
assert(!(file && path)); /* At most one can be specified */
@@ -1047,7 +1047,7 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
if (filename) {
#if HAVE_COMPRESSION
- _cleanup_close_ int fdf = -1;
+ _cleanup_close_ int fdf = -EBADF;
fdf = open(filename, O_RDONLY | O_CLOEXEC);
if (fdf < 0) {