]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use -EBADF for fd initialization
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Dec 2022 12:07:42 +0000 (13:07 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Dec 2022 14:00:57 +0000 (15:00 +0100)
-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.

284 files changed:
coccinelle/safe_close.cocci
docs/BLOCK_DEVICE_LOCKING.md
src/activate/activate.c
src/analyze/analyze-inspect-elf.c
src/basic/chase-symlinks.c
src/basic/chattr-util.c
src/basic/efivars.c
src/basic/fd-util.c
src/basic/fd-util.h
src/basic/fileio.c
src/basic/fs-util.c
src/basic/locale-util.c
src/basic/log.c
src/basic/memfd-util.c
src/basic/mkdir.c
src/basic/mountpoint-util.c
src/basic/namespace-util.c
src/basic/os-util.c
src/basic/path-util.c
src/basic/random-util.c
src/basic/recurse-dir.c
src/basic/socket-util.c
src/basic/stat-util.c
src/basic/sync-util.c
src/basic/terminal-util.c
src/basic/time-util.c
src/basic/tmpfile-util.c
src/basic/xattr-util.c
src/boot/bless-boot.c
src/boot/bootctl-install.c
src/boot/bootctl-random-seed.c
src/boot/bootctl-status.c
src/boot/measure.c
src/cgroups-agent/cgroups-agent.c
src/core/automount.c
src/core/bpf-firewall.c
src/core/bpf-lsm.c
src/core/bpf-socket-bind.c
src/core/dbus-manager.c
src/core/dbus-path.c
src/core/dbus-socket.c
src/core/dbus.c
src/core/dynamic-user.c
src/core/efi-random.c
src/core/execute.c
src/core/ima-setup.c
src/core/import-creds.c
src/core/load-fragment.c
src/core/main.c
src/core/manager-serialize.c
src/core/manager.c
src/core/mount.c
src/core/namespace.c
src/core/path.c
src/core/restrict-ifaces.c
src/core/service.c
src/core/show-status.c
src/core/smack-setup.c
src/core/socket.c
src/core/swap.c
src/core/unit.c
src/coredump/coredump.c
src/coredump/coredumpctl.c
src/creds/creds.c
src/dissect/dissect.c
src/fsck/fsck.c
src/fuzz/fuzz-bootspec.c
src/fuzz/fuzz-catalog.c
src/getty-generator/getty-generator.c
src/home/homectl.c
src/home/homed-home-bus.c
src/home/homed-home.c
src/home/homed-manager.c
src/home/homed-operation.c
src/home/homework-directory.c
src/home/homework-fscrypt.c
src/home/homework-luks.c
src/home/homework-mount.c
src/home/homework.c
src/home/homework.h
src/home/pam_systemd_home.c
src/import/export-raw.c
src/import/export-tar.c
src/import/export.c
src/import/import-fs.c
src/import/import-raw.c
src/import/import-tar.c
src/import/import.c
src/import/importd.c
src/import/pull-job.c
src/import/pull-raw.c
src/import/test-qcow2.c
src/journal-remote/fuzz-journal-remote.c
src/journal-remote/journal-gatewayd.c
src/journal-remote/journal-remote.c
src/journal/cat.c
src/journal/fuzz-journald-native-fd.c
src/journal/fuzz-journald.c
src/journal/journalctl.c
src/journal/journald-console.c
src/journal/journald-kmsg.c
src/journal/journald-server.c
src/journal/journald-stream.c
src/libsystemd-network/lldp-network.c
src/libsystemd-network/sd-dhcp-client.c
src/libsystemd-network/sd-dhcp-server.c
src/libsystemd-network/sd-dhcp6-client.c
src/libsystemd-network/sd-ipv4acd.c
src/libsystemd-network/sd-lldp-rx.c
src/libsystemd-network/sd-lldp-tx.c
src/libsystemd-network/sd-ndisc.c
src/libsystemd-network/sd-radv.c
src/libsystemd/sd-bus/bus-container.c
src/libsystemd/sd-bus/bus-message.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-bus/test-bus-watch-bind.c
src/libsystemd/sd-daemon/sd-daemon.c
src/libsystemd/sd-device/device-util.c
src/libsystemd/sd-device/sd-device.c
src/libsystemd/sd-device/test-sd-device.c
src/libsystemd/sd-event/event-util.c
src/libsystemd/sd-event/sd-event.c
src/libsystemd/sd-event/test-event.c
src/libsystemd/sd-id128/id128-util.c
src/libsystemd/sd-journal/catalog.c
src/libsystemd/sd-journal/journal-authenticate.c
src/libsystemd/sd-journal/journal-send.c
src/libsystemd/sd-journal/journal-vacuum.c
src/libsystemd/sd-journal/journal-verify.c
src/libsystemd/sd-journal/sd-journal.c
src/libsystemd/sd-journal/test-catalog.c
src/libsystemd/sd-login/sd-login.c
src/libsystemd/sd-netlink/netlink-util.c
src/libsystemd/sd-netlink/sd-netlink.c
src/libsystemd/sd-network/sd-network.c
src/libsystemd/sd-resolve/sd-resolve.c
src/libudev/libudev-queue.c
src/login/inhibit.c
src/login/logind-button.c
src/login/logind-core.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-seat.c
src/login/logind-session-dbus.c
src/login/logind-session-device.c
src/login/logind-session.c
src/login/logind.c
src/login/pam_systemd.c
src/machine/image-dbus.c
src/machine/machine-dbus.c
src/machine/machinectl.c
src/machine/machined-dbus.c
src/machine/operation.c
src/network/netdev/tuntap.c
src/network/networkctl.c
src/network/networkd-manager.c
src/nspawn/nspawn-cgroup.c
src/nspawn/nspawn-expose-ports.c
src/nspawn/nspawn-patch-uid.c
src/nspawn/nspawn-setuid.c
src/nspawn/nspawn.c
src/oom/oomctl.c
src/oom/oomd-manager-bus.c
src/oom/test-oomd-util.c
src/partition/growfs.c
src/partition/makefs.c
src/partition/repart.c
src/portable/portable.c
src/portable/portabled-bus.c
src/portable/portabled-image-bus.c
src/portable/portabled-operation.c
src/pstore/pstore.c
src/random-seed/random-seed.c
src/reply-password/reply-password.c
src/resolve/resolved-dns-scope.c
src/resolve/resolved-dns-stream.c
src/resolve/resolved-dns-stub.c
src/resolve/resolved-dns-transaction.c
src/resolve/resolved-manager.c
src/resolve/test-resolved-stream.c
src/shared/acpi-fpdt.c
src/shared/ask-password-api.c
src/shared/base-filesystem.c
src/shared/blockdev-util.c
src/shared/bootspec.c
src/shared/bpf-program.c
src/shared/btrfs-util.c
src/shared/cgroup-show.c
src/shared/chown-recursive.c
src/shared/clock-util.c
src/shared/copy.c
src/shared/creds-util.c
src/shared/data-fd-util.c
src/shared/discover-image.c
src/shared/dissect-image.c
src/shared/dissect-image.h
src/shared/dm-util.c
src/shared/ethtool-util.c
src/shared/exec-util.c
src/shared/fdset.c
src/shared/find-esp.c
src/shared/install-file.c
src/shared/install.c
src/shared/local-addresses.c
src/shared/lockfile-util.c
src/shared/lockfile-util.h
src/shared/logs-show.c
src/shared/loop-util.c
src/shared/machine-id-setup.c
src/shared/mkfs-util.c
src/shared/mount-util.c
src/shared/nscd-flush.c
src/shared/ptyfwd.c
src/shared/reboot-util.c
src/shared/selinux-util.c
src/shared/sleep-config.c
src/shared/smack-util.c
src/shared/socket-label.c
src/shared/specifier.c
src/shared/switch-root.c
src/shared/tests.c
src/shared/udev-util.c
src/shared/utmp-wtmp.c
src/shared/varlink.c
src/shared/watchdog.c
src/shutdown/umount.c
src/sleep/sleep.c
src/socket-proxy/socket-proxyd.c
src/systemctl/fuzz-systemctl-parse-argv.c
src/systemctl/systemctl-sysv-compat.c
src/sysupdate/sysupdate-resource.c
src/test/test-acl-util.c
src/test/test-chase-symlinks.c
src/test/test-copy.c
src/test/test-data-fd-util.c
src/test/test-fd-util.c
src/test/test-fdset.c
src/test/test-fileio.c
src/test/test-fs-util.c
src/test/test-glob-util.c
src/test/test-id128.c
src/test/test-io-util.c
src/test/test-loop-block.c
src/test/test-mountpoint-util.c
src/test/test-namespace.c
src/test/test-path-util.c
src/test/test-process-util.c
src/test/test-psi-util.c
src/test/test-seccomp.c
src/test/test-selinux.c
src/test/test-sigbus.c
src/test/test-sleep.c
src/test/test-socket-util.c
src/test/test-stat-util.c
src/test/test-tmpfiles.c
src/test/test-varlink.c
src/test/test-xattr-util.c
src/timesync/timesyncd.c
src/timesync/wait-sync.c
src/tmpfiles/offline-passwd.c
src/tmpfiles/tmpfiles.c
src/tty-ask-password-agent/tty-ask-password-agent.c
src/udev/ata_id/ata_id.c
src/udev/cdrom_id/cdrom_id.c
src/udev/fido_id/fido_id.c
src/udev/mtd_probe/mtd_probe.c
src/udev/net/link-config.c
src/udev/scsi_id/scsi_serial.c
src/udev/udev-builtin-blkid.c
src/udev/udev-builtin-btrfs.c
src/udev/udev-builtin-input_id.c
src/udev/udev-builtin-keyboard.c
src/udev/udev-builtin-usb_id.c
src/udev/udev-node.c
src/udev/udev-watch.c
src/udev/udevadm-lock.c
src/udev/udevd.c
src/udev/v4l_id/v4l_id.c
src/update-utmp/update-utmp.c
src/userdb/userdbctl.c
src/userdb/userdbd-manager.c
src/userdb/userwork.c
src/vconsole/vconsole-setup.c
src/xdg-autostart-generator/fuzz-xdg-desktop.c

index 36a853725176c872d0674f95b93a494fa9d48b93..49254b6fff5e1c5ad0b52093203ae5196daf86bc 100644 (file)
@@ -3,17 +3,17 @@
 expression fd;
 @@
 - close(fd);
-- fd = -1;
+- fd = -EBADF;
 + fd = safe_close(fd);
 @@
 expression fd;
 @@
 - close_nointr(fd);
-- fd = -1;
+- fd = -EBADF;
 + fd = safe_close(fd);
 @@
 expression fd;
 @@
 - safe_close(fd);
-- fd = -1;
+- fd = -EBADF;
 + fd = safe_close(fd);
index 862d6f0369d81fccc8808179a0271392c9912d9b..a6e3374bc7932dcfea6de6b761dbcfcb45e282c7 100644 (file)
@@ -213,7 +213,7 @@ int lock_whole_disk_from_devname(const char *devname, int open_flags, int flock_
 
     // take the fd to avoid automatic cleanup
     int ret_fd = fd;
-    fd = -1;
+    fd = -EBADF;
     return ret_fd;
 }
 
index 5934e7a57a629654df467ceee8de990aa48676e4..16463a9b93f2ffd09ddeebd55e4d84c3ef0f4bd2 100644 (file)
@@ -233,7 +233,7 @@ static int fork_and_exec_process(const char *child, char **argv, int fd) {
 
 static int do_accept(const char *name, char **argv, int fd) {
         _cleanup_free_ char *local = NULL, *peer = NULL;
-        _cleanup_close_ int fd_accepted = -1;
+        _cleanup_close_ int fd_accepted = -EBADF;
 
         fd_accepted = accept4(fd, NULL, NULL, 0);
         if (fd_accepted < 0) {
@@ -434,7 +434,7 @@ static int parse_argv(int argc, char *argv[]) {
 
 int main(int argc, char **argv) {
         int r, n;
-        int epoll_fd = -1;
+        int epoll_fd = -EBADF;
 
         log_show_color(true);
         log_parse_environment();
index cb6692e2771d814c6c1ca315c68f5f0f6303d5e8..70226a842b27a54a0b189f4b3081157229cf7780 100644 (file)
@@ -18,7 +18,7 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) {
                 _cleanup_(json_variant_unrefp) JsonVariant *package_metadata = NULL;
                 _cleanup_(table_unrefp) Table *t = NULL;
                 _cleanup_free_ char *abspath = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 r = path_make_absolute_cwd(*filename, &abspath);
                 if (r < 0)
index 385d0aed6984b8b9f619311b2ace96ffb2810059..a9de17b47631f30f2cc8c542cbe169cb4ab2e90a 100644 (file)
@@ -80,7 +80,7 @@ int chase_symlinks_at(
                 int *ret_fd) {
 
         _cleanup_free_ char *buffer = NULL, *done = NULL;
-        _cleanup_close_ int fd = -1, root_fd = -1;
+        _cleanup_close_ int fd = -EBADF, root_fd = -EBADF;
         unsigned max_follow = CHASE_SYMLINKS_MAX; /* how many symlinks to follow before giving up and returning ELOOP */
         bool exists = true, append_trail_slash = false;
         struct stat previous_stat;
@@ -227,7 +227,7 @@ int chase_symlinks_at(
                 /* Two dots? Then chop off the last bit of what we already found out. */
                 if (path_equal(first, "..")) {
                         _cleanup_free_ char *parent = NULL;
-                        _cleanup_close_ int fd_parent = -1;
+                        _cleanup_close_ int fd_parent = -EBADF;
 
                         /* If we already are at the top, then going up will not change anything. This is
                          * in-line with how the kernel handles this. */
@@ -415,7 +415,7 @@ int chase_symlinks(
                 int *ret_fd) {
 
         _cleanup_free_ char *root = NULL, *absolute = NULL, *p = NULL;
-        _cleanup_close_ int fd = -1, pfd = -1;
+        _cleanup_close_ int fd = -EBADF, pfd = -EBADF;
         int r;
 
         assert(path);
@@ -496,7 +496,7 @@ int chase_symlinks_and_open(
                 int open_flags,
                 char **ret_path) {
 
-        _cleanup_close_ int path_fd = -1;
+        _cleanup_close_ int path_fd = -EBADF;
         _cleanup_free_ char *p = NULL;
         int r;
 
@@ -534,7 +534,7 @@ int chase_symlinks_and_opendir(
                 char **ret_path,
                 DIR **ret_dir) {
 
-        _cleanup_close_ int path_fd = -1;
+        _cleanup_close_ int path_fd = -EBADF;
         _cleanup_free_ char *p = NULL;
         DIR *d;
         int r;
@@ -578,7 +578,7 @@ int chase_symlinks_and_stat(
                 struct stat *ret_stat,
                 int *ret_fd) {
 
-        _cleanup_close_ int path_fd = -1;
+        _cleanup_close_ int path_fd = -EBADF;
         _cleanup_free_ char *p = NULL;
         int r;
 
@@ -621,7 +621,7 @@ int chase_symlinks_and_access(
                 char **ret_path,
                 int *ret_fd) {
 
-        _cleanup_close_ int path_fd = -1;
+        _cleanup_close_ int path_fd = -EBADF;
         _cleanup_free_ char *p = NULL;
         int r;
 
@@ -665,7 +665,7 @@ int chase_symlinks_and_fopen_unlocked(
                 FILE **ret_file) {
 
         _cleanup_free_ char *final_path = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int mode_flags, r;
 
         assert(path);
index eddde132aaea896619225c0e01121dadb761a3b4..3c66a3e0c83bcddd293121cb74719a426f3e48bf 100644 (file)
@@ -20,7 +20,7 @@ int chattr_full(const char *path,
                 unsigned *ret_final,
                 ChattrApplyFlags flags) {
 
-        _cleanup_close_ int fd_will_close = -1;
+        _cleanup_close_ int fd_will_close = -EBADF;
         unsigned old_attr, new_attr;
         int set_flags_errno = 0;
         struct stat st;
@@ -149,7 +149,7 @@ int read_attr_fd(int fd, unsigned *ret) {
 }
 
 int read_attr_path(const char *p, unsigned *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(p);
         assert(ret);
index 17e0fb895e637e4284d8e08c118c99ae7aad5d13..e7ece805d4cae64471e1cd0872ffb8faf61b7756 100644 (file)
@@ -37,7 +37,7 @@ int efi_get_variable(
                 void **ret_value,
                 size_t *ret_size) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ void *buf = NULL;
         struct stat st;
         usec_t begin = 0; /* Unnecessary initialization to appease gcc */
@@ -181,7 +181,7 @@ int efi_set_variable(const char *variable, const void *value, size_t size) {
                 uint32_t attr;
                 char buf[];
         } _packed_ * _cleanup_free_ buf = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         uint32_t attr = EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS;
         bool saved_flags_valid = false;
         unsigned saved_flags;
index b97039284cdab820ce393ee529eac8ec73f7e5e9..4ab972b13e3d62c229f4c1a4df5a8b931bf664a1 100644 (file)
@@ -56,11 +56,9 @@ int close_nointr(int fd) {
 }
 
 int safe_close(int fd) {
-
         /*
-         * Like close_nointr() but cannot fail. Guarantees errno is
-         * unchanged. Is a NOP with negative fds passed, and returns
-         * -1, so that it can be used in this syntax:
+         * Like close_nointr() but cannot fail. Guarantees errno is unchanged. Is a noop for negative fds,
+         * and returns -EBADF, so that it can be used in this syntax:
          *
          * fd = safe_close(fd);
          */
@@ -76,7 +74,7 @@ int safe_close(int fd) {
                 assert_se(close_nointr(fd) != -EBADF);
         }
 
-        return -1;
+        return -EBADF;
 }
 
 void safe_close_pair(int p[static 2]) {
@@ -412,7 +410,7 @@ int close_all_fds(const int except[], size_t n_except) {
                 return close_all_fds_frugal(except, n_except); /* ultimate fallback if /proc/ is not available */
 
         FOREACH_DIRENT(de, d, return -errno) {
-                int fd = -1, q;
+                int fd = -EBADF, q;
 
                 if (!IN_SET(de->d_type, DT_LNK, DT_UNKNOWN))
                         continue;
@@ -639,17 +637,19 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
         };
 
         int r, i,
-                null_fd = -1,                /* if we open /dev/null, we store the fd to it here */
-                copy_fd[3] = { -1, -1, -1 }; /* This contains all fds we duplicate here temporarily, and hence need to close at the end */
+                null_fd = -EBADF,                        /* If we open /dev/null, we store the fd to it here */
+                copy_fd[3] = { -EBADF, -EBADF, -EBADF }; /* This contains all fds we duplicate here
+                                                          * temporarily, and hence need to close at the end. */
         bool null_readable, null_writable;
 
-        /* Sets up stdin, stdout, stderr with the three file descriptors passed in. If any of the descriptors is
-         * specified as -1 it will be connected with /dev/null instead. If any of the file descriptors is passed as
-         * itself (e.g. stdin as STDIN_FILENO) it is left unmodified, but the O_CLOEXEC bit is turned off should it be
-         * on.
+        /* Sets up stdin, stdout, stderr with the three file descriptors passed in. If any of the descriptors
+         * is specified as -EBADF it will be connected with /dev/null instead. If any of the file descriptors
+         * is passed as itself (e.g. stdin as STDIN_FILENO) it is left unmodified, but the O_CLOEXEC bit is
+         * turned off should it be on.
          *
-         * Note that if any of the passed file descriptors are > 2 they will be closed — both on success and on
-         * failure! Thus, callers should assume that when this function returns the input fds are invalidated.
+         * Note that if any of the passed file descriptors are > 2 they will be closed — both on success and
+         * on failure! Thus, callers should assume that when this function returns the input fds are
+         * invalidated.
          *
          * Note that when this function fails stdin/stdout/stderr might remain half set up!
          *
@@ -701,9 +701,9 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
                 }
         }
 
-        /* At this point we now have the fds to use in fd[], and they are all above the stdio range, so that we
-         * have freedom to move them around. If the fds already were at the right places then the specific fds are
-         * -1. Let's now move them to the right places. This is the point of no return. */
+        /* At this point we now have the fds to use in fd[], and they are all above the stdio range, so that
+         * we have freedom to move them around. If the fds already were at the right places then the specific
+         * fds are -EBADF. Let's now move them to the right places. This is the point of no return. */
         for (i = 0; i < 3; i++) {
 
                 if (fd[i] == i) {
@@ -800,7 +800,7 @@ int fd_reopen_condition(
                 return -errno;
 
         if ((r & mask) == (flags & mask)) {
-                *ret_new_fd = -1;
+                *ret_new_fd = -EBADF;
                 return fd;
         }
 
index fbaa45861342fa51a5119f658bd5ec6c3a28a5a9..530270a73fe00acb083a666b1672299b095e2b5b 100644 (file)
@@ -94,7 +94,7 @@ static inline int make_null_stdio(void) {
         ({                                      \
                 int *_fd_ = &(fd);              \
                 int _ret_ = *_fd_;              \
-                *_fd_ = -1;                     \
+                *_fd_ = -EBADF;                 \
                 _ret_;                          \
         })
 
index 5078cae2df1ec4f3b7fec0a766965d629ccae49c..a9015979620e810adc2621487439000cb04a222b 100644 (file)
@@ -80,7 +80,7 @@ int take_fdopen_unlocked(int *fd, const char *options, FILE **ret) {
         if (r < 0)
                 return r;
 
-        *fd = -1;
+        *fd = -EBADF;
 
         return 0;
 }
@@ -92,7 +92,7 @@ FILE* take_fdopen(int *fd, const char *options) {
         if (!f)
                 return NULL;
 
-        *fd = -1;
+        *fd = -EBADF;
 
         return f;
 }
@@ -104,7 +104,7 @@ DIR* take_fdopendir(int *dfd) {
         if (!d)
                 return NULL;
 
-        *dfd = -1;
+        *dfd = -EBADF;
 
         return d;
 }
@@ -136,7 +136,7 @@ int write_string_stream_ts(
                 const struct timespec *ts) {
 
         bool needs_nl;
-        int r, fd = -1;
+        int r, fd = -EBADF;
 
         assert(f);
         assert(line);
@@ -558,7 +558,7 @@ int read_virtual_file_at(
                 char **ret_contents,
                 size_t *ret_size) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
 
index fbc7492b15264f0826b824403a67fe16a112e136..ed020b1b08b988369d95aa01f3f358d6b34958e2 100644 (file)
@@ -195,7 +195,7 @@ int readlink_and_make_absolute(const char *p, char **r) {
 }
 
 int chmod_and_chown_at(int dir_fd, const char *path, mode_t mode, uid_t uid, gid_t gid) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
 
@@ -360,7 +360,7 @@ int fd_warn_permissions(const char *path, int fd) {
 }
 
 int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r, ret;
 
         assert(path);
@@ -684,7 +684,7 @@ void unlink_tempfilep(char (*p)[]) {
 }
 
 int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {
-        _cleanup_close_ int truncate_fd = -1;
+        _cleanup_close_ int truncate_fd = -EBADF;
         struct stat st;
         off_t l, bs;
 
@@ -815,7 +815,7 @@ int conservative_renameat(
                 int olddirfd, const char *oldpath,
                 int newdirfd, const char *newpath) {
 
-        _cleanup_close_ int old_fd = -1, new_fd = -1;
+        _cleanup_close_ int old_fd = -EBADF, new_fd = -EBADF;
         struct stat old_stat, new_stat;
 
         /* Renames the old path to thew new path, much like renameat() — except if both are regular files and
@@ -997,7 +997,7 @@ int parse_cifs_service(
 }
 
 int open_mkdir_at(int dirfd, const char *path, int flags, mode_t mode) {
-        _cleanup_close_ int fd = -1, parent_fd = -1;
+        _cleanup_close_ int fd = -EBADF, parent_fd = -EBADF;
         _cleanup_free_ char *fname = NULL;
         bool made;
         int r;
index 40c6e46ab888e2760d9bc21c20df281b0f28c8f0..d94fbcff4b97d2fef939dcf666970272d886834e 100644 (file)
@@ -95,7 +95,7 @@ static int add_locales_from_archive(Set *locales) {
         const struct locarhead *h;
         const struct namehashent *e;
         const void *p = MAP_FAILED;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         size_t sz = 0;
         struct stat st;
         int r;
index 173643196e7dbbc9d45f216bf5563876200bfb7f..282130345f3b458858864202794b18fb1a329c09 100644 (file)
@@ -48,9 +48,9 @@ static int log_max_level = LOG_INFO;
 static int log_facility = LOG_DAEMON;
 
 static int console_fd = STDERR_FILENO;
-static int syslog_fd = -1;
-static int kmsg_fd = -1;
-static int journal_fd = -1;
+static int syslog_fd = -EBADF;
+static int kmsg_fd = -EBADF;
+static int journal_fd = -EBADF;
 
 static bool syslog_is_stream = false;
 
@@ -345,7 +345,7 @@ void log_close(void) {
 void log_forget_fds(void) {
         /* Do not call from library code. */
 
-        console_fd = kmsg_fd = syslog_fd = journal_fd = -1;
+        console_fd = kmsg_fd = syslog_fd = journal_fd = -EBADF;
 }
 
 void log_set_max_level(int level) {
index f05fb1524e82d8f773229c861324952d8de725c2..fb86ac2b5bab6f154c4640471a0873c2c6a5c80a 100644 (file)
@@ -113,7 +113,7 @@ int memfd_set_size(int fd, uint64_t sz) {
 }
 
 int memfd_new_and_map(const char *name, size_t sz, void **p) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(sz > 0);
index 6796d4aeda947fa961429d6bdb5124bd9a40f0f3..7ad19ee33b7f9147ae0d2903259c33707fb5846a 100644 (file)
@@ -211,7 +211,7 @@ int mkdir_p_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, g
 
 int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m) {
         _cleanup_free_ char *pp = NULL, *bn = NULL;
-        _cleanup_close_ int dfd = -1;
+        _cleanup_close_ int dfd = -EBADF;
         int r;
 
         r = path_extract_directory(p, &pp);
@@ -250,7 +250,7 @@ int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m
         }
 
         if (uid_is_valid(uid) || gid_is_valid(gid)) {
-                _cleanup_close_ int nfd = -1;
+                _cleanup_close_ int nfd = -EBADF;
 
                 nfd = openat(dfd, bn, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
                 if (nfd < 0)
index 1136454b7df79a7f0f571f85932a6db6d724eaf6..bc74fbef8f7cd840b84bd3ca802d420ae7cba0d0 100644 (file)
@@ -97,7 +97,7 @@ int name_to_handle_at_loop(
 static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mnt_id) {
         char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
         _cleanup_free_ char *fdinfo = NULL;
-        _cleanup_close_ int subfd = -1;
+        _cleanup_close_ int subfd = -EBADF;
         char *p;
         int r;
 
@@ -322,7 +322,7 @@ fallback_fstat:
 /* flags can be AT_SYMLINK_FOLLOW or 0 */
 int path_is_mount_point(const char *t, const char *root, int flags) {
         _cleanup_free_ char *canonical = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(t);
@@ -550,7 +550,7 @@ int mount_nofollow(
                 unsigned long mountflags,
                 const void *data) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         /* In almost all cases we want to manipulate the mount table without following symlinks, hence
          * mount_nofollow() is usually the way to go. The only exceptions are environments where /proc/ is
index a87a875943c7dfcd8dba681dd7cea48e2d7f0d4a..f5c0e04cecb1015611ea1f07954886952f10db16 100644 (file)
@@ -34,8 +34,8 @@ const struct namespace_info namespace_info[] = {
 #define pid_namespace_path(pid, type) procfs_file_alloca(pid, namespace_info[type].proc_path)
 
 int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd) {
-        _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, netnsfd = -1, usernsfd = -1;
-        int rfd = -1;
+        _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, netnsfd = -EBADF, usernsfd = -EBADF;
+        int rfd = -EBADF;
 
         assert(pid >= 0);
 
@@ -113,7 +113,7 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
                 if (r < 0)
                         return r;
                 if (r)
-                        userns_fd = -1;
+                        userns_fd = -EBADF;
         }
 
         if (pidns_fd >= 0)
@@ -202,7 +202,7 @@ int detach_mount_namespace(void) {
 int userns_acquire(const char *uid_map, const char *gid_map) {
         char path[STRLEN("/proc//uid_map") + DECIMAL_STR_MAX(pid_t) + 1];
         _cleanup_(sigkill_waitp) pid_t pid = 0;
-        _cleanup_close_ int userns_fd = -1;
+        _cleanup_close_ int userns_fd = -EBADF;
         int r;
 
         assert(uid_map);
index 8f8bb0881e957e6ea469744dde879b544578b1b8..9c21dc3bdc56e2cd7df725a0ab96e965180fb87e 100644 (file)
@@ -227,7 +227,7 @@ int open_extension_release(const char *root, const char *extension, bool relax_e
 
 int fopen_extension_release(const char *root, const char *extension, bool relax_extension_release_check, char **ret_path, FILE **ret_file) {
         _cleanup_free_ char *p = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         FILE *f;
         int r;
 
index bf93990fde1db8422f37ca8bfdf46b3a0083bff1..cc45cb311e778f528b9a6a5314d531c52b51fa47 100644 (file)
@@ -587,7 +587,7 @@ char* path_extend_internal(char **x, ...) {
 }
 
 static int check_x_access(const char *path, int *ret_fd) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         /* We need to use O_PATH because there may be executables for which we have only exec
@@ -615,7 +615,7 @@ static int check_x_access(const char *path, int *ret_fd) {
 }
 
 static int find_executable_impl(const char *name, const char *root, char **ret_filename, int *ret_fd) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *path_name = NULL;
         int r;
 
index d8734cc7d0faf78edcfc3f21044228df73c45b0e..28ace92f194d3d88b5771d5c24c1917a999d449d 100644 (file)
@@ -75,7 +75,7 @@ static void fallback_random_bytes(void *p, size_t n) {
 
 void random_bytes(void *p, size_t n) {
         static bool have_getrandom = true, have_grndinsecure = true;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         if (n == 0)
                 return;
@@ -117,7 +117,7 @@ void random_bytes(void *p, size_t n) {
 
 int crypto_random_bytes(void *p, size_t n) {
         static bool have_getrandom = true, seen_initialized = false;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         if (n == 0)
                 return 0;
@@ -145,7 +145,7 @@ int crypto_random_bytes(void *p, size_t n) {
         }
 
         if (!seen_initialized) {
-                _cleanup_close_ int ready_fd = -1;
+                _cleanup_close_ int ready_fd = -EBADF;
                 int r;
 
                 ready_fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY);
@@ -187,7 +187,7 @@ size_t random_pool_size(void) {
 }
 
 int random_write_entropy(int fd, const void *seed, size_t size, bool credit) {
-        _cleanup_close_ int opened_fd = -1;
+        _cleanup_close_ int opened_fd = -EBADF;
         int r;
 
         assert(seed || size == 0);
index fe18b98d5b8672ff0357e675b618b046237e91e7..5e98b7a5d8d66102cb345f194fee33688acfa01e 100644 (file)
@@ -182,7 +182,7 @@ int recurse_dir(
                 return r;
 
         for (size_t i = 0; i < de->n_entries; i++) {
-                _cleanup_close_ int inode_fd = -1, subdir_fd = -1;
+                _cleanup_close_ int inode_fd = -EBADF, subdir_fd = -EBADF;
                 _cleanup_free_ char *joined = NULL;
                 STRUCT_STATX_DEFINE(sx);
                 bool sx_valid = false;
@@ -490,7 +490,7 @@ int recurse_dir_at(
                 recurse_dir_func_t func,
                 void *userdata) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(atfd >= 0 || atfd == AT_FDCWD);
         assert(func);
index f39be19a598e450d33372f25da5bd3f11f47ba29..54f5f1cc5bca053d88e910e7609e00abf70ec5f7 100644 (file)
@@ -1049,7 +1049,7 @@ ssize_t receive_one_fd_iov(
         if (found)
                 *ret_fd = *(int*) CMSG_DATA(found);
         else
-                *ret_fd = -1;
+                *ret_fd = -EBADF;
 
         return k;
 }
@@ -1426,7 +1426,7 @@ int socket_get_mtu(int fd, int af, size_t *ret) {
 }
 
 int connect_unix_path(int fd, int dir_fd, const char *path) {
-        _cleanup_close_ int inode_fd = -1;
+        _cleanup_close_ int inode_fd = -EBADF;
         union sockaddr_union sa = {
                 .un.sun_family = AF_UNIX,
         };
index 0974f6178ab7845fef5cdb5fd726ae0fcffce81e..693e1f7eb62201e8abc7b56d982b40033345636e 100644 (file)
@@ -65,7 +65,7 @@ int is_device_node(const char *path) {
 }
 
 int dir_is_empty_at(int dir_fd, const char *path, bool ignore_hidden_or_backup) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct dirent *buf;
         size_t m;
 
index e2d4a3d895f107af0fde76126b222ff7b9833815..52c8c417dee310b857bf8ab582a05217dd187e2b 100644 (file)
@@ -9,7 +9,7 @@
 #include "sync-util.h"
 
 int fsync_directory_of_file(int fd) {
-        _cleanup_close_ int dfd = -1;
+        _cleanup_close_ int dfd = -EBADF;
         struct stat st;
         int r;
 
@@ -86,7 +86,7 @@ int fsync_full(int fd) {
 }
 
 int fsync_path_at(int at_fd, const char *path) {
-        _cleanup_close_ int opened_fd = -1;
+        _cleanup_close_ int opened_fd = -EBADF;
         int fd;
 
         if (isempty(path)) {
@@ -110,7 +110,7 @@ int fsync_path_at(int at_fd, const char *path) {
 }
 
 int fsync_parent_at(int at_fd, const char *path) {
-        _cleanup_close_ int opened_fd = -1;
+        _cleanup_close_ int opened_fd = -EBADF;
 
         if (isempty(path)) {
                 if (at_fd != AT_FDCWD)
@@ -131,7 +131,7 @@ int fsync_parent_at(int at_fd, const char *path) {
 }
 
 int fsync_path_and_parent_at(int at_fd, const char *path) {
-        _cleanup_close_ int opened_fd = -1;
+        _cleanup_close_ int opened_fd = -EBADF;
 
         if (isempty(path)) {
                 if (at_fd != AT_FDCWD)
@@ -147,7 +147,7 @@ int fsync_path_and_parent_at(int at_fd, const char *path) {
 }
 
 int syncfs_path(int at_fd, const char *path) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         if (isempty(path)) {
                 if (at_fd != AT_FDCWD)
index 7bc2f71bcfd3624bda1b2d1ba503d5802138dab2..da03a884f843a12cc3c2ad8b1bee05a482ed4d48 100644 (file)
@@ -53,7 +53,7 @@ static volatile int cached_color_mode = _COLOR_INVALID;
 static volatile int cached_underline_enabled = -1;
 
 int chvt(int vt) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         /* Switch to the specified vt number. If the VT is specified <= 0 switch to the VT the kernel log messages go,
          * if that's configured. */
@@ -300,7 +300,7 @@ finish:
 }
 
 int reset_terminal(const char *name) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         /* We open the terminal with O_NONBLOCK here, to ensure we
          * don't block on carrier if this is a terminal with carrier
@@ -314,7 +314,7 @@ int reset_terminal(const char *name) {
 }
 
 int open_terminal(const char *name, int mode) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         unsigned c = 0;
 
         /*
@@ -355,7 +355,7 @@ int acquire_terminal(
                 AcquireTerminalFlags flags,
                 usec_t timeout) {
 
-        _cleanup_close_ int notify = -1, fd = -1;
+        _cleanup_close_ int notify = -EBADF, fd = -EBADF;
         usec_t ts = USEC_INFINITY;
         int r, wd = -1;
 
@@ -483,7 +483,7 @@ int release_terminal(void) {
                 .sa_flags = SA_RESTART,
         };
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct sigaction sa_old;
         int r;
 
@@ -508,7 +508,7 @@ int terminal_vhangup_fd(int fd) {
 }
 
 int terminal_vhangup(const char *name) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
         if (fd < 0)
@@ -530,7 +530,7 @@ int vt_disallocate(const char *name) {
                 return -EINVAL;
 
         if (tty_is_vc(name)) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 unsigned u;
                 const char *n;
 
@@ -1083,7 +1083,7 @@ int ptsname_malloc(int fd, char **ret) {
 }
 
 int openpt_allocate(int flags, char **ret_slave) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *p = NULL;
         int r;
 
@@ -1129,7 +1129,7 @@ static int ptsname_namespace(int pty, char **ret) {
 }
 
 int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_slave) {
-        _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1, fd = -1;
+        _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF, fd = -EBADF;
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
         pid_t child;
         int r;
@@ -1182,7 +1182,7 @@ int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_slave) {
 }
 
 int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
-        _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
+        _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
         pid_t child;
         int r;
index 71b2f673505e1d16a4c77fdf99fe71194018582c..d5c10571c9b169be9a667e2d69911572edde0359 100644 (file)
@@ -1395,7 +1395,7 @@ int get_timezones(char ***ret) {
 int verify_timezone(const char *name, int log_level) {
         bool slash = false;
         const char *p, *t;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char buf[4];
         int r;
 
@@ -1568,7 +1568,7 @@ int time_change_fd(void) {
                 .it_value.tv_sec = TIME_T_MAX,
         };
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX));
 
index dbbd54027e6ac74295f272e9a9aa7bce0531cdfc..95adf9d374403c065d28b51d2ee8a4f634e2f55b 100644 (file)
@@ -21,7 +21,7 @@
 
 static int fopen_temporary_internal(int dir_fd, const char *path, FILE **ret_file) {
         _cleanup_fclose_ FILE *f = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
@@ -101,7 +101,7 @@ int mkostemp_safe(char *pattern) {
 }
 
 int fmkostemp_safe(char *pattern, const char *mode, FILE **ret_f) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         FILE *f;
 
         fd = mkostemp_safe(pattern);
@@ -309,7 +309,7 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path) {
 int fopen_tmpfile_linkable(const char *target, int flags, char **ret_path, FILE **ret_file) {
         _cleanup_free_ char *path = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(target);
         assert(ret_file);
index 0b661d93250e43b3a425c18878fd4794625d80dc..5b6131b56a36b466404d97ff6be176fd6b2ffe0a 100644 (file)
@@ -26,7 +26,7 @@ int getxattr_at_malloc(
                 int flags,
                 char **ret) {
 
-        _cleanup_close_ int opened_fd = -1;
+        _cleanup_close_ int opened_fd = -EBADF;
         unsigned n_attempts = 7;
         bool by_procfs = false;
         size_t l = 100;
@@ -212,7 +212,7 @@ int listxattr_at_malloc(
                 int flags,
                 char **ret) {
 
-        _cleanup_close_ int opened_fd = -1;
+        _cleanup_close_ int opened_fd = -EBADF;
         bool by_procfs = false;
         unsigned n_attempts = 7;
         size_t l = 100;
index b2dd60f8ad44022e035bc99068139af4b1ef5a15..59f02b761aca5657ab48c42770f8d4d0244cfc2d 100644 (file)
@@ -360,7 +360,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
                   left, done);
 
         STRV_FOREACH(p, arg_path) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 fd = open(*p, O_DIRECTORY|O_CLOEXEC|O_RDONLY);
                 if (fd < 0) {
@@ -439,7 +439,7 @@ static int verb_set(int argc, char *argv[], void *userdata) {
         }
 
         STRV_FOREACH(p, arg_path) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 fd = open(*p, O_DIRECTORY|O_CLOEXEC|O_RDONLY);
                 if (fd < 0)
index c14bdb69f8387af1cce92a06a36fa2a402980e73..d6c2feaeafbf570cb99e27155fa4121db4ec279b 100644 (file)
@@ -299,7 +299,7 @@ static int version_check(int fd_from, const char *from, int fd_to, const char *t
 }
 
 static int copy_file_with_version_check(const char *from, const char *to, bool force) {
-        _cleanup_close_ int fd_from = -1, fd_to = -1;
+        _cleanup_close_ int fd_from = -EBADF, fd_to = -EBADF;
         _cleanup_free_ char *t = NULL;
         int r;
 
@@ -899,7 +899,7 @@ static int remove_boot_efi(const char *esp_path) {
                 return log_error_errno(r, "Failed to open directory \"%s/EFI/BOOT\": %m", esp_path);
 
         FOREACH_DIRENT(de, d, break) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 _cleanup_free_ char *v = NULL;
 
                 if (!endswith_no_case(de->d_name, ".efi"))
index 0b3ff74eaa129d94a2f16a618a67c8578438137b..7d6e863728ce54a22cc72ba637baaf435d061249 100644 (file)
@@ -19,7 +19,7 @@ int install_random_seed(const char *esp) {
         _cleanup_(unlink_and_freep) char *tmp = NULL;
         uint8_t buffer[RANDOM_EFI_SEED_SIZE];
         _cleanup_free_ char *path = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         size_t token_size;
         ssize_t n;
         int r;
index 44f38004f5afb64d2ee6850e3bb791a4573d7854..a0fee7d3c737e8662d233506415518790b0c6161 100644 (file)
@@ -205,7 +205,7 @@ static int enumerate_binaries(
 
         FOREACH_DIRENT(de, d, break) {
                 _cleanup_free_ char *v = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 if (!endswith_no_case(de->d_name, ".efi"))
                         continue;
index 4ee5b1de3b1a5eeabd20c7ff24583525b3c1c0b3..a153455904d271747643da91b0de8a1f85d49754 100644 (file)
@@ -427,7 +427,7 @@ static int measure_kernel(PcrState *pcr_states, size_t n) {
 
         for (UnifiedSection c = 0; c < _UNIFIED_SECTION_MAX; c++) {
                 _cleanup_(evp_md_ctx_free_all) EVP_MD_CTX **mdctx = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 uint64_t m = 0;
 
                 if (!arg_sections[c])
index 91267362351805b2e2c818347f009fad2986f381..d6480097b5e991db92b0c27026ab98e9a7cab5d0 100644 (file)
@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
                 .un.sun_path = "/run/systemd/cgroups-agent",
         };
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         ssize_t n;
         size_t l;
         int r;
index a44b8e878d97d4de86cb854275e6171d80911a04..d2976d6734e9bb589b75ec3a9cd2b97cb8498318 100644 (file)
@@ -73,7 +73,7 @@ static void automount_init(Unit *u) {
         assert(u);
         assert(u->load_state == UNIT_STUB);
 
-        a->pipe_fd = -1;
+        a->pipe_fd = -EBADF;
         a->directory_mode = 0755;
         UNIT(a)->ignore_on_isolate = true;
 }
@@ -392,7 +392,7 @@ static int open_ioctl_fd(int dev_autofs_fd, const char *where, dev_t devid) {
 
         init_autofs_dev_ioctl(param);
         param->size = l;
-        param->ioctlfd = -1;
+        param->ioctlfd = -EBADF;
         param->openmount.devid = devid;
         strcpy(param->path, where);
 
@@ -470,7 +470,7 @@ static int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, in
 }
 
 static int automount_send_ready(Automount *a, Set *tokens, int status) {
-        _cleanup_close_ int ioctl_fd = -1;
+        _cleanup_close_ int ioctl_fd = -EBADF;
         unsigned token;
         int r;
 
@@ -572,7 +572,7 @@ static void automount_trigger_notify(Unit *u, Unit *other) {
 }
 
 static void automount_enter_waiting(Automount *a) {
-        _cleanup_close_ int ioctl_fd = -1;
+        _cleanup_close_ int ioctl_fd = -EBADF;
         int p[2] = { -1, -1 };
         char name[STRLEN("systemd-") + DECIMAL_STR_MAX(pid_t) + 1];
         _cleanup_free_ char *options = NULL;
@@ -707,7 +707,7 @@ static int automount_dispatch_expire(sd_event_source *source, usec_t usec, void
         if (!data)
                 return log_oom();
 
-        data->ioctl_fd = -1;
+        data->ioctl_fd = -EBADF;
 
         data->dev_autofs_fd = fcntl(UNIT(a)->manager->dev_autofs_fd, F_DUPFD_CLOEXEC, 3);
         if (data->dev_autofs_fd < 0)
index ce3b76c512329b023e3940aa63fcbed0627efbfb..5878a8187915456f11510d211bbcf845b2fef8da 100644 (file)
@@ -411,7 +411,7 @@ static int bpf_firewall_prepare_access_maps(
                 int *ret_ipv6_map_fd,
                 bool *ret_has_any) {
 
-        _cleanup_close_ int ipv4_map_fd = -1, ipv6_map_fd = -1;
+        _cleanup_close_ int ipv4_map_fd = -EBADF, ipv6_map_fd = -EBADF;
         size_t n_ipv4 = 0, n_ipv6 = 0;
         Unit *p;
         int r;
@@ -874,8 +874,8 @@ int bpf_firewall_supported(void) {
         // Ideally it should behave like GCC, so that we can remove these workarounds.
         zero(attr);
         attr.attach_type = BPF_CGROUP_INET_EGRESS;
-        attr.target_fd = -1;
-        attr.attach_bpf_fd = -1;
+        attr.target_fd = -EBADF;
+        attr.attach_bpf_fd = -EBADF;
 
         if (bpf(BPF_PROG_DETACH, &attr, sizeof(attr)) < 0) {
                 if (errno != EBADF) {
@@ -902,8 +902,8 @@ int bpf_firewall_supported(void) {
 
         zero(attr);
         attr.attach_type = BPF_CGROUP_INET_EGRESS;
-        attr.target_fd = -1;
-        attr.attach_bpf_fd = -1;
+        attr.target_fd = -EBADF;
+        attr.attach_bpf_fd = -EBADF;
         attr.attach_flags = BPF_F_ALLOW_MULTI;
 
         if (bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)) < 0) {
index de601c48d751ffce39a7ba12a6c5e0254edaf451..0be250af5cca8250639e4f7cc2b6a653cc60f90e 100644 (file)
@@ -55,7 +55,7 @@ static bool bpf_can_link_lsm_program(struct bpf_program *prog) {
 
 static int prepare_restrict_fs_bpf(struct restrict_fs_bpf **ret_obj) {
         _cleanup_(restrict_fs_bpf_freep) struct restrict_fs_bpf *obj = NULL;
-        _cleanup_close_ int inner_map_fd = -1;
+        _cleanup_close_ int inner_map_fd = -EBADF;
         int r;
 
         assert(ret_obj);
index 660ffdb7232567f81c9b65e780a39684b97eefde..9f290ab412c1d1d46b6c8a9d8f0fc8e5d4ae67a6 100644 (file)
@@ -156,7 +156,7 @@ static int socket_bind_install_impl(Unit *u) {
         _cleanup_(bpf_link_freep) struct bpf_link *ipv4 = NULL, *ipv6 = NULL;
         _cleanup_(socket_bind_bpf_freep) struct socket_bind_bpf *obj = NULL;
         _cleanup_free_ char *cgroup_path = NULL;
-        _cleanup_close_ int cgroup_fd = -1;
+        _cleanup_close_ int cgroup_fd = -EBADF;
         CGroupContext *cc;
         int r;
 
index f01c67ecf145f524bbffe5775e3a28d204656a41..9e529d6375ca7cae3d8c20dc7e4732ca8eca39ea 100644 (file)
@@ -1379,7 +1379,7 @@ static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *er
 }
 
 static int reply_dump_by_fd(sd_bus_message *message, char *dump) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = acquire_data_fd(dump, strlen(dump), 0);
         if (fd < 0)
index 65fb7d7eb7e1f5a9928bfff5d1e043bfda4866ac..22de551c548e967c615735d2b0fc6f18fa8923a2 100644 (file)
@@ -112,7 +112,7 @@ static int bus_path_set_transient_property(
                                 s->unit = u;
                                 s->path = TAKE_PTR(k);
                                 s->type = t;
-                                s->inotify_fd = -1;
+                                s->inotify_fd = -EBADF;
 
                                 LIST_PREPEND(spec, p->specs, s);
 
index 43edbb60e4bf60afe8616cbc25bb90447d76091b..d0d92507d6ab47baee6c5395e7b652f3e4c61783 100644 (file)
@@ -371,7 +371,7 @@ static int bus_socket_set_transient_property(
                                 return log_oom();
 
                         *p = (SocketPort) {
-                                .fd = -1,
+                                .fd = -EBADF,
                                 .socket = s,
                         };
 
index c6024a061ebcf2b731b5f5e9cce32ccb1a341219..c295e1fbd415247c7ee9aeb69741b8860402911e 100644 (file)
@@ -649,7 +649,7 @@ static int bus_setup_disconnected_match(Manager *m, sd_bus *bus) {
 
 static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
         _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
-        _cleanup_close_ int nfd = -1;
+        _cleanup_close_ int nfd = -EBADF;
         Manager *m = ASSERT_PTR(userdata);
         sd_id128_t id;
         int r;
@@ -684,7 +684,7 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
                 return 0;
         }
 
-        nfd = -1;
+        nfd = -EBADF;
 
         r = bus_check_peercred(bus);
         if (r < 0) {
@@ -897,7 +897,7 @@ int bus_init_system(Manager *m) {
 }
 
 int bus_init_private(Manager *m) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union sockaddr_union sa;
         socklen_t sa_len;
         sd_event_source *s;
index 18b36e74bfa7a91502b6f6c00749364fc9c7b049..e0b371a4c4ec0e53d406277f60cec1d8f24872c3 100644 (file)
@@ -211,7 +211,7 @@ static int pick_uid(char **suggested_paths, const char *name, uid_t *ret_uid) {
 
         for (;;) {
                 char lock_path[STRLEN("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1];
-                _cleanup_close_ int lock_fd = -1;
+                _cleanup_close_ int lock_fd = -EBADF;
                 uid_t candidate;
                 ssize_t l;
 
@@ -373,7 +373,7 @@ static void unlockfp(int *fd_lock) {
         if (*fd_lock < 0)
                 return;
         lockf(*fd_lock, F_ULOCK, 0);
-        *fd_lock = -1;
+        *fd_lock = -EBADF;
 }
 
 static int dynamic_user_realize(
@@ -383,8 +383,8 @@ static int dynamic_user_realize(
                 bool is_user) {
 
         _cleanup_(unlockfp) int storage_socket0_lock = -1;
-        _cleanup_close_ int uid_lock_fd = -1;
-        _cleanup_close_ int etc_passwd_lock_fd = -1;
+        _cleanup_close_ int uid_lock_fd = -EBADF;
+        _cleanup_close_ int etc_passwd_lock_fd = -EBADF;
         uid_t num = UID_INVALID; /* a uid if is_user, and a gid otherwise */
         gid_t gid = GID_INVALID; /* a gid if is_user, ignored otherwise */
         bool flush_cache = false;
@@ -525,7 +525,7 @@ static int dynamic_user_realize(
 
 int dynamic_user_current(DynamicUser *d, uid_t *ret) {
         _cleanup_(unlockfp) int storage_socket0_lock = -1;
-        _cleanup_close_ int lock_fd = -1;
+        _cleanup_close_ int lock_fd = -EBADF;
         uid_t uid;
         int r;
 
@@ -568,7 +568,7 @@ static DynamicUser* dynamic_user_unref(DynamicUser *d) {
 
 static int dynamic_user_close(DynamicUser *d) {
         _cleanup_(unlockfp) int storage_socket0_lock = -1;
-        _cleanup_close_ int lock_fd = -1;
+        _cleanup_close_ int lock_fd = -EBADF;
         uid_t uid;
         int r;
 
index 61516775fc705f5681ab6e6a4c8150c58fecab07..dffde57c912e09aeb488631270102e7a7a52102f 100644 (file)
@@ -13,7 +13,7 @@
 #include "strv.h"
 
 void lock_down_efi_variables(void) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         fd = open(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderSystemToken)), O_RDONLY|O_CLOEXEC);
index 42c95556ac799c0414333587ab4fae6398a4c3ce..94021f20e81cf101cc36b258d6f492eb813af713 100644 (file)
@@ -329,7 +329,7 @@ static int connect_logger_as(
                 uid_t uid,
                 gid_t gid) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(context);
@@ -385,7 +385,7 @@ static int open_terminal_as(const char *path, int flags, int nfd) {
 }
 
 static int acquire_path(const char *path, int flags, mode_t mode) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(path);
@@ -766,7 +766,7 @@ static int setup_confirm_stdio(
                 int *ret_saved_stdin,
                 int *ret_saved_stdout) {
 
-        _cleanup_close_ int fd = -1, saved_stdin = -1, saved_stdout = -1;
+        _cleanup_close_ int fd = -EBADF, saved_stdin = -EBADF, saved_stdout = -EBADF;
         int r;
 
         assert(ret_saved_stdin);
@@ -818,7 +818,7 @@ static void write_confirm_error_fd(int err, int fd, const Unit *u) {
 }
 
 static void write_confirm_error(int err, const char *vc, const Unit *u) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(vc);
 
@@ -2100,7 +2100,7 @@ bool exec_needs_mount_namespace(
 static int setup_private_users(uid_t ouid, gid_t ogid, uid_t uid, gid_t gid) {
         _cleanup_free_ char *uid_map = NULL, *gid_map = NULL;
         _cleanup_close_pair_ int errno_pipe[2] = { -1, -1 };
-        _cleanup_close_ int unshare_ready_fd = -1;
+        _cleanup_close_ int unshare_ready_fd = -EBADF;
         _cleanup_(sigkill_waitp) pid_t pid = 0;
         uint64_t c = 1;
         ssize_t n;
@@ -2159,7 +2159,7 @@ static int setup_private_users(uid_t ouid, gid_t ogid, uid_t uid, gid_t gid) {
         if (r < 0)
                 return r;
         if (r == 0) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 const char *a;
                 pid_t ppid;
 
@@ -2554,7 +2554,7 @@ static int write_credential(
                 bool ownership_ok) {
 
         _cleanup_(unlink_and_freep) char *tmp = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         r = tempfn_random_child("", "cred", &tmp);
@@ -2852,7 +2852,7 @@ static int acquire_credentials(
                 bool ownership_ok) {
 
         uint64_t left = CREDENTIALS_TOTAL_SIZE_MAX;
-        _cleanup_close_ int dfd = -1;
+        _cleanup_close_ int dfd = -EBADF;
         ExecLoadCredential *lc;
         ExecSetCredential *sc;
         int r;
@@ -2866,7 +2866,7 @@ static int acquire_credentials(
 
         /* First, load credentials off disk (or acquire via AF_UNIX socket) */
         HASHMAP_FOREACH(lc, context->load_credentials) {
-                _cleanup_close_ int sub_fd = -1;
+                _cleanup_close_ int sub_fd = -EBADF;
 
                 /* If this is an absolute path, then try to open it as a directory. If that works, then we'll
                  * recurse into it. If it is an absolute path but it isn't a directory, then we'll open it as
@@ -4084,7 +4084,7 @@ static int add_shifted_fd(int *fds, size_t fds_size, size_t *n_fds, int fd, int
         assert(ret_fd);
 
         if (fd < 0) {
-                *ret_fd = -1;
+                *ret_fd = -EBADF;
                 return 0;
         }
 
@@ -4781,7 +4781,7 @@ static int exec_child(
          * shall execute. */
 
         _cleanup_free_ char *executable = NULL;
-        _cleanup_close_ int executable_fd = -1;
+        _cleanup_close_ int executable_fd = -EBADF;
         r = find_executable_full(command->path, /* root= */ NULL, context->exec_search_path, false, &executable, &executable_fd);
         if (r < 0) {
                 if (r != -ENOMEM && (command->flags & EXEC_COMMAND_IGNORE_FAILURE)) {
@@ -4812,7 +4812,7 @@ static int exec_child(
 
 #if HAVE_SELINUX
         if (needs_sandboxing && use_selinux && params->selinux_context_net) {
-                int fd = -1;
+                int fd = -EBADF;
 
                 if (socket_fd >= 0)
                         fd = socket_fd;
@@ -5211,7 +5211,7 @@ int exec_spawn(Unit *unit,
 
                 socket_fd = params->fds[0];
         } else {
-                socket_fd = -1;
+                socket_fd = -EBADF;
                 fds = params->fds;
                 n_socket_fds = params->n_socket_fds;
                 n_storage_fds = params->n_storage_fds;
@@ -6279,7 +6279,7 @@ void exec_context_free_log_extra_fields(ExecContext *c) {
 }
 
 void exec_context_revert_tty(ExecContext *c) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *path;
         struct stat st;
         int r;
index 7f517a09099065b67525a0d005150123d7e17910..37916bb474a396d1d200b107c9e2975ed2d70dda 100644 (file)
@@ -23,7 +23,7 @@
 int ima_setup(void) {
 #if ENABLE_IMA
         _cleanup_fclose_ FILE *input = NULL;
-        _cleanup_close_ int imafd = -1;
+        _cleanup_close_ int imafd = -EBADF;
         unsigned lineno = 0;
         int r;
 
index 1f2017ee5a522132bc877da50f63ce9b7aa5beb0..0bcd407e682fb5e8e17f49df5d800a53c9a725bf 100644 (file)
@@ -146,7 +146,7 @@ static int finalize_credentials_dir(const char *dir, const char *envvar) {
 
 static int import_credentials_boot(void) {
         _cleanup_(import_credentials_context_free) ImportCredentialContext context = {
-                .target_dir_fd = -1,
+                .target_dir_fd = -EBADF,
         };
         int r;
 
@@ -165,7 +165,7 @@ static int import_credentials_boot(void) {
                        "/.extra/global_credentials/") { /* boot partition wide */
 
                 _cleanup_free_ DirectoryEntries *de = NULL;
-                _cleanup_close_ int source_dir_fd = -1;
+                _cleanup_close_ int source_dir_fd = -EBADF;
 
                 source_dir_fd = open(p, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
                 if (source_dir_fd < 0) {
@@ -186,7 +186,7 @@ static int import_credentials_boot(void) {
 
                 for (size_t i = 0; i < de->n_entries; i++) {
                         const struct dirent *d = de->entries[i];
-                        _cleanup_close_ int cfd = -1, nfd = -1;
+                        _cleanup_close_ int cfd = -EBADF, nfd = -EBADF;
                         _cleanup_free_ char *n = NULL;
                         const char *e;
                         struct stat st;
@@ -294,7 +294,7 @@ static int acquire_credential_directory(ImportCredentialContext *c) {
 static int proc_cmdline_callback(const char *key, const char *value, void *data) {
         ImportCredentialContext *c = ASSERT_PTR(data);
         _cleanup_free_ char *n = NULL;
-        _cleanup_close_ int nfd = -1;
+        _cleanup_close_ int nfd = -EBADF;
         const char *colon;
         size_t l;
         int r;
@@ -365,7 +365,7 @@ static int import_credentials_proc_cmdline(ImportCredentialContext *c) {
 
 static int import_credentials_qemu(ImportCredentialContext *c) {
         _cleanup_free_ DirectoryEntries *de = NULL;
-        _cleanup_close_ int source_dir_fd = -1;
+        _cleanup_close_ int source_dir_fd = -EBADF;
         int r;
 
         assert(c);
@@ -389,7 +389,7 @@ static int import_credentials_qemu(ImportCredentialContext *c) {
 
         for (size_t i = 0; i < de->n_entries; i++) {
                 const struct dirent *d = de->entries[i];
-                _cleanup_close_ int vfd = -1, rfd = -1, nfd = -1;
+                _cleanup_close_ int vfd = -EBADF, rfd = -EBADF, nfd = -EBADF;
                 _cleanup_free_ char *szs = NULL;
                 uint64_t sz;
 
@@ -468,7 +468,7 @@ static int parse_smbios_strings(ImportCredentialContext *c, const char *data, si
         for (p = data, left = size; left > 0; p += skip, left -= skip) {
                 _cleanup_free_ void *buf = NULL;
                 _cleanup_free_ char *cn = NULL;
-                _cleanup_close_ int nfd = -1;
+                _cleanup_close_ int nfd = -EBADF;
                 const char *nul, *n, *eq;
                 const void *cdata;
                 size_t buflen, cdata_len;
@@ -606,7 +606,7 @@ static int import_credentials_smbios(ImportCredentialContext *c) {
 
 static int import_credentials_trusted(void) {
         _cleanup_(import_credentials_context_free) ImportCredentialContext c = {
-                .target_dir_fd = -1,
+                .target_dir_fd = -EBADF,
         };
         int q, w, r;
 
index 3a95f0d504b03f911550ed3098ccf37d4887c1d6..e5766a58a7c5f11286d680a1e8242e62b41593c0 100644 (file)
@@ -674,7 +674,7 @@ int config_parse_socket_listen(
                 p->type = SOCKET_SOCKET;
         }
 
-        p->fd = -1;
+        p->fd = -EBADF;
         p->auxiliary_fds = NULL;
         p->n_auxiliary_fds = 0;
         p->socket = s;
@@ -2232,7 +2232,7 @@ int config_parse_path_spec(const char *unit,
         s->unit = UNIT(p);
         s->path = TAKE_PTR(k);
         s->type = b;
-        s->inotify_fd = -1;
+        s->inotify_fd = -EBADF;
 
         LIST_PREPEND(spec, p->specs, s);
 
index 4adb4165acb315799dc98fe3f55a129a285a73e0..f779410fda5b4370478d4d4791c2c26c1c09c759 100644 (file)
@@ -213,7 +213,7 @@ static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) {
 }
 
 static int console_setup(void) {
-        _cleanup_close_ int tty_fd = -1;
+        _cleanup_close_ int tty_fd = -EBADF;
         int r;
 
         tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
index dd16d17afa829a7c980b857dce77b76f2ad5804f..61a464c06bfe041b652702e2ca9e6beb1a7e91d6 100644 (file)
@@ -18,7 +18,7 @@
 #include "varlink-internal.h"
 
 int manager_open_serialization(Manager *m, FILE **ret_f) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         FILE *f;
 
         assert(ret_f);
index 292e82fd87a83b1fb00c76207957e376591029bc..4e15f5cb8b13dca6450353bb50d99e046356a2a5 100644 (file)
@@ -495,7 +495,7 @@ static int manager_setup_timezone_change(Manager *m) {
 }
 
 static int enable_special_signals(Manager *m) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(m);
 
@@ -848,16 +848,16 @@ int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager *
 
                 .show_status_overridden = _SHOW_STATUS_INVALID,
 
-                .notify_fd = -1,
-                .cgroups_agent_fd = -1,
-                .signal_fd = -1,
-                .user_lookup_fds = { -1, -1 },
-                .private_listen_fd = -1,
-                .dev_autofs_fd = -1,
-                .cgroup_inotify_fd = -1,
-                .pin_cgroupfs_fd = -1,
-                .ask_password_inotify_fd = -1,
-                .idle_pipe = { -1, -1, -1, -1},
+                .notify_fd = -EBADF,
+                .cgroups_agent_fd = -EBADF,
+                .signal_fd = -EBADF,
+                .user_lookup_fds = { -EBADF, -EBADF },
+                .private_listen_fd = -EBADF,
+                .dev_autofs_fd = -EBADF,
+                .cgroup_inotify_fd = -EBADF,
+                .pin_cgroupfs_fd = -EBADF,
+                .ask_password_inotify_fd = -EBADF,
+                .idle_pipe = { -EBADF, -EBADF, -EBADF, -EBADF},
 
                  /* start as id #1, so that we can leave #0 around as "null-like" value */
                 .current_job_id = 1,
@@ -1000,7 +1000,7 @@ static int manager_setup_notify(Manager *m) {
                 return 0;
 
         if (m->notify_fd < 0) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 union sockaddr_union sa;
                 socklen_t sa_len;
 
@@ -1091,7 +1091,7 @@ static int manager_setup_cgroups_agent(Manager *m) {
                 return 0;
 
         if (m->cgroups_agent_fd < 0) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 /* First free all secondary fields */
                 m->cgroups_agent_event_source = sd_event_source_disable_unref(m->cgroups_agent_event_source);
@@ -3187,7 +3187,7 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
 void manager_send_unit_plymouth(Manager *m, Unit *u) {
         static const union sockaddr_union sa = PLYMOUTH_SOCKET;
         _cleanup_free_ char *message = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int n = 0;
 
         /* Don't generate plymouth events if the service was already
index f16e5c487bcbbc6a816ea66e952761734068ee41..4ea609a4fde9c80f40fe6f140a5022f39758d8a6 100644 (file)
@@ -886,10 +886,10 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
 
         _cleanup_(exec_params_clear) ExecParameters exec_params = {
                 .flags     = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN,
-                .stdin_fd  = -1,
-                .stdout_fd = -1,
-                .stderr_fd = -1,
-                .exec_fd   = -1,
+                .stdin_fd  = -EBADF,
+                .stdout_fd = -EBADF,
+                .stderr_fd = -EBADF,
+                .exec_fd   = -EBADF,
         };
         pid_t pid;
         int r;
index 3bac6bb6a3b9bcdfc79c101b3500d0b0e8e40188..d7c911a509f74c7ddeedaefc9dfa5725f863da48 100644 (file)
@@ -1075,7 +1075,7 @@ static int mount_sysfs(const MountEntry *m) {
 }
 
 static bool mount_option_supported(const char *fstype, const char *key, const char *value) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         /* This function assumes support by default. Only if the fsconfig() call fails with -EINVAL/-EOPNOTSUPP
@@ -2698,7 +2698,7 @@ int temporary_filesystem_add(
 
 static int make_tmp_prefix(const char *prefix) {
         _cleanup_free_ char *t = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         /* Don't do anything unless we know the dir is actually missing */
index 3a46e44928813912e3b6f19af1c35670c97e51b8..3881c77a868f3c8ed19b7ae820eb51464c0d566f 100644 (file)
@@ -265,7 +265,7 @@ static void path_spec_dump(PathSpec *s, FILE *f, const char *prefix) {
 
 void path_spec_done(PathSpec *s) {
         assert(s);
-        assert(s->inotify_fd == -1);
+        assert(s->inotify_fd == -EBADF);
 
         free(s->path);
 }
index 134f70a07b862fb8bf8b5ef6ea76683478e03488..4dd8656718961e35054113c41cca9b35ee53ef7b 100644 (file)
@@ -101,7 +101,7 @@ static int restrict_network_interfaces_install_impl(Unit *u) {
         _cleanup_(bpf_link_freep) struct bpf_link *egress_link = NULL, *ingress_link = NULL;
         _cleanup_(restrict_ifaces_bpf_freep) struct restrict_ifaces_bpf *obj = NULL;
         _cleanup_free_ char *cgroup_path = NULL;
-        _cleanup_close_ int cgroup_fd = -1;
+        _cleanup_close_ int cgroup_fd = -EBADF;
         CGroupContext *cc;
         int r;
 
index bb190b1e8aa2159ae0ce2bd062525815bb56ab33..5181826c84cc26a4376b9dcca8ce602031a91827 100644 (file)
@@ -111,8 +111,8 @@ static void service_init(Unit *u) {
         s->restart_usec = u->manager->default_restart_usec;
         s->runtime_max_usec = USEC_INFINITY;
         s->type = _SERVICE_TYPE_INVALID;
-        s->socket_fd = -1;
-        s->stdin_fd = s->stdout_fd = s->stderr_fd = -1;
+        s->socket_fd = -EBADF;
+        s->stdin_fd = s->stdout_fd = s->stderr_fd = -EBADF;
         s->guess_main_pid = true;
 
         s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
@@ -480,7 +480,7 @@ static int service_add_fd_store_set(Service *s, FDSet *fds, const char *name, bo
         assert(s);
 
         while (fdset_size(fds) > 0) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 fd = fdset_steal_first(fds);
                 if (fd < 0)
@@ -495,7 +495,7 @@ static int service_add_fd_store_set(Service *s, FDSet *fds, const char *name, bo
                         return log_unit_error_errno(UNIT(s), r, "Failed to add fd to store: %m");
                 if (r > 0)
                         log_unit_debug(UNIT(s), "Added fd %i (%s) to fd store.", fd, strna(name));
-                fd = -1;
+                fd = -EBADF;
         }
 
         return 0;
@@ -959,7 +959,7 @@ static int service_is_suitable_main_pid(Service *s, pid_t pid, int prio) {
 static int service_load_pid_file(Service *s, bool may_warn) {
         bool questionable_pid_file = false;
         _cleanup_free_ char *k = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r, prio;
         pid_t pid;
 
@@ -1483,10 +1483,10 @@ static int service_spawn_internal(
 
         _cleanup_(exec_params_clear) ExecParameters exec_params = {
                 .flags     = flags,
-                .stdin_fd  = -1,
-                .stdout_fd = -1,
-                .stderr_fd = -1,
-                .exec_fd   = -1,
+                .stdin_fd  = -EBADF,
+                .stdout_fd = -EBADF,
+                .stderr_fd = -EBADF,
+                .exec_fd   = -EBADF,
         };
         _cleanup_(sd_event_source_unrefp) sd_event_source *exec_fd_source = NULL;
         _cleanup_strv_free_ char **final_env = NULL, **our_env = NULL;
@@ -3241,7 +3241,7 @@ static int service_demand_pid_file(Service *s) {
         /* PATH_CHANGED would not be enough. There are daemons (sendmail) that
          * keep their PID file open all the time. */
         ps->type = PATH_MODIFIED;
-        ps->inotify_fd = -1;
+        ps->inotify_fd = -EBADF;
 
         s->pid_file_pathspec = ps;
 
index 2ba7a8588d2a182f766524fec7e2f690a4497aab..c6b106fc9c5e320da41473230a61aca5f9ae5e58 100644 (file)
@@ -39,7 +39,7 @@ int parse_show_status(const char *v, ShowStatus *ret) {
 int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) {
         static const char status_indent[] = "         "; /* "[" STATUS "] " */
         _cleanup_free_ char *s = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct iovec iovec[7] = {};
         int n = 0;
         static bool prev_ephemeral;
index 58552f79e73e48b8b4abff73fa8fe6e96f2d0ac2..bcaa237c8dc24d8c3b38cee78d0dfec6473ef281 100644 (file)
@@ -48,9 +48,9 @@ static int fdopen_unlocked_at(int dfd, const char *dir, const char *name, int *s
 }
 
 static int write_access2_rules(const char *srcdir) {
-        _cleanup_close_ int load2_fd = -1, change_fd = -1;
+        _cleanup_close_ int load2_fd = -EBADF, change_fd = -EBADF;
         _cleanup_closedir_ DIR *dir = NULL;
-        int dfd = -1, r = 0;
+        int dfd = -EBADF, r = 0;
 
         load2_fd = open("/sys/fs/smackfs/load2", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (load2_fd < 0)  {
@@ -120,9 +120,9 @@ static int write_access2_rules(const char *srcdir) {
 }
 
 static int write_cipso2_rules(const char *srcdir) {
-        _cleanup_close_ int cipso2_fd = -1;
+        _cleanup_close_ int cipso2_fd = -EBADF;
         _cleanup_closedir_ DIR *dir = NULL;
-        int dfd = -1, r = 0;
+        int dfd = -EBADF, r = 0;
 
         cipso2_fd = open("/sys/fs/smackfs/cipso2", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (cipso2_fd < 0)  {
@@ -181,7 +181,7 @@ static int write_cipso2_rules(const char *srcdir) {
 static int write_netlabel_rules(const char *srcdir) {
         _cleanup_fclose_ FILE *dst = NULL;
         _cleanup_closedir_ DIR *dir = NULL;
-        int dfd = -1, r = 0;
+        int dfd = -EBADF, r = 0;
 
         dst = fopen("/sys/fs/smackfs/netlabel", "we");
         if (!dst)  {
@@ -238,7 +238,7 @@ static int write_netlabel_rules(const char *srcdir) {
 }
 
 static int write_onlycap_list(void) {
-        _cleanup_close_ int onlycap_fd = -1;
+        _cleanup_close_ int onlycap_fd = -EBADF;
         _cleanup_free_ char *list = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         size_t len = 0;
index 55847c2f7c73418ffa4115701664fa2312c29e2c..e0e91dba53e633989f1c0491d02146716035622a 100644 (file)
@@ -1116,7 +1116,7 @@ static int fifo_address_create(
                 mode_t directory_mode,
                 mode_t socket_mode) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         mode_t old_mask;
         struct stat st;
         int r;
@@ -1172,7 +1172,7 @@ fail:
 }
 
 static int special_address_create(const char *path, bool writable) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
 
         assert(path);
@@ -1192,7 +1192,7 @@ static int special_address_create(const char *path, bool writable) {
 }
 
 static int usbffs_address_create(const char *path) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
 
         assert(path);
@@ -1217,7 +1217,7 @@ static int mq_address_create(
                 long maxmsg,
                 long msgsize) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
         mode_t old_mask;
         struct mq_attr _attr, *attr = NULL;
@@ -1918,10 +1918,10 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
 
         _cleanup_(exec_params_clear) ExecParameters exec_params = {
                 .flags     = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN,
-                .stdin_fd  = -1,
-                .stdout_fd = -1,
-                .stderr_fd = -1,
-                .exec_fd   = -1,
+                .stdin_fd  = -EBADF,
+                .stdout_fd = -EBADF,
+                .stderr_fd = -EBADF,
+                .exec_fd   = -EBADF,
         };
         pid_t pid;
         int r;
@@ -2978,7 +2978,7 @@ shortcut:
 
 static int socket_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
         SocketPort *p = ASSERT_PTR(userdata);
-        int cfd = -1;
+        int cfd = -EBADF;
 
         assert(fd >= 0);
 
index 5c83c4780f58b745b6a9e8210bcf768ab03f9de0..2d25014e5f4abf2c5ff94765d474843da056518c 100644 (file)
@@ -660,10 +660,10 @@ static int swap_spawn(Swap *s, ExecCommand *c, pid_t *_pid) {
 
         _cleanup_(exec_params_clear) ExecParameters exec_params = {
                 .flags     = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN,
-                .stdin_fd  = -1,
-                .stdout_fd = -1,
-                .stderr_fd = -1,
-                .exec_fd   = -1,
+                .stdin_fd  = -EBADF,
+                .stdout_fd = -EBADF,
+                .stderr_fd = -EBADF,
+                .exec_fd   = -EBADF,
         };
         pid_t pid;
         int r;
index 641993b836d7eca39cd9a9c92bc341de96f94c58..e14238b3bae681f46ddc033ff3d9a5b189a95bc3 100644 (file)
@@ -115,15 +115,15 @@ Unit* unit_new(Manager *m, size_t size) {
         u->cgroup_invalidated_mask |= CGROUP_MASK_BPF_FIREWALL;
         u->failure_action_exit_status = u->success_action_exit_status = -1;
 
-        u->ip_accounting_ingress_map_fd = -1;
-        u->ip_accounting_egress_map_fd = -1;
+        u->ip_accounting_ingress_map_fd = -EBADF;
+        u->ip_accounting_egress_map_fd = -EBADF;
         for (CGroupIOAccountingMetric i = 0; i < _CGROUP_IO_ACCOUNTING_METRIC_MAX; i++)
                 u->io_accounting_last[i] = UINT64_MAX;
 
-        u->ipv4_allow_map_fd = -1;
-        u->ipv6_allow_map_fd = -1;
-        u->ipv4_deny_map_fd = -1;
-        u->ipv6_deny_map_fd = -1;
+        u->ipv4_allow_map_fd = -EBADF;
+        u->ipv6_allow_map_fd = -EBADF;
+        u->ipv4_deny_map_fd = -EBADF;
+        u->ipv6_deny_map_fd = -EBADF;
 
         u->last_section_private = -1;
 
@@ -5274,7 +5274,7 @@ static int unit_export_log_level_max(Unit *u, const ExecContext *c) {
 }
 
 static int unit_export_log_extra_fields(Unit *u, const ExecContext *c) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct iovec *iovec;
         const char *p;
         char *pattern;
index 50220c5ec719a37cf46fd9553423fb89dd5bf312..4ca19370f3e280165dcab70cac3ea4e45d97f6a4 100644 (file)
@@ -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);
index 6a6a968149a63e1483edaca04cf4ee902f5d71b4..8a4f31aa624a6c97c992e180a9f493ba13236a85 100644 (file)
@@ -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) {
index 3c86b10aab0f445245bfc539007974814eef90bf..d987f04ef43775edb922502ca2a64d810a46369c 100644 (file)
@@ -137,7 +137,7 @@ static int add_credentials_to_table(Table *t, bool encrypted) {
         for (;;) {
                 _cleanup_free_ char *j = NULL;
                 const char *secure, *secure_color = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 struct dirent *de;
                 struct stat st;
 
index b7bcf731f7590c25ef4168d2e212a147f4ed323f..ed923c2c863b7911505c6d1a55c73a548e2427e1 100644 (file)
@@ -859,7 +859,7 @@ static int list_print_item(
 }
 
 static int get_file_sha256(int inode_fd, uint8_t ret[static SHA256_DIGEST_SIZE]) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct sha256_ctx ctx;
 
         /* convert O_PATH fd into a regular one */
@@ -1063,7 +1063,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
                 return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
 
         if (arg_action == ACTION_COPY_FROM) {
-                _cleanup_close_ int source_fd = -1, target_fd = -1;
+                _cleanup_close_ int source_fd = -EBADF, target_fd = -EBADF;
 
                 source_fd = chase_symlinks_and_open(arg_source, mounted_dir, CHASE_PREFIX_ROOT|CHASE_WARN, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
                 if (source_fd < 0)
@@ -1108,7 +1108,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
                 /* When this is a regular file we don't copy ownership! */
 
         } else if (arg_action == ACTION_COPY_TO) {
-                _cleanup_close_ int source_fd = -1, target_fd = -1, dfd = -1;
+                _cleanup_close_ int source_fd = -EBADF, target_fd = -EBADF, dfd = -EBADF;
                 _cleanup_free_ char *dn = NULL, *bn = NULL;
 
                 r = path_extract_directory(arg_target, &dn);
@@ -1177,7 +1177,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
                 /* When this is a regular file we don't copy ownership! */
 
         } else {
-                _cleanup_close_ int dfd = -1;
+                _cleanup_close_ int dfd = -EBADF;
 
                 dfd = open(mounted_dir, O_DIRECTORY|O_CLOEXEC|O_RDONLY);
                 if (dfd < 0)
@@ -1199,7 +1199,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
 }
 
 static int action_umount(const char *path) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *canonical = NULL;
         _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
@@ -1219,7 +1219,7 @@ static int action_umount(const char *path) {
 
         r = block_device_new_from_fd(fd, BLOCK_DEVICE_LOOKUP_WHOLE_DISK | BLOCK_DEVICE_LOOKUP_BACKING, &dev);
         if (r < 0) {
-                _cleanup_close_ int usr_fd = -1;
+                _cleanup_close_ int usr_fd = -EBADF;
 
                 /* The command `systemd-dissect --mount` expects that the image at least has the root or /usr
                  * partition. If it does not have the root partition, then we mount the /usr partition on a
index 73c76fceea5b8c1143696e496f0dd6a4ddf1f513..f5c0732cf5981beb41972cb46efe64e0fb923f01 100644 (file)
@@ -225,7 +225,7 @@ static int process_progress(int fd, FILE* console) {
 }
 
 static int fsck_progress_socket(void) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         fd = socket(AF_UNIX, SOCK_STREAM, 0);
index c08f76c14a3e2e8a611d78c23310a8fee1423624..cea674c4c8ba2c0fe6af72ae754b25e8fdf3d3d0 100644 (file)
@@ -106,7 +106,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 
         (void) boot_config_select_special_entries(&config, /* skip_efivars= */ false);
 
-        _cleanup_close_ int orig_stdout_fd = -1;
+        _cleanup_close_ int orig_stdout_fd = -EBADF;
         if (getenv_bool("SYSTEMD_FUZZ_OUTPUT") <= 0) {
                 orig_stdout_fd = fcntl(fileno(stdout), F_DUPFD_CLOEXEC, 3);
                 if (orig_stdout_fd < 0)
index f0134557301eaef598fa08831eb01336100fbf5f..f3029f49d04bf23d9600bdcbb7a90b5171b21527 100644 (file)
@@ -8,7 +8,7 @@
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         _cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-catalog.XXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
 
         if (!getenv("SYSTEMD_LOG_LEVEL"))
index b3f5ddc5860e012feeb6fed85852b010124cc566..d255e90db52ec722484f8725355d87992d7b8efc 100644 (file)
@@ -78,7 +78,7 @@ static int add_container_getty(const char *tty) {
 }
 
 static int verify_tty(const char *name) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *p;
 
         /* Some TTYs are weird and have been enumerated but don't work
index a6d25c84fc1b5aa53d73e06bdbb57c75c8d0e805..0a4c01834aa3465c7d1a0da15e5f9048fab1b532 100644 (file)
@@ -1964,7 +1964,7 @@ static int with_home(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
         _cleanup_(user_record_unrefp) UserRecord *secret = NULL;
-        _cleanup_close_ int acquired_fd = -1;
+        _cleanup_close_ int acquired_fd = -EBADF;
         _cleanup_strv_free_ char **cmdline  = NULL;
         const char *home;
         int r, ret;
index 4e3fd5f0ae6f994d11e55a4a495efd9717144b34..a47f4d8a844483f134a3b58ac215ee767d56f9ce 100644 (file)
@@ -597,7 +597,7 @@ int bus_home_method_acquire(
 
         _cleanup_(user_record_unrefp) UserRecord *secret = NULL;
         _cleanup_(operation_unrefp) Operation *o = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r, please_suspend;
         Home *h = ASSERT_PTR(userdata);
 
@@ -635,7 +635,7 @@ int bus_home_method_ref(
                 void *userdata,
                 sd_bus_error *error) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         Home *h = ASSERT_PTR(userdata);
         HomeState state;
         int please_suspend, r;
index 19be186400dc1ef60819a6bedae28f6adff6528d..c2514aafc9a7716eeb93fd9b23c6d99e48a66593 100644 (file)
@@ -135,11 +135,11 @@ int home_new(Manager *m, UserRecord *hr, const char *sysfs, Home **ret) {
                 .user_name = TAKE_PTR(nm),
                 .uid = hr->uid,
                 .state = _HOME_STATE_INVALID,
-                .worker_stdout_fd = -1,
+                .worker_stdout_fd = -EBADF,
                 .sysfs = TAKE_PTR(ns),
                 .signed_locally = -1,
-                .pin_fd = -1,
-                .luks_lock_fd = -1,
+                .pin_fd = -EBADF,
+                .luks_lock_fd = -EBADF,
         };
 
         r = hashmap_put(m->homes_by_name, home->user_name, home);
@@ -1137,7 +1137,7 @@ static int home_on_worker_process(sd_event_source *s, const siginfo_t *si, void
 static int home_start_work(Home *h, const char *verb, UserRecord *hr, UserRecord *secret) {
         _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
         _cleanup_(erase_and_freep) char *formatted = NULL;
-        _cleanup_close_ int stdin_fd = -1, stdout_fd = -1;
+        _cleanup_close_ int stdin_fd = -EBADF, stdout_fd = -EBADF;
         pid_t pid = 0;
         int r;
 
@@ -1496,7 +1496,7 @@ int home_create(Home *h, UserRecord *secret, sd_bus_error *error) {
                 if (IN_SET(t, USER_TEST_MAYBE, USER_TEST_UNDEFINED))
                         break; /* And if the image path test isn't conclusive, let's also go on */
 
-                if (IN_SET(t, -EBADFD, -ENOTDIR))
+                if (IN_SET(t, -EBADF, -ENOTDIR))
                         return sd_bus_error_setf(error, BUS_ERROR_HOME_EXISTS, "Selected home image of user %s already exists or has wrong inode type.", h->user_name);
 
                 return sd_bus_error_setf(error, BUS_ERROR_HOME_EXISTS, "Selected home image of user %s already exists.", h->user_name);
@@ -2630,7 +2630,7 @@ static int on_home_ref_eof(sd_event_source *s, int fd, uint32_t revents, void *u
 }
 
 int home_create_fifo(Home *h, bool please_suspend) {
-        _cleanup_close_ int ret_fd = -1;
+        _cleanup_close_ int ret_fd = -EBADF;
         sd_event_source **ss;
         const char *fn, *suffix;
         int r;
@@ -2648,7 +2648,7 @@ int home_create_fifo(Home *h, bool please_suspend) {
         fn = strjoina("/run/systemd/home/", h->user_name, suffix);
 
         if (!*ss) {
-                _cleanup_close_ int ref_fd = -1;
+                _cleanup_close_ int ref_fd = -EBADF;
 
                 (void) mkdir("/run/systemd/home/", 0755);
                 if (mkfifo(fn, 0600) < 0 && errno != EEXIST)
index 61ef979049497dc45518a4235d8e5ca6d79a6b97..2fd1d67eff219237f07f5f7f6264889d7abd1e11 100644 (file)
@@ -860,7 +860,7 @@ static int manager_assess_image(
 
         if (S_ISDIR(st.st_mode)) {
                 _cleanup_free_ char *n = NULL, *user_name = NULL, *realm = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 UserStorage storage;
 
                 if (!directory_suffix)
@@ -1041,7 +1041,7 @@ static ssize_t read_datagram(
 
         CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred)) + CMSG_SPACE(sizeof(int))) control;
         _cleanup_free_ void *buffer = NULL;
-        _cleanup_close_ int passed_fd = -1;
+        _cleanup_close_ int passed_fd = -EBADF;
         struct ucred *sender = NULL;
         struct cmsghdr *cmsg;
         struct msghdr mh;
@@ -1119,7 +1119,7 @@ static ssize_t read_datagram(
 static int on_notify_socket(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
         _cleanup_strv_free_ char **l = NULL;
         _cleanup_free_ void *datagram = NULL;
-        _cleanup_close_ int passed_fd = -1;
+        _cleanup_close_ int passed_fd = -EBADF;
         struct ucred sender = UCRED_INVALID;
         Manager *m = ASSERT_PTR(userdata);
         ssize_t n;
@@ -1154,7 +1154,7 @@ static int on_notify_socket(sd_event_source *s, int fd, uint32_t revents, void *
 }
 
 static int manager_listen_notify(Manager *m) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union sockaddr_union sa = {
                 .un.sun_family = AF_UNIX,
                 .un.sun_path = "/run/systemd/home/notify",
index 3847fc5d6878aff350860dfebacf7eb92e17337d..618e920a596cd8c810fa9506fc02f81dbcfeb20a 100644 (file)
@@ -17,7 +17,7 @@ Operation *operation_new(OperationType type, sd_bus_message *m) {
                 .type = type,
                 .n_ref = 1,
                 .message = sd_bus_message_ref(m),
-                .send_fd = -1,
+                .send_fd = -EBADF,
                 .result = -1,
         };
 
index d3bc54742981d417e0ac4ceaa65c7b51ae25af9d..6668edb7491028790798d6f82b91de5057c80aef 100644 (file)
@@ -108,7 +108,7 @@ int home_activate_directory(
 int home_create_directory_or_subvolume(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) {
         _cleanup_(rm_rf_subvolume_and_freep) char *temporary = NULL;
         _cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
-        _cleanup_close_ int mount_fd = -1;
+        _cleanup_close_ int mount_fd = -EBADF;
         _cleanup_free_ char *d = NULL;
         bool is_subvolume = false;
         const char *ip;
index f29c55c8952b05dc5859efbc777f7f0f3f13e43a..f8f9f462bbca967766f640fcb5e8b35c377c9008 100644 (file)
@@ -491,7 +491,7 @@ int home_create_fscrypt(
         _cleanup_(rm_rf_physical_and_freep) char *temporary = NULL;
         _cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
         _cleanup_(erase_and_freep) void *volume_key = NULL;
-        _cleanup_close_ int mount_fd = -1;
+        _cleanup_close_ int mount_fd = -EBADF;
         struct fscrypt_policy policy = {};
         size_t volume_key_size = 512 / 8;
         _cleanup_free_ char *d = NULL;
index 2b803bc0bdd19f60cd2fdf68637908b55abaafb7..f215558ae04b0a4d1779aa1b40568201398d57fd 100644 (file)
@@ -108,7 +108,7 @@ int run_mark_dirty(int fd, bool b) {
 }
 
 int run_mark_dirty_by_path(const char *path, bool b) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(path);
 
@@ -178,7 +178,7 @@ static int probe_file_system_by_fd(
 }
 
 static int probe_file_system_by_path(const char *path, char **ret_fstype, sd_id128_t *ret_uuid) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
         if (fd < 0)
@@ -203,7 +203,7 @@ static int block_get_size_by_fd(int fd, uint64_t *ret) {
 }
 
 static int block_get_size_by_path(const char *path, uint64_t *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
         if (fd < 0)
@@ -1135,7 +1135,7 @@ int run_fallocate(int backing_fd, const struct stat *st) {
 }
 
 int run_fallocate_by_path(const char *backing_path) {
-        _cleanup_close_ int backing_fd = -1;
+        _cleanup_close_ int backing_fd = -EBADF;
 
         backing_fd = open(backing_path, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
         if (backing_fd < 0)
@@ -1187,7 +1187,7 @@ static int open_image_file(
                 const char *force_image_path,
                 struct stat *ret_stat) {
 
-        _cleanup_close_ int image_fd = -1;
+        _cleanup_close_ int image_fd = -EBADF;
         struct stat st;
         const char *ip;
         int r;
@@ -1959,7 +1959,7 @@ static bool supported_fs_size(const char *fstype, uint64_t host_size) {
 }
 
 static int wait_for_devlink(const char *path) {
-        _cleanup_close_ int inotify_fd = -1;
+        _cleanup_close_ int inotify_fd = -EBADF;
         usec_t until;
         int r;
 
@@ -2141,7 +2141,7 @@ int home_create_luks(
                 host_size = 0, partition_offset = 0, partition_size = 0; /* Unnecessary initialization to appease gcc */
         _cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
         sd_id128_t partition_uuid, fs_uuid, luks_uuid, disk_uuid;
-        _cleanup_close_ int mount_fd = -1;
+        _cleanup_close_ int mount_fd = -EBADF;
         const char *fstype, *ip;
         struct statfs sfs;
         int r;
@@ -3079,9 +3079,9 @@ int home_resize_luks(
         _cleanup_(user_record_unrefp) UserRecord *header_home = NULL, *embedded_home = NULL, *new_home = NULL;
         _cleanup_(fdisk_unref_tablep) struct fdisk_table *table = NULL;
         struct fdisk_partition *partition = NULL;
-        _cleanup_close_ int opened_image_fd = -1;
+        _cleanup_close_ int opened_image_fd = -EBADF;
         _cleanup_free_ char *whole_disk = NULL;
-        int r, resize_type, image_fd = -1;
+        int r, resize_type, image_fd = -EBADF;
         sd_id128_t disk_uuid;
         const char *ip, *ipo;
         struct statfs sfs;
index cd03f79a7398ee22b99f7c917e64980bb7082a56..cf42a0b94dfae6e7aa3254db66eadfa80ac6b464 100644 (file)
@@ -186,7 +186,7 @@ static int append_identity_range(char **text, uid_t start, uid_t next_start, uid
 
 static int make_userns(uid_t stored_uid, uid_t exposed_uid) {
         _cleanup_free_ char *text = NULL;
-        _cleanup_close_ int userns_fd = -1;
+        _cleanup_close_ int userns_fd = -EBADF;
         int r;
 
         assert(uid_is_valid(stored_uid));
@@ -238,7 +238,7 @@ static int make_userns(uid_t stored_uid, uid_t exposed_uid) {
 }
 
 int home_shift_uid(int dir_fd, const char *target, uid_t stored_uid, uid_t exposed_uid, int *ret_mount_fd) {
-        _cleanup_close_ int mount_fd = -1, userns_fd = -1;
+        _cleanup_close_ int mount_fd = -EBADF, userns_fd = -EBADF;
         int r;
 
         assert(dir_fd >= 0);
@@ -261,7 +261,7 @@ int home_shift_uid(int dir_fd, const char *target, uid_t stored_uid, uid_t expos
                         log_debug_errno(errno, "The open_tree() syscall is not supported, not setting up UID shift mount: %m");
 
                         if (ret_mount_fd)
-                                *ret_mount_fd = -1;
+                                *ret_mount_fd = -EBADF;
 
                         return 0;
                 }
@@ -284,7 +284,7 @@ int home_shift_uid(int dir_fd, const char *target, uid_t stored_uid, uid_t expos
                         log_debug_errno(errno, "UID/GID mapping for shifted mount not available, not setting it up: %m");
 
                         if (ret_mount_fd)
-                                *ret_mount_fd = -1;
+                                *ret_mount_fd = -EBADF;
 
                         return 0;
                 }
index bc38437f2cf6cee030bfd6b57abd7e74142dd3e9..28907386a46419fe4b49f1a89aa87219c6ce28c5 100644 (file)
@@ -512,7 +512,7 @@ int home_sync_and_statfs(int root_fd, struct statfs *ret) {
 
 static int read_identity_file(int root_fd, JsonVariant **ret) {
         _cleanup_(fclosep) FILE *identity_file = NULL;
-        _cleanup_close_ int identity_fd = -1;
+        _cleanup_close_ int identity_fd = -EBADF;
         unsigned line, column;
         int r;
 
@@ -543,7 +543,7 @@ static int read_identity_file(int root_fd, JsonVariant **ret) {
 static int write_identity_file(int root_fd, JsonVariant *v, uid_t uid) {
         _cleanup_(json_variant_unrefp) JsonVariant *normalized = NULL;
         _cleanup_(fclosep) FILE *identity_file = NULL;
-        _cleanup_close_ int identity_fd = -1;
+        _cleanup_close_ int identity_fd = -EBADF;
         _cleanup_free_ char *fn = NULL;
         int r;
 
@@ -785,7 +785,7 @@ int home_maybe_shift_uid(
                 HomeSetupFlags flags,
                 HomeSetup *setup) {
 
-        _cleanup_close_ int mount_fd = -1;
+        _cleanup_close_ int mount_fd = -EBADF;
         struct stat st;
 
         assert(h);
index b27c31d56bab562e54050440e7cf2c7b8213fae4..cef3f4eb98b99996136502068e2ef1fe292f87ad 100644 (file)
@@ -50,8 +50,8 @@ typedef struct HomeSetup {
 
 #define HOME_SETUP_INIT                                 \
         {                                               \
-                .root_fd = -1,                          \
-                .image_fd = -1,                         \
+                .root_fd = -EBADF,                      \
+                .image_fd = -EBADF,                     \
                 .partition_offset = UINT64_MAX,         \
                 .partition_size = UINT64_MAX,           \
                 .key_serial = -1,                       \
index 8b41416578004e287607494f29b87240632890b0..8a7bfc5837f26fe9b9e3bccea4c3b425994b1229 100644 (file)
@@ -477,7 +477,7 @@ static int acquire_home(
         _cleanup_(user_record_unrefp) UserRecord *ur = NULL, *secret = NULL;
         bool do_auth = please_authenticate, home_not_active = false, home_locked = false;
         _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
-        _cleanup_close_ int acquired_fd = -1;
+        _cleanup_close_ int acquired_fd = -EBADF;
         _cleanup_free_ char *fd_field = NULL;
         const void *home_fd_ptr = NULL;
         const char *username = NULL;
index 6b15884e777dd071d8963e046382b1c03aae979e..7c61aef3b68f15149e6df08d994c8e9cc3358804 100644 (file)
@@ -84,8 +84,8 @@ int raw_export_new(
                 return -ENOMEM;
 
         *e = (RawExport) {
-                .output_fd = -1,
-                .input_fd = -1,
+                .output_fd = -EBADF,
+                .input_fd = -EBADF,
                 .on_finished = on_finished,
                 .userdata = userdata,
                 .last_percent = UINT_MAX,
@@ -267,7 +267,7 @@ static int reflink_snapshot(int fd, const char *path) {
 }
 
 int raw_export_start(RawExport *e, const char *path, int fd, ImportCompressType compress) {
-        _cleanup_close_ int sfd = -1, tfd = -1;
+        _cleanup_close_ int sfd = -EBADF, tfd = -EBADF;
         int r;
 
         assert(e);
index b9953a4bf3743e72e8b5f8233e270813e01b0172..4aa8204983a448b1817da8e789dbd3da09e136e4 100644 (file)
@@ -90,8 +90,8 @@ int tar_export_new(
                 return -ENOMEM;
 
         *e = (TarExport) {
-                .output_fd = -1,
-                .tar_fd = -1,
+                .output_fd = -EBADF,
+                .tar_fd = -EBADF,
                 .on_finished = on_finished,
                 .userdata = userdata,
                 .quota_referenced = UINT64_MAX,
@@ -250,7 +250,7 @@ static int tar_export_on_defer(sd_event_source *s, void *userdata) {
 }
 
 int tar_export_start(TarExport *e, const char *path, int fd, ImportCompressType compress) {
-        _cleanup_close_ int sfd = -1;
+        _cleanup_close_ int sfd = -EBADF;
         int r;
 
         assert(e);
index 690e19445335e2f20445849d7dd5dee7d540fe38..84609cbe124da43863676423bdf19ac80e1960d2 100644 (file)
@@ -63,7 +63,7 @@ static int export_tar(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_event_unrefp) sd_event *event = NULL;
         _cleanup_(image_unrefp) Image *image = NULL;
         const char *path = NULL, *local = NULL;
-        _cleanup_close_ int open_fd = -1;
+        _cleanup_close_ int open_fd = -EBADF;
         int r, fd;
 
         if (hostname_is_valid(argv[1], 0)) {
@@ -139,7 +139,7 @@ static int export_raw(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_event_unrefp) sd_event *event = NULL;
         _cleanup_(image_unrefp) Image *image = NULL;
         const char *path = NULL, *local = NULL;
-        _cleanup_close_ int open_fd = -1;
+        _cleanup_close_ int open_fd = -EBADF;
         int r, fd;
 
         if (hostname_is_valid(argv[1], 0)) {
index ca5d33c00821b0669f41a027fac52404fb207682..d81dd13ffde4df06b37097c735e842d16b349bb9 100644 (file)
@@ -100,7 +100,7 @@ static int import_fs(int argc, char *argv[], void *userdata) {
         _cleanup_(progress_info_free) ProgressInfo progress = {};
         _cleanup_free_ char *l = NULL, *final_path = NULL;
         const char *path = NULL, *local = NULL, *dest = NULL;
-        _cleanup_close_ int open_fd = -1;
+        _cleanup_close_ int open_fd = -EBADF;
         int r, fd;
 
         if (argc >= 2)
index ee904bc4e0ed6ee97f972041ddf5d1e5f20ace83..5d4dedf66d609b1c52e3d0b75e262e7fa33e6460 100644 (file)
@@ -105,8 +105,8 @@ int raw_import_new(
                 return -ENOMEM;
 
         *i = (RawImport) {
-                .input_fd = -1,
-                .output_fd = -1,
+                .input_fd = -EBADF,
+                .output_fd = -EBADF,
                 .on_finished = on_finished,
                 .userdata = userdata,
                 .last_percent = UINT_MAX,
@@ -154,7 +154,7 @@ static void raw_import_report_progress(RawImport *i) {
 }
 
 static int raw_import_maybe_convert_qcow2(RawImport *i) {
-        _cleanup_close_ int converted_fd = -1;
+        _cleanup_close_ int converted_fd = -EBADF;
         _cleanup_(unlink_and_freep) char *t = NULL;
         _cleanup_free_ char *f = NULL;
         int r;
index 90b4e51d2c121a57a54ef4b15864fe5b65536185..dff6d3276ab2a382beed15d037dff609173c0c75 100644 (file)
@@ -107,8 +107,8 @@ int tar_import_new(
                 return -ENOMEM;
 
         *i = (TarImport) {
-                .input_fd = -1,
-                .tar_fd = -1,
+                .input_fd = -EBADF,
+                .tar_fd = -EBADF,
                 .on_finished = on_finished,
                 .userdata = userdata,
                 .last_percent = UINT_MAX,
index 13f34633d2a5dae016b94ce9152b9b32b454fb31..a81617d38e865a8173f2cabbb8bc9b07bfc95f73 100644 (file)
@@ -83,7 +83,7 @@ static int normalize_local(const char *local, char **ret) {
 }
 
 static int open_source(const char *path, const char *local, int *ret_open_fd) {
-        _cleanup_close_ int open_fd = -1;
+        _cleanup_close_ int open_fd = -EBADF;
         int retval;
 
         assert(local);
@@ -132,7 +132,7 @@ static int import_tar(int argc, char *argv[], void *userdata) {
         _cleanup_free_ char *ll = NULL, *normalized = NULL;
         _cleanup_(sd_event_unrefp) sd_event *event = NULL;
         const char *path = NULL, *local = NULL;
-        _cleanup_close_ int open_fd = -1;
+        _cleanup_close_ int open_fd = -EBADF;
         int r, fd;
 
         if (argc >= 2)
@@ -204,7 +204,7 @@ static int import_raw(int argc, char *argv[], void *userdata) {
         _cleanup_free_ char *ll = NULL, *normalized = NULL;
         _cleanup_(sd_event_unrefp) sd_event *event = NULL;
         const char *path = NULL, *local = NULL;
-        _cleanup_close_ int open_fd = -1;
+        _cleanup_close_ int open_fd = -EBADF;
         int r, fd;
 
         if (argc >= 2)
index 4f6be5f20c914f143e8e79da193a36dab3470b7c..b2d176b4e739e94f795d17a1c407fe300e54f92b 100644 (file)
@@ -157,9 +157,9 @@ static int transfer_new(Manager *m, Transfer **ret) {
 
         *t = (Transfer) {
                 .type = _TRANSFER_TYPE_INVALID,
-                .log_fd = -1,
-                .stdin_fd = -1,
-                .stdout_fd = -1,
+                .log_fd = -EBADF,
+                .stdin_fd = -EBADF,
+                .stdout_fd = -EBADF,
                 .verify = _IMPORT_VERIFY_INVALID,
                 .progress_percent= UINT_MAX,
         };
index 1e105bc769f71eb5cbd1b8194bcd7f3af22b2c03..ce7642e897cf61fba276cda07dd1ea8f1765e82e 100644 (file)
@@ -27,7 +27,7 @@ void pull_job_close_disk_fd(PullJob *j) {
         if (j->close_disk_fd)
                 safe_close(j->disk_fd);
 
-        j->disk_fd = -1;
+        j->disk_fd = -EBADF;
 }
 
 PullJob* pull_job_unref(PullJob *j) {
@@ -692,7 +692,7 @@ int pull_job_new(
 
         *j = (PullJob) {
                 .state = PULL_JOB_INIT,
-                .disk_fd = -1,
+                .disk_fd = -EBADF,
                 .close_disk_fd = true,
                 .userdata = userdata,
                 .glue = glue,
index d3d14af6d1d24ff01815da7f264b3b9692926a83..a4a844bf0727ac160cb2bf3681f943839c103c6b 100644 (file)
@@ -238,7 +238,7 @@ static void raw_pull_report_progress(RawPull *i, RawProgress p) {
 
 static int raw_pull_maybe_convert_qcow2(RawPull *i) {
         _cleanup_(unlink_and_freep) char *t = NULL;
-        _cleanup_close_ int converted_fd = -1;
+        _cleanup_close_ int converted_fd = -EBADF;
         _cleanup_free_ char *f = NULL;
         int r;
 
@@ -346,7 +346,7 @@ static int raw_pull_copy_auxiliary_file(
 static int raw_pull_make_local_copy(RawPull *i) {
         _cleanup_(unlink_and_freep) char *tp = NULL;
         _cleanup_free_ char *f = NULL;
-        _cleanup_close_ int dfd = -1;
+        _cleanup_close_ int dfd = -EBADF;
         const char *p;
         int r;
 
index 77fed01dd375b87e725d53f961684a8444547ade..ca31fd678d31a8aff3c0741340c1bb60289d834e 100644 (file)
@@ -9,7 +9,7 @@
 #include "qcow2-util.h"
 
 int main(int argc, char *argv[]) {
-        _cleanup_close_ int sfd = -1, dfd = -1;
+        _cleanup_close_ int sfd = -EBADF, dfd = -EBADF;
         int r;
 
         if (argc != 3) {
index db10c2b01271070758ae69bb1f796c784094394f..da0d83ec9a96bf6962ef23d2cd19a2bcf51d6435 100644 (file)
@@ -19,7 +19,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         int fdin;
         void *mem;
         _cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-journal-remote.XXXXXX.journal";
-        _cleanup_close_ int fdout = -1;
+        _cleanup_close_ int fdout = -EBADF;
         _cleanup_(sd_journal_closep) sd_journal *j = NULL;
         _cleanup_(journal_remote_server_destroy) RemoteServer s = {};
         int r;
index b3b44bceb8b50850d11af6465671f15669abbd85..747e0be743b0cd09322d4c88ab8505c76c1a37e0 100644 (file)
@@ -127,7 +127,7 @@ static int request_meta_ensure_tmp(RequestMeta *m) {
         if (m->tmp)
                 rewind(m->tmp);
         else {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 fd = open_tmpfile_unlinkable("/tmp", O_RDWR|O_CLOEXEC);
                 if (fd < 0)
@@ -670,7 +670,7 @@ static int request_handler_file(
                 const char *mime_type) {
 
         _cleanup_(MHD_destroy_responsep) struct MHD_Response *response = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
 
         assert(connection);
index 3d7b552e95e90f3eab451bf656fb2cc7ab916121..a670468884133d3d2db09c119c51d512954c9f11 100644 (file)
@@ -294,7 +294,7 @@ int journal_remote_add_raw_socket(RemoteServer *s, int fd) {
         if (r < 0)
                 return r;
 
-        fd_ = -1;
+        fd_ = -EBADF;
         s->active++;
         return 0;
 }
@@ -483,7 +483,7 @@ static int accept_connection(
                 SocketAddress *addr,
                 char **hostname) {
 
-        _cleanup_close_ int fd2 = -1;
+        _cleanup_close_ int fd2 = -EBADF;
         int r;
 
         log_debug("Accepting new %s connection on fd:%d", type, fd);
index 404a74873634d33696467870fd375c50328631d3..0ba427a660b54cd7e12efea8e66c8e1b92f46358 100644 (file)
@@ -122,7 +122,7 @@ static int parse_argv(int argc, char *argv[]) {
 }
 
 static int run(int argc, char *argv[]) {
-        _cleanup_close_ int outfd = -1, errfd = -1, saved_stderr = -1;
+        _cleanup_close_ int outfd = -EBADF, errfd = -EBADF, saved_stderr = -EBADF;
         int r;
 
         log_setup();
index fcfc5dfaba4a0259130264925bf94538a45504a2..9adbb8b0dc52988921637c14658bcc01bbffe74a 100644 (file)
@@ -11,7 +11,7 @@
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         Server s;
-        _cleanup_close_ int sealed_fd = -1, unsealed_fd = -1;
+        _cleanup_close_ int sealed_fd = -EBADF, unsealed_fd = -EBADF;
         _cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-journald-native-fd.XXXXXX";
         char *label = NULL;
         size_t label_len = 0;
index ff1746e1221ca45c0f58e30f152434fc9a53f952..c96fad58e8dda990a8fe6742bd86e7a902f2a35e 100644 (file)
@@ -7,13 +7,13 @@
 
 void dummy_server_init(Server *s, const uint8_t *buffer, size_t size) {
         *s = (Server) {
-                .syslog_fd = -1,
-                .native_fd = -1,
-                .stdout_fd = -1,
-                .dev_kmsg_fd = -1,
-                .audit_fd = -1,
-                .hostname_fd = -1,
-                .notify_fd = -1,
+                .syslog_fd = -EBADF,
+                .native_fd = -EBADF,
+                .stdout_fd = -EBADF,
+                .dev_kmsg_fd = -EBADF,
+                .audit_fd = -EBADF,
+                .hostname_fd = -EBADF,
+                .notify_fd = -EBADF,
                 .storage = STORAGE_NONE,
                 .line_max = 64,
         };
index ba5636af141d38ccda6453e86c5391e033f87d5c..7805c9cd9db22d6d204468f193249a2b9fe29c6d 100644 (file)
@@ -1803,7 +1803,7 @@ static int setup_keys(void) {
         _cleanup_(unlink_and_freep) char *k = NULL;
         _cleanup_free_ char *p = NULL;
         uint8_t *mpk, *seed, *state;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         sd_id128_t machine, boot;
         struct stat st;
         uint64_t n;
@@ -2101,7 +2101,7 @@ int main(int argc, char *argv[]) {
         _cleanup_(sd_journal_closep) sd_journal *j = NULL;
         sd_id128_t previous_boot_id = SD_ID128_NULL, previous_boot_id_output = SD_ID128_NULL;
         dual_timestamp previous_ts_output = DUAL_TIMESTAMP_NULL;
-        int n_shown = 0, r, poll_fd = -1;
+        int n_shown = 0, r, poll_fd = -EBADF;
 
         setlocale(LC_ALL, "");
         log_setup();
index 2035e2d9b6962cd9a3fb8d71347b7928cb31bf97..c8a3e18360f208e802eb53c69fe2d92353d39ef4 100644 (file)
@@ -43,7 +43,7 @@ void server_forward_console(
         char tbuf[STRLEN("[] ") + DECIMAL_STR_MAX(ts.tv_sec) + DECIMAL_STR_MAX(ts.tv_nsec)-3 + 1];
         char header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t)];
         _cleanup_free_ char *ident_buf = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *tty;
         int n = 0;
 
index 99eace084876bb72b01a1faf078b5dca6800158a..685863ff50ca6b634a6fa86207708ba50ce80777 100644 (file)
@@ -431,7 +431,7 @@ fail:
 }
 
 int server_open_kernel_seqnum(Server *s) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *fn;
         uint64_t *p;
         int r;
index b268db0220ea4387283e660fddc691977e83c901..9e2d239abd26e7c9cd1e146ff4d48a1e49727cfe 100644 (file)
@@ -560,7 +560,7 @@ static int vacuum_offline_user_journals(Server *s) {
 
         for (;;) {
                 _cleanup_free_ char *u = NULL, *full = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 const char *a, *b;
                 struct dirent *de;
                 ManagedJournalFile *f;
@@ -2299,19 +2299,19 @@ static int set_namespace(Server *s, const char *namespace) {
 int server_init(Server *s, const char *namespace) {
         const char *native_socket, *syslog_socket, *stdout_socket, *varlink_socket, *e;
         _cleanup_fdset_free_ FDSet *fds = NULL;
-        int n, r, fd, varlink_fd = -1;
+        int n, r, fd, varlink_fd = -EBADF;
         bool no_sockets;
 
         assert(s);
 
         *s = (Server) {
-                .syslog_fd = -1,
-                .native_fd = -1,
-                .stdout_fd = -1,
-                .dev_kmsg_fd = -1,
-                .audit_fd = -1,
-                .hostname_fd = -1,
-                .notify_fd = -1,
+                .syslog_fd = -EBADF,
+                .native_fd = -EBADF,
+                .stdout_fd = -EBADF,
+                .dev_kmsg_fd = -EBADF,
+                .audit_fd = -EBADF,
+                .hostname_fd = -EBADF,
+                .notify_fd = -EBADF,
 
                 .compress.enabled = true,
                 .compress.threshold_bytes = UINT64_MAX,
index 4446b2daec7ce63e44a37066cc56c004bed2e414..735e2c5e8bac63e4444cfae56315b2998347ece7 100644 (file)
@@ -669,7 +669,7 @@ int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
                 return log_oom();
 
         *stream = (StdoutStream) {
-                .fd = -1,
+                .fd = -EBADF,
                 .priority = LOG_INFO,
                 .ucred = UCRED_INVALID,
         };
@@ -716,7 +716,7 @@ int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
 }
 
 static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revents, void *userdata) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         Server *s = ASSERT_PTR(userdata);
         int r;
 
index 24edc371db03c2fc27c6290742072c1952435f32..598669fe20ceee865e3637be2373b0c8726da9b3 100644 (file)
@@ -37,7 +37,7 @@ int lldp_network_bind_raw_socket(int ifindex) {
                 .ll.sll_family = AF_PACKET,
                 .ll.sll_ifindex = ifindex,
         };
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(ifindex > 0);
 
index 47b4cb121f54ad29d26daf96ba94ea88e0b34f4d..48174e7c4b0f9848c300192d2faa5444a8b14944 100644 (file)
@@ -2207,7 +2207,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) {
                 .n_ref = 1,
                 .state = DHCP_STATE_INIT,
                 .ifindex = -1,
-                .fd = -1,
+                .fd = -EBADF,
                 .mtu = DHCP_MIN_PACKET_SIZE,
                 .port = DHCP_PORT_CLIENT,
                 .anonymize = !!anonymize,
index 11ab2338cecbf55f9ebcfb21a5dda9bf32685fbd..b5aff7d4fab54d8e54c2907e824ab68be7f83496 100644 (file)
@@ -200,9 +200,9 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
 
         *server = (sd_dhcp_server) {
                 .n_ref = 1,
-                .fd_raw = -1,
-                .fd = -1,
-                .fd_broadcast = -1,
+                .fd_raw = -EBADF,
+                .fd = -EBADF,
+                .fd_broadcast = -EBADF,
                 .address = htobe32(INADDR_ANY),
                 .netmask = htobe32(INADDR_ANY),
                 .ifindex = ifindex,
index 3f34b46280894f7a5833e3eb78121ddc3fb9f8a8..29cd0035063000c638d98f7cd668d4d06ac4d187 100644 (file)
@@ -1499,7 +1499,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret) {
                 .ia_pd.type = SD_DHCP6_OPTION_IA_PD,
                 .ifindex = -1,
                 .request_ia = DHCP6_REQUEST_IA_NA | DHCP6_REQUEST_IA_PD,
-                .fd = -1,
+                .fd = -EBADF,
                 .rapid_commit = true,
         };
 
index 9b11b2f160663f68a49e0ed6c78339284bad31a1..d34c63e854ab3efc1850e24d902123e35fdc9888 100644 (file)
@@ -151,7 +151,7 @@ int sd_ipv4acd_new(sd_ipv4acd **ret) {
                 .n_ref = 1,
                 .state = IPV4ACD_STATE_INIT,
                 .ifindex = -1,
-                .fd = -1,
+                .fd = -EBADF,
         };
 
         *ret = TAKE_PTR(acd);
index 0479cff5f5758032bb9dd512b8b09cc07f3a3efa..03e89860498344ff65d5e379ae0a0c1deb7da479 100644 (file)
@@ -405,7 +405,7 @@ int sd_lldp_rx_new(sd_lldp_rx **ret) {
 
         *lldp_rx = (sd_lldp_rx) {
                 .n_ref = 1,
-                .fd = -1,
+                .fd = -EBADF,
                 .neighbors_max = LLDP_DEFAULT_NEIGHBORS_MAX,
                 .capability_mask = UINT16_MAX,
         };
index d2d24be089eeb58c932d8dc7d2b76dd72dff9c0f..2b822af01a90781f68328a55b7552620d12ec8d7 100644 (file)
@@ -451,7 +451,7 @@ static int lldp_tx_create_packet(sd_lldp_tx *lldp_tx, size_t *ret_packet_size, u
 }
 
 static int lldp_tx_send_packet(sd_lldp_tx *lldp_tx, size_t packet_size, const uint8_t *packet) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union sockaddr_union sa;
         ssize_t l;
 
index 2cf0cebdeb741826054a34d63885039806ae7ac4..2e446fece3d1e5b6e2a492e61c87342f5180cf15 100644 (file)
@@ -171,7 +171,7 @@ int sd_ndisc_new(sd_ndisc **ret) {
 
         *nd = (sd_ndisc) {
                 .n_ref = 1,
-                .fd = -1,
+                .fd = -EBADF,
         };
 
         *ret = TAKE_PTR(nd);
index a3a5a21b3d70e761980d99ada7d565604a91628e..20458b9f97eb89da3fd9bd1d4632ef2e573a87b3 100644 (file)
@@ -37,7 +37,7 @@ int sd_radv_new(sd_radv **ret) {
 
         *ra = (sd_radv) {
                 .n_ref = 1,
-                .fd = -1,
+                .fd = -EBADF,
                 .lifetime_usec = RADV_DEFAULT_ROUTER_LIFETIME_USEC,
         };
 
index b9a38269d9d0518d5fde59dec49b99bad02541c5..3047dce85810a7d8ed56b52ef23b7b5b1d5fd7d9 100644 (file)
@@ -13,7 +13,7 @@
 
 int bus_container_connect_socket(sd_bus *b) {
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
-        _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
+        _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
         int r, error_buf = 0;
         pid_t child;
         ssize_t n;
index 39e21480ac2b2e36eb7e86c82eda3e744e112dd1..07168f660b8af907744ec210fb86a1d181f1b081 100644 (file)
@@ -433,7 +433,7 @@ int bus_message_from_malloc(
                 m->body.data = (uint8_t*) buffer + sizeof(struct bus_header) + ALIGN8(m->fields_size);
                 m->body.size = sz;
                 m->body.sealed = true;
-                m->body.memfd = -1;
+                m->body.memfd = -EBADF;
         }
 
         m->n_iovec = 1;
@@ -1108,7 +1108,7 @@ static struct bus_body_part *message_append_part(sd_bus_message *m) {
                 m->body_end->next = part;
         }
 
-        part->memfd = -1;
+        part->memfd = -EBADF;
         m->body_end = part;
         m->n_body_parts++;
 
@@ -1303,7 +1303,7 @@ static int message_push_fd(sd_bus_message *m, int fd) {
 }
 
 int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct bus_container *c;
         ssize_t align, sz;
         uint32_t u32;
@@ -1422,7 +1422,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
         if (c->enclosing != SD_BUS_TYPE_ARRAY)
                 c->index++;
 
-        fd = -1;
+        fd = -EBADF;
         return 0;
 }
 
@@ -2172,7 +2172,7 @@ _public_ int sd_bus_message_append_array_memfd(
                 uint64_t offset,
                 uint64_t size) {
 
-        _cleanup_close_ int copy_fd = -1;
+        _cleanup_close_ int copy_fd = -EBADF;
         struct bus_body_part *part;
         ssize_t align, sz;
         uint64_t real_size;
@@ -2234,7 +2234,7 @@ _public_ int sd_bus_message_append_array_memfd(
         part->memfd_offset = offset;
         part->sealed = true;
         part->size = size;
-        copy_fd = -1;
+        copy_fd = -EBADF;
 
         m->body_size += size;
         message_extend_containers(m, size);
@@ -2248,7 +2248,7 @@ _public_ int sd_bus_message_append_string_memfd(
                 uint64_t offset,
                 uint64_t size) {
 
-        _cleanup_close_ int copy_fd = -1;
+        _cleanup_close_ int copy_fd = -EBADF;
         struct bus_body_part *part;
         struct bus_container *c;
         uint64_t real_size;
@@ -2319,7 +2319,7 @@ _public_ int sd_bus_message_append_string_memfd(
         part->memfd_offset = offset;
         part->sealed = true;
         part->size = size;
-        copy_fd = -1;
+        copy_fd = -EBADF;
 
         m->body_size += size;
         message_extend_containers(m, size);
index c75276f4bacc3c3abb5d43400b2dd5fc69a54a84..d85dcc52c17d47705f5ee8c14a9f4b54a9ae1375 100644 (file)
@@ -240,9 +240,9 @@ _public_ int sd_bus_new(sd_bus **ret) {
 
         *b = (sd_bus) {
                 .n_ref = 1,
-                .input_fd = -1,
-                .output_fd = -1,
-                .inotify_fd = -1,
+                .input_fd = -EBADF,
+                .output_fd = -EBADF,
+                .inotify_fd = -EBADF,
                 .message_version = 1,
                 .creds_mask = SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME,
                 .accept_fd = true,
index 6e522ae54becaadb6fc59fcb45db4d6307d99b04..987d151b55ebfde5787f34eadf977a40b5224ed8 100644 (file)
@@ -40,7 +40,7 @@ static const sd_bus_vtable vtable[] = {
 
 static void* thread_server(void *p) {
         _cleanup_free_ char *suffixed = NULL, *suffixed2 = NULL, *d = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union sockaddr_union u;
         const char *path = p;
         int r;
index 80206a7d914938073858f91b9e91982fcfca67ed..91f96051717c2e8b1d489e3e839fbd395ac98112 100644 (file)
@@ -447,7 +447,7 @@ _public_ int sd_pid_notify_with_fds(
                 .msg_iovlen = 1,
                 .msg_name = &sockaddr,
         };
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct cmsghdr *cmsg = NULL;
         const char *e;
         bool send_ucred;
index b192914b1d09eeaf5aa5c48a567e621e14494c55..56acec67f6de2a2a4b536b685ecef60c0366fcec 100644 (file)
@@ -35,7 +35,7 @@ int devname_from_devnum(mode_t mode, dev_t devnum, char **ret) {
 
 int device_open_from_devnum(mode_t mode, dev_t devnum, int flags, char **ret) {
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         r = device_new_from_mode_and_devnum(&dev, mode, devnum);
index 9c4743f05508aa3d2d84aac98a172a04549068c4..2fcdce7bac9f48a6f7e07debcdce080e4257c5c0 100644 (file)
@@ -145,7 +145,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
         assert(_syspath);
 
         if (verify) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 /* The input path maybe a symlink located outside of /sys. Let's try to chase the symlink at first.
                  * The primary usecase is that e.g. /proc/device-tree is a symlink to /sys/firmware/devicetree/base.
@@ -2535,7 +2535,7 @@ _public_ int sd_device_trigger_with_uuid(
 }
 
 _public_ int sd_device_open(sd_device *device, int flags) {
-        _cleanup_close_ int fd = -1, fd2 = -1;
+        _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
         const char *devname, *subsystem = NULL;
         uint64_t q, diskseq = 0;
         struct stat st;
index 2bb9c287889a1907cbeaf63ea5365b7d00c19ca6..9d5cab75b3a1e77ebc9923c219bb3dca77d68150 100644 (file)
@@ -131,7 +131,7 @@ static void test_sd_device_one(sd_device *d) {
                         assert_se(streq(syspath, val));
                         dev = sd_device_unref(dev);
 
-                        _cleanup_close_ int fd = -1;
+                        _cleanup_close_ int fd = -EBADF;
                         fd = sd_device_open(d, O_CLOEXEC| O_NONBLOCK | (is_block ? O_RDONLY : O_NOCTTY | O_PATH));
                         assert_se(fd >= 0 || ERRNO_IS_PRIVILEGE(fd));
                 } else
index a36eba902932fabdc0ed9590e0b2a885f7327c74..9863b07653f71a005cb6669a753e5d2d88a044d4 100644 (file)
@@ -111,7 +111,7 @@ int event_reset_time_relative(
 
 int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata) {
         _cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(e);
index c936fcb3b64ac8f482ff1d0cdc972731c9cdec87..b9df1c86c364a2d926cdb6a541b593b77ec674f6 100644 (file)
@@ -378,22 +378,22 @@ _public_ int sd_event_new(sd_event** ret) {
 
         *e = (sd_event) {
                 .n_ref = 1,
-                .epoll_fd = -1,
-                .watchdog_fd = -1,
+                .epoll_fd = -EBADF,
+                .watchdog_fd = -EBADF,
                 .realtime.wakeup = WAKEUP_CLOCK_DATA,
-                .realtime.fd = -1,
+                .realtime.fd = -EBADF,
                 .realtime.next = USEC_INFINITY,
                 .boottime.wakeup = WAKEUP_CLOCK_DATA,
-                .boottime.fd = -1,
+                .boottime.fd = -EBADF,
                 .boottime.next = USEC_INFINITY,
                 .monotonic.wakeup = WAKEUP_CLOCK_DATA,
-                .monotonic.fd = -1,
+                .monotonic.fd = -EBADF,
                 .monotonic.next = USEC_INFINITY,
                 .realtime_alarm.wakeup = WAKEUP_CLOCK_DATA,
-                .realtime_alarm.fd = -1,
+                .realtime_alarm.fd = -EBADF,
                 .realtime_alarm.next = USEC_INFINITY,
                 .boottime_alarm.wakeup = WAKEUP_CLOCK_DATA,
-                .boottime_alarm.fd = -1,
+                .boottime_alarm.fd = -EBADF,
                 .boottime_alarm.next = USEC_INFINITY,
                 .perturb = USEC_INFINITY,
                 .original_pid = getpid_cached(),
@@ -643,7 +643,7 @@ static int event_make_signal_data(
 
                 *d = (struct signal_data) {
                         .wakeup = WAKEUP_SIGNAL_DATA,
-                        .fd = -1,
+                        .fd = -EBADF,
                         .priority = priority,
                 };
 
@@ -1180,7 +1180,7 @@ static int event_setup_timer_fd(
         if (_likely_(d->fd >= 0))
                 return 0;
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = timerfd_create(clock, TFD_NONBLOCK|TFD_CLOEXEC);
         if (fd < 0)
@@ -1516,7 +1516,7 @@ _public_ int sd_event_add_child(
                 } else
                         s->child.pidfd_owned = true; /* If we allocate the pidfd we own it by default */
         } else
-                s->child.pidfd = -1;
+                s->child.pidfd = -EBADF;
 
         if (EVENT_SOURCE_WATCH_PIDFD(s)) {
                 /* We have a pidfd and we only want to watch for exit */
@@ -1779,7 +1779,7 @@ static int event_make_inotify_data(
                 int64_t priority,
                 struct inotify_data **ret) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct inotify_data *d;
         int r;
 
@@ -1976,7 +1976,7 @@ static int event_make_inode_data(
                 .dev = dev,
                 .ino = ino,
                 .wd = -1,
-                .fd = -1,
+                .fd = -EBADF,
                 .inotify_data = inotify_data,
         };
 
index 9ec988d76e61e90adb3c667a110e166f1cc4f7b1..8d0cb5861bd8127718632c52190c7d62a6d16e0a 100644 (file)
@@ -225,8 +225,7 @@ static void test_basic_one(bool with_pidfd) {
 
         got_a = false, got_b = false, got_c = false, got_d = 0;
 
-        /* Add a oneshot handler, trigger it, reenable it, and trigger
-         * it again. */
+        /* Add a oneshot handler, trigger it, reenable it, and trigger it again. */
         assert_se(sd_event_add_io(e, &w, d[0], EPOLLIN, io_handler, INT_TO_PTR('d')) >= 0);
         assert_se(sd_event_source_set_enabled(w, SD_EVENT_ONESHOT) >= 0);
         assert_se(write(d[1], &ch, 1) >= 0);
@@ -742,7 +741,7 @@ TEST(inotify_self_destroy) {
         _cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
         _cleanup_(sd_event_unrefp) sd_event *e = NULL;
         char path[] = "/tmp/inotifyXXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         /* Tests that destroying an inotify event source from its own handler is safe */
 
index eae2562410cca074b18d751fcc086a96142556b1..a27f4bf7427d799c024caa4a4c890a25c054d3f2 100644 (file)
@@ -102,7 +102,7 @@ int id128_read_fd(int fd, Id128FormatFlag f, sd_id128_t *ret) {
 }
 
 int id128_read(const char *p, Id128FormatFlag f, sd_id128_t *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY);
         if (fd < 0)
@@ -142,7 +142,7 @@ int id128_write_fd(int fd, Id128FormatFlag f, sd_id128_t id) {
 }
 
 int id128_write(const char *p, Id128FormatFlag f, sd_id128_t id) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(p, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_TRUNC, 0444);
         if (fd < 0)
index b988ee3bba4965b794b729ba664f7ed97194f992..7527abf636cb99756b5fc75f5cec4598b1817f54 100644 (file)
@@ -504,7 +504,7 @@ int catalog_update(const char* database, const char* root, const char* const* di
 }
 
 static int open_mmap(const char *database, int *_fd, struct stat *_st, void **_p) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const CatalogHeader *h;
         struct stat st;
         void *p;
@@ -601,7 +601,7 @@ static const char *find_id(void *p, sd_id128_t id) {
 }
 
 int catalog_get(const char* database, sd_id128_t id, char **_text) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         void *p = NULL;
         struct stat st = {};
         char *text = NULL;
@@ -668,7 +668,7 @@ static void dump_catalog_entry(FILE *f, sd_id128_t id, const char *s, bool oneli
 }
 
 int catalog_list(FILE *f, const char *database, bool oneline) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         void *p = NULL;
         struct stat st;
         const CatalogHeader *h;
index 1cb894338979365d104d0b0775fc1bfa79760eb3..3c5d9d7e4975bb61d224f18e7f03f9d1efee8c00 100644 (file)
@@ -308,7 +308,7 @@ int journal_file_hmac_put_header(JournalFile *f) {
 }
 
 int journal_file_fss_load(JournalFile *f) {
-        int r, fd = -1;
+        int r, fd = -EBADF;
         char *p = NULL;
         struct stat st;
         FSSHeader *m = NULL;
index db53dd7debb9205ac968f194557cf659c21ee93c..3b74d2246e2a2e267f010f92b1a440896ae396af 100644 (file)
@@ -239,7 +239,7 @@ finish:
 _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
         PROTECT_ERRNO;
         int fd, r;
-        _cleanup_close_ int buffer_fd = -1;
+        _cleanup_close_ int buffer_fd = -EBADF;
         struct iovec *w;
         uint64_t *l;
         int i, j = 0;
@@ -419,7 +419,7 @@ _public_ int sd_journal_perror(const char *message) {
 }
 
 _public_ int sd_journal_stream_fd(const char *identifier, int priority, int level_prefix) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char *header;
         size_t l;
         int r;
index 7b5e0fa65fa0ade51eedbef4fd064f0490534433..d62cf3eb3af020ac1b8ee6cadb90b87a66dd96ed 100644 (file)
@@ -85,7 +85,7 @@ static void patch_realtime(
 }
 
 static int journal_file_empty(int dir_fd, const char *name) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
         le64_t n_entries;
         ssize_t n;
index 34b1d8b90934c156a9bbb98e39ddde9ec0311e22..1eca48536cf9023ee2282d2c1d7a96be88cdf858 100644 (file)
@@ -823,7 +823,7 @@ int journal_file_verify(
         bool entry_seqnum_set = false, entry_monotonic_set = false, entry_realtime_set = false, found_main_entry_array = false;
         uint64_t n_objects = 0, n_entries = 0, n_data = 0, n_fields = 0, n_data_hash_tables = 0, n_field_hash_tables = 0, n_entry_arrays = 0, n_tags = 0;
         usec_t last_usec = 0;
-        _cleanup_close_ int data_fd = -1, entry_fd = -1, entry_array_fd = -1;
+        _cleanup_close_ int data_fd = -EBADF, entry_fd = -EBADF, entry_array_fd = -EBADF;
         _cleanup_fclose_ FILE *data_fp = NULL, *entry_fp = NULL, *entry_array_fp = NULL;
         MMapFileDescriptor *cache_data_fd = NULL, *cache_entry_fd = NULL, *cache_entry_array_fd = NULL;
         unsigned i;
index 0f3376823bb0b01e4b010a735dc51d7171a5e624..204886b1e43d2dae289a1b19fbd189fb4c7b5164 100644 (file)
@@ -1266,7 +1266,7 @@ static int add_any_file(
                 int fd,
                 const char *path) {
 
-        _cleanup_close_ int our_fd = -1;
+        _cleanup_close_ int our_fd = -EBADF;
         JournalFile *f;
         struct stat st;
         int r;
@@ -1730,7 +1730,7 @@ static int add_root_directory(sd_journal *j, const char *p, bool missing_ok) {
                         goto fail;
                 }
         } else {
-                _cleanup_close_ int dfd = -1;
+                _cleanup_close_ int dfd = -EBADF;
 
                 /* If there's no path specified, then we use the top-level fd itself. We duplicate the fd here, since
                  * opendir() will take possession of the fd, and close it, which we don't want. */
@@ -1888,8 +1888,8 @@ static sd_journal *journal_new(int flags, const char *path, const char *namespac
                 return NULL;
 
         j->original_pid = getpid_cached();
-        j->toplevel_fd = -1;
-        j->inotify_fd = -1;
+        j->toplevel_fd = -EBADF;
+        j->inotify_fd = -EBADF;
         j->flags = flags;
         j->data_threshold = DEFAULT_DATA_THRESHOLD;
 
index 526b8200ba1897e2c7ced64203f1c6cdd44da70d..49185cc2b32e7967116fa94e14e3e7aaa4007fa9 100644 (file)
@@ -195,7 +195,7 @@ static void test_catalog_file_lang(void) {
 
 int main(int argc, char *argv[]) {
         _cleanup_(unlink_tempfilep) char database[] = "/tmp/test-catalog.XXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *text = NULL;
         int r;
 
index 872d39e9ab79673fb612b3461bb5182ecafe685d..90b5ebb4b7f9a056f898a6c376dd4f912fdaf4e3 100644 (file)
@@ -944,7 +944,7 @@ static sd_login_monitor* FD_TO_MONITOR(int fd) {
 }
 
 _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         bool good = false;
         int k;
 
index af601bd347cbcae618c0115ba9856a61170e0747..6cd916a2097b484f3d6a116d34cf6ca34d1523d2 100644 (file)
@@ -658,7 +658,7 @@ static int socket_open(int family) {
 }
 
 int netlink_open_family(sd_netlink **ret, int family) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         fd = socket_open(family);
index fe888926a1d70b900ec39d09a750a8dd1f87146d..132f63e57decbd021e48037ccfce2d3829cedc2d 100644 (file)
@@ -31,7 +31,7 @@ static int netlink_new(sd_netlink **ret) {
 
         *nl = (sd_netlink) {
                 .n_ref = 1,
-                .fd = -1,
+                .fd = -EBADF,
                 .sockaddr.nl.nl_family = AF_NETLINK,
                 .original_pid = getpid_cached(),
                 .protocol = -1,
@@ -93,7 +93,7 @@ int sd_netlink_open_fd(sd_netlink **ret, int fd) {
 
         r = socket_bind(nl);
         if (r < 0) {
-                nl->fd = -1; /* on failure, the caller remains owner of the fd, hence don't close it here */
+                nl->fd = -EBADF; /* on failure, the caller remains owner of the fd, hence don't close it here */
                 nl->protocol = -1;
                 return r;
         }
index 00687e5cc82dd1886782de2722c32313a56cd3e3..56de3f965c4a05e0a1513cd193f9485137623f86 100644 (file)
@@ -344,7 +344,7 @@ static int monitor_add_inotify_watch(int fd) {
 }
 
 int sd_network_monitor_new(sd_network_monitor **m, const char *category) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int k;
         bool good = false;
 
index 5362ec0fa8441c3954fda5a4edd2e4a54251182f..48a92ac6153ce9b7f5347372e2d7dfcc3114a0b3 100644 (file)
@@ -494,7 +494,7 @@ _public_ int sd_resolve_new(sd_resolve **ret) {
         resolve->original_pid = getpid_cached();
 
         for (i = 0; i < _FD_MAX; i++)
-                resolve->fds[i] = -1;
+                resolve->fds[i] = -EBADF;
 
         if (socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, resolve->fds + REQUEST_RECV_FD) < 0)
                 return -errno;
index 7ca17fa6c39c0a76b4f3f004bcc22fe5b2d8c18c..7c5bb5500c60000526f3fd9575834cd202445efa 100644 (file)
@@ -50,7 +50,7 @@ _public_ struct udev_queue *udev_queue_new(struct udev *udev) {
         *udev_queue = (struct udev_queue) {
                 .udev = udev,
                 .n_ref = 1,
-                .fd = -1,
+                .fd = -EBADF,
         };
 
         return udev_queue;
index 6184d10cde57ad04935e697b7f1d71cf604d3ed2..7cd2fd3e6688b9cdac378140c9cc9628d02bc10a 100644 (file)
@@ -287,7 +287,7 @@ static int run(int argc, char *argv[]) {
                 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
                 _cleanup_strv_free_ char **arguments = NULL;
                 _cleanup_free_ char *w = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 pid_t pid;
 
                 /* Ignore SIGINT and allow the forked process to receive it */
index f16be0f4e1a90ccd8f651ecc8cf17a66aad03142..727dad0b16021a51d715028f4cd383ea7c07263c 100644 (file)
@@ -48,7 +48,7 @@ Button* button_new(Manager *m, const char *name) {
         }
 
         b->manager = m;
-        b->fd = -1;
+        b->fd = -EBADF;
 
         return b;
 }
@@ -463,7 +463,7 @@ static int button_set_mask(const char *name, int fd) {
 }
 
 int button_open(Button *b) {
-        _cleanup_(asynchronous_closep) int fd = -1;
+        _cleanup_(asynchronous_closep) int fd = -EBADF;
         const char *p;
         char name[256];
         int r;
index 02adc81909bf0ba123c92e6d438f03313d85e98f..7d4ff6c98be19d8fdb054a74e421d7d8bce51a5f 100644 (file)
@@ -492,7 +492,7 @@ int config_parse_n_autovts(
 static int vt_is_busy(unsigned vtnr) {
         struct vt_stat vt_stat;
         int r;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(vtnr >= 1);
 
index 2ab26b9c6d4b9280dd7ea29034913fb5d20f526a..7024bba82daddce1d364f2f34a42a41174e4215c 100644 (file)
@@ -3196,7 +3196,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
         _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
         const char *who, *why, *what, *mode;
         _cleanup_free_ char *id = NULL;
-        _cleanup_close_ int fifo_fd = -1;
+        _cleanup_close_ int fifo_fd = -EBADF;
         Manager *m = ASSERT_PTR(userdata);
         InhibitMode mm;
         InhibitWhat w;
index 9cf00a502f95f3acd14ca9db9e3ff315f7887cda..95b11ed9e731796dc5c792be18762f59f6546b4a 100644 (file)
@@ -44,7 +44,7 @@ int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) {
                 .what = _INHIBIT_WHAT_INVALID,
                 .mode = _INHIBIT_MODE_INVALID,
                 .uid = UID_INVALID,
-                .fifo_fd = -1,
+                .fifo_fd = -EBADF,
         };
 
         i->state_file = path_join("/run/systemd/inhibit", id);
@@ -264,7 +264,7 @@ int inhibitor_load(Inhibitor *i) {
         }
 
         if (i->fifo_path) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 /* Let's re-open the FIFO on both sides, and close the writing side right away */
                 fd = inhibitor_create_fifo(i);
index 863b8cc3b48ceb44a6b1ad890405c5a46c384ae0..65323f6c9235c0b337bf629387b137b9741edae0 100644 (file)
@@ -167,7 +167,7 @@ int seat_load(Seat *s) {
 
 static int vt_allocate(unsigned vtnr) {
         char p[sizeof("/dev/tty") + DECIMAL_STR_MAX(unsigned)];
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(vtnr >= 1);
 
index ea4800d82761cb66edc0ddbb345b9cf6e800addf..e3bebc9188be9d5e818149f51b78a5d6f39583de 100644 (file)
@@ -774,7 +774,7 @@ static bool session_ready(Session *s) {
 
 int session_send_create_reply(Session *s, sd_bus_error *error) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *c = NULL;
-        _cleanup_close_ int fifo_fd = -1;
+        _cleanup_close_ int fifo_fd = -EBADF;
         _cleanup_free_ char *p = NULL;
 
         assert(s);
index eccc1aeb5d46b1b026848ff05b548e69fdb7077f..a8b3b48992216fb6b7de4201274a8af4599e9c55 100644 (file)
@@ -333,7 +333,7 @@ int session_device_new(Session *s, dev_t dev, bool open_device, SessionDevice **
 
         sd->session = s;
         sd->dev = dev;
-        sd->fd = -1;
+        sd->fd = -EBADF;
         sd->type = DEVICE_TYPE_UNKNOWN;
 
         r = session_device_verify(sd);
index 85cb4eba9eadc90808a2bc0e870337417b59e1c1..2a121faea59527a8506c7e118e7bb35c2fdf7364 100644 (file)
@@ -61,8 +61,8 @@ int session_new(Session **ret, Manager *m, const char *id) {
 
         *s = (Session) {
                 .manager = m,
-                .fifo_fd = -1,
-                .vtfd = -1,
+                .fifo_fd = -EBADF,
+                .vtfd = -EBADF,
                 .audit_id = AUDIT_SESSION_INVALID,
                 .tty_validity = _TTY_VALIDITY_INVALID,
         };
index a564f94bfe918c839b9ad98f13378a20dbf9d01b..def2f5a44286f3b4d2fc6629507659f9c53b92fc 100644 (file)
@@ -53,8 +53,8 @@ static int manager_new(Manager **ret) {
                 return -ENOMEM;
 
         *m = (Manager) {
-                .console_active_fd = -1,
-                .reserve_vt_fd = -1,
+                .console_active_fd = -EBADF,
+                .reserve_vt_fd = -EBADF,
                 .enable_wall_messages = true,
                 .idle_action_not_before_usec = now(CLOCK_MONOTONIC),
         };
@@ -701,7 +701,7 @@ static int manager_vt_switch(sd_event_source *src, const struct signalfd_siginfo
 
         active = m->seat0->active;
         if (!active || active->vtnr < 1) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 int r;
 
                 /* We are requested to acknowledge the VT-switch signal by the kernel but
index a288b3602a963b7360f3cc1090974d234aede326..ba2fca32c6b4669ebca8f26f8be640f5e05c190f 100644 (file)
@@ -188,7 +188,7 @@ static int socket_from_display(const char *display) {
         char *c;
         union sockaddr_union sa;
         socklen_t sa_len;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(display);
@@ -236,7 +236,7 @@ static int socket_from_display(const char *display) {
 
 static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) {
         _cleanup_free_ char *sys_path = NULL, *tty = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct ucred ucred;
         int v, r;
         dev_t display_ctty;
@@ -671,7 +671,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                 *memory_max = NULL, *tasks_max = NULL, *cpu_weight = NULL, *io_weight = NULL, *runtime_max_sec = NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
         _cleanup_(user_record_unrefp) UserRecord *ur = NULL;
-        int session_fd = -1, existing, r;
+        int session_fd = -EBADF, existing, r;
         bool debug = false, remote;
         uint32_t vtnr = 0;
         uid_t original_uid;
index 84dc95eca13c4e4e3eeabf5c07d5b572c912bac7..698052dd8660f106254daa4d68eb68908145f4cf 100644 (file)
@@ -88,7 +88,7 @@ int bus_image_method_remove(
                 return r;
         }
 
-        errno_pipe_fd[0] = -1;
+        errno_pipe_fd[0] = -EBADF;
 
         return 1;
 }
@@ -211,7 +211,7 @@ int bus_image_method_clone(
                 return r;
         }
 
-        errno_pipe_fd[0] = -1;
+        errno_pipe_fd[0] = -EBADF;
 
         return 1;
 }
index 75f397dd6bac8ee27f9d9c6389b7a6968fc1eb54..26ba5d4292193566647addaa65e4d979a1a06355 100644 (file)
@@ -225,7 +225,7 @@ int bus_machine_method_get_addresses(sd_bus_message *message, void *userdata, sd
         case MACHINE_CONTAINER: {
                 _cleanup_close_pair_ int pair[2] = { -1, -1 };
                 _cleanup_free_ char *us = NULL, *them = NULL;
-                _cleanup_close_ int netns_fd = -1;
+                _cleanup_close_ int netns_fd = -EBADF;
                 const char *p;
                 pid_t child;
 
@@ -370,7 +370,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
                 break;
 
         case MACHINE_CONTAINER: {
-                _cleanup_close_ int mntns_fd = -1, root_fd = -1, pidns_fd = -1;
+                _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF;
                 _cleanup_close_pair_ int pair[2] = { -1, -1 };
                 _cleanup_fclose_ FILE *f = NULL;
                 pid_t child;
@@ -388,7 +388,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
                 if (r < 0)
                         return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m");
                 if (r == 0) {
-                        int fd = -1;
+                        int fd = -EBADF;
 
                         pair[0] = safe_close(pair[0]);
 
@@ -890,7 +890,7 @@ int bus_machine_method_copy(sd_bus_message *message, void *userdata, sd_bus_erro
         const char *src, *dest, *host_path, *container_path;
         _cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
         CopyFlags copy_flags = COPY_REFLINK|COPY_MERGE|COPY_HARDLINKS;
-        _cleanup_close_ int hostfd = -1;
+        _cleanup_close_ int hostfd = -EBADF;
         Machine *m = ASSERT_PTR(userdata);
         bool copy_from;
         pid_t child;
@@ -1042,13 +1042,13 @@ int bus_machine_method_copy(sd_bus_message *message, void *userdata, sd_bus_erro
                 (void) sigkill_wait(child);
                 return r;
         }
-        errno_pipe_fd[0] = -1;
+        errno_pipe_fd[0] = -EBADF;
 
         return 1;
 }
 
 int bus_machine_method_open_root_directory(sd_bus_message *message, void *userdata, sd_bus_error *error) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         Machine *m = ASSERT_PTR(userdata);
         int r;
 
@@ -1084,7 +1084,7 @@ int bus_machine_method_open_root_directory(sd_bus_message *message, void *userda
                 break;
 
         case MACHINE_CONTAINER: {
-                _cleanup_close_ int mntns_fd = -1, root_fd = -1;
+                _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF;
                 _cleanup_close_pair_ int pair[2] = { -1, -1 };
                 pid_t child;
 
@@ -1100,7 +1100,7 @@ int bus_machine_method_open_root_directory(sd_bus_message *message, void *userda
                 if (r < 0)
                         return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m");
                 if (r == 0) {
-                        _cleanup_close_ int dfd = -1;
+                        _cleanup_close_ int dfd = -EBADF;
 
                         pair[0] = safe_close(pair[0]);
 
index 93761a1da9bdff993b5a7a25f8c347025246d7c2..149b5d8e60976a585c29546220dbe299ebaedc1f 100644 (file)
@@ -1800,7 +1800,7 @@ static int import_tar(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
         _cleanup_free_ char *ll = NULL, *fn = NULL;
         const char *local = NULL, *path = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         sd_bus *bus = ASSERT_PTR(userdata);
         int r;
 
@@ -1861,7 +1861,7 @@ static int import_raw(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
         _cleanup_free_ char *ll = NULL, *fn = NULL;
         const char *local = NULL, *path = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         sd_bus *bus = ASSERT_PTR(userdata);
         int r;
 
@@ -1922,7 +1922,7 @@ static int import_fs(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
         const char *local = NULL, *path = NULL;
         _cleanup_free_ char *fn = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         sd_bus *bus = ASSERT_PTR(userdata);
         int r;
 
@@ -1987,7 +1987,7 @@ static void determine_compression_from_filename(const char *p) {
 
 static int export_tar(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *local = NULL, *path = NULL;
         sd_bus *bus = ASSERT_PTR(userdata);
         int r;
@@ -2027,7 +2027,7 @@ static int export_tar(int argc, char *argv[], void *userdata) {
 
 static int export_raw(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *local = NULL, *path = NULL;
         sd_bus *bus = ASSERT_PTR(userdata);
         int r;
index 3da639279d8c74c64b85972ee745a4653b876462..aef3e905426ff514879c7c7c8096c665e1e4e282 100644 (file)
@@ -44,7 +44,7 @@ static int property_get_pool_usage(
                 void *userdata,
                 sd_bus_error *error) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         uint64_t usage = UINT64_MAX;
 
         assert(bus);
@@ -70,7 +70,7 @@ static int property_get_pool_limit(
                 void *userdata,
                 sd_bus_error *error) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         uint64_t size = UINT64_MAX;
 
         assert(bus);
@@ -684,7 +684,7 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err
         } mode;
 
         _cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
-        _cleanup_close_ int result_fd = -1;
+        _cleanup_close_ int result_fd = -EBADF;
         Manager *m = userdata;
         Operation *operation;
         const char *mm;
@@ -824,8 +824,8 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err
         operation->extra_fd = result_fd;
         operation->done = clean_pool_done;
 
-        result_fd = -1;
-        errno_pipe_fd[0] = -1;
+        result_fd = -EBADF;
+        errno_pipe_fd[0] = -EBADF;
 
         return 1;
 }
index c97b29aba830f6782e2157c2d8b0fe64a254b644..49b6d31bdc0f8c0fdf8151e1d7a6801da31eeea3 100644 (file)
@@ -81,7 +81,7 @@ int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_messag
         if (!o)
                 return -ENOMEM;
 
-        o->extra_fd = -1;
+        o->extra_fd = -EBADF;
 
         r = sd_event_add_child(manager->event, &o->event_source, child, WEXITED, operation_done, o);
         if (r < 0) {
index 39ea7c1d739e6c1579134caf9980d4cc2b9d9cf1..1a37ba34652e3a92ddd145210da4202f8dbdc4ee 100644 (file)
@@ -101,7 +101,7 @@ static int tuntap_take_fd(NetDev *netdev) {
 }
 
 static int netdev_create_tuntap(NetDev *netdev) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct ifreq ifr = {};
         TunTap *t;
         int r;
@@ -180,7 +180,7 @@ static void tuntap_init(NetDev *netdev) {
         t = TUNTAP(netdev);
         assert(t);
 
-        t->fd = -1;
+        t->fd = -EBADF;
 }
 
 static void tuntap_drop(NetDev *netdev) {
index 8146125fc8a44b365aafc7e5ed53f03dbdd82427..357d38f5ea64518765aed3d93fd4b8987859fe8b 100644 (file)
@@ -711,7 +711,7 @@ static void acquire_wlan_link_info(LinkInfo *link) {
 static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, LinkInfo **ret) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
         _cleanup_(link_info_array_freep) LinkInfo *links = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         size_t c = 0;
         int r;
 
index f3ebeadd2cd8c5add0aa27c42ecddbf66d2177d9..7d067a8c46bfbe5e21248c557aa11fb3602a9512 100644 (file)
@@ -235,7 +235,7 @@ static int manager_connect_udev(Manager *m) {
 
 static int manager_listen_fds(Manager *m, int *ret_rtnl_fd) {
         _cleanup_strv_free_ char **names = NULL;
-        int n, rtnl_fd = -1;
+        int n, rtnl_fd = -EBADF;
 
         assert(m);
         assert(ret_rtnl_fd);
@@ -499,7 +499,7 @@ static int manager_set_keep_configuration(Manager *m) {
 }
 
 int manager_setup(Manager *m) {
-        _cleanup_close_ int rtnl_fd = -1;
+        _cleanup_close_ int rtnl_fd = -EBADF;
         int r;
 
         assert(m);
@@ -583,7 +583,7 @@ int manager_new(Manager **ret, bool test_mode) {
                 .online_state = _LINK_ONLINE_STATE_INVALID,
                 .manage_foreign_routes = true,
                 .manage_foreign_rules = true,
-                .ethtool_fd = -1,
+                .ethtool_fd = -EBADF,
                 .dhcp_duid.type = DUID_TYPE_EN,
                 .dhcp6_duid.type = DUID_TYPE_EN,
                 .duid_product_uuid.type = DUID_TYPE_UUID,
index d7ca3afc8aca9ca532474aa0c267849bec7d4df1..0deb4ebb304b90285675babf46d5ed8423e47abe 100644 (file)
@@ -20,7 +20,7 @@
 #include "user-util.h"
 
 static int chown_cgroup_path(const char *path, uid_t uid_shift) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
         if (fd < 0)
index a8b1437171161d46055e0288a7bcf9d91196bb2e..b35f8b6a9ba2698a82cbcdb3f122bf8a0fe449b8 100644 (file)
@@ -160,7 +160,7 @@ int expose_port_execute(sd_netlink *rtnl, FirewallContext **fw_ctx, ExposePort *
 }
 
 int expose_port_send_rtnl(int send_fd) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(send_fd >= 0);
index 1535d19bbb62eb018028b638ebab26fc6afaf559..9f369315810590028b17cc7cfd2dd2c49b53825e 100644 (file)
@@ -28,7 +28,7 @@ static int get_acl(int fd, const char *name, acl_type_t type, acl_t *ret) {
         assert(ret);
 
         if (name) {
-                _cleanup_close_ int child_fd = -1;
+                _cleanup_close_ int child_fd = -EBADF;
 
                 child_fd = openat(fd, name, O_PATH|O_CLOEXEC|O_NOFOLLOW);
                 if (child_fd < 0)
@@ -53,7 +53,7 @@ static int set_acl(int fd, const char *name, acl_type_t type, acl_t acl) {
         assert(acl);
 
         if (name) {
-                _cleanup_close_ int child_fd = -1;
+                _cleanup_close_ int child_fd = -EBADF;
 
                 child_fd = openat(fd, name, O_PATH|O_CLOEXEC|O_NOFOLLOW);
                 if (child_fd < 0)
index 54f56725a8573d2bf8a126a1856e7e88a9d8b44f..a91ab9f25ecf04a4342a8bd93211bec18b593895 100644 (file)
@@ -93,7 +93,7 @@ int change_uid_gid(const char *user, bool chown_stdio, char **ret_home) {
         _cleanup_free_ gid_t *gids = NULL;
         _cleanup_free_ char *home = NULL, *line = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         unsigned n_gids = 0;
         uid_t uid;
         gid_t gid;
index a1bf5bb1d19bc8841c8aca98b44022c388432d37..de3e95145b6ae0cb3c90e4619fc6033e7ca909c0 100644 (file)
@@ -2459,7 +2459,7 @@ static int setup_credentials(const char *root) {
 
         for (size_t i = 0; i < arg_n_credentials; i++) {
                 _cleanup_free_ char *j = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 j = path_join(q, arg_credentials[i].id);
                 if (!j)
@@ -2500,7 +2500,7 @@ static int setup_credentials(const char *root) {
 static int setup_kmsg(int fd_inner_socket) {
         _cleanup_(unlink_and_freep) char *from = NULL;
         _cleanup_free_ char *fifo = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(fd_inner_socket >= 0);
@@ -3590,7 +3590,7 @@ static int inner_child(
 }
 
 static int setup_notify_child(void) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         static const union sockaddr_union sa = {
                 .un.sun_family = AF_UNIX,
                 .un.sun_path = NSPAWN_NOTIFY_SOCKET_PATH,
@@ -3631,7 +3631,7 @@ static int outer_child(
 
         _cleanup_(bind_user_context_freep) BindUserContext *bind_user_context = NULL;
         _cleanup_strv_free_ char **os_release_pairs = NULL;
-        _cleanup_close_ int fd = -1, mntns_fd = -EBADF;
+        _cleanup_close_ int fd = -EBADF, mntns_fd = -EBADF;
         bool idmap = false;
         const char *p;
         pid_t pid;
@@ -4760,7 +4760,7 @@ static int run_container(
         int ifi = 0, r;
         ssize_t l;
         sigset_t mask_chld;
-        _cleanup_close_ int child_netns_fd = -1;
+        _cleanup_close_ int child_netns_fd = -EBADF;
 
         assert_se(sigemptyset(&mask_chld) == 0);
         assert_se(sigaddset(&mask_chld, SIGCHLD) == 0);
@@ -5168,7 +5168,7 @@ static int run_container(
         }
 
         if (arg_console_mode != CONSOLE_PIPE) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 PTYForwardFlags flags = 0;
 
                 /* Retrieve the master pty allocated by inner child */
@@ -5236,7 +5236,7 @@ static int run_container(
                         return r;
 
                 if (r == 0) {
-                        _cleanup_close_ int parent_netns_fd = -1;
+                        _cleanup_close_ int parent_netns_fd = -EBADF;
 
                         r = namespace_open(getpid(), NULL, NULL, &parent_netns_fd, NULL, NULL);
                         if (r < 0) {
@@ -5373,7 +5373,7 @@ static int initialize_rlimits(void) {
 }
 
 static int cant_be_in_netns(void) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct ucred ucred;
         int r;
 
index e527abf5da294b6baaced427cb94b11a2eabbef5..d18f999841002996fdb996673eeb671acbfcafd2 100644 (file)
@@ -46,7 +46,7 @@ static int dump_state(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
-        int fd = -1;
+        int fd = -EBADF;
         int r;
 
         r = sd_bus_open_system(&bus);
index 3a3308f0c48a4dd73ec938bfd8246686ffff8803..0581d58016a4c5eab50a58b90873ecd86e1b7cec 100644 (file)
@@ -12,7 +12,7 @@
 
 static int bus_method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         _cleanup_free_ char *dump = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         Manager *m = ASSERT_PTR(userdata);
         int r;
 
index faa75c55788f874f4adc7576c0fae232cfe4da5e..ed98812399132306b0de5f255ca0e52ce079715b 100644 (file)
@@ -205,7 +205,7 @@ static void test_oomd_update_cgroup_contexts_between_hashmaps(void) {
 
 static void test_oomd_system_context_acquire(void) {
         _cleanup_(unlink_tempfilep) char path[] = "/oomdgetsysctxtestXXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         OomdSystemContext ctx;
 
         if (geteuid() != 0)
index bb2b53103ff6e2586d8bee53d04b07c2d4d23a37..248746f7247678b7cf82f02adfe7a4fc8b947368 100644 (file)
@@ -37,7 +37,7 @@ static bool arg_dry_run = false;
 static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_devno) {
         _cleanup_free_ char *devpath = NULL, *main_devpath = NULL;
         _cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
-        _cleanup_close_ int main_devfd = -1;
+        _cleanup_close_ int main_devfd = -EBADF;
         uint64_t size;
         int r;
 
@@ -206,7 +206,7 @@ static int parse_argv(int argc, char *argv[]) {
 }
 
 static int run(int argc, char *argv[]) {
-        _cleanup_close_ int mountfd = -1, devfd = -1;
+        _cleanup_close_ int mountfd = -EBADF, devfd = -EBADF;
         _cleanup_free_ char *devpath = NULL;
         uint64_t size, newsize;
         dev_t devno;
index 9ffdcb6db85eca03288e65e382177e076b9fa837..3f54bbb0da0a9a2a0739e0295f0f3185616705f1 100644 (file)
@@ -19,7 +19,7 @@
 
 static int run(int argc, char *argv[]) {
         _cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL;
-        _cleanup_close_ int lock_fd = -1;
+        _cleanup_close_ int lock_fd = -EBADF;
         sd_id128_t uuid;
         struct stat st;
         int r;
index 010d775c0b61c53cd97a38dfda6f003939615b99..71018a79cc861834e2810b531572e3f492e03cf3 100644 (file)
@@ -336,7 +336,7 @@ static Partition *partition_new(void) {
                 .padding_max = UINT64_MAX,
                 .partno = UINT64_MAX,
                 .offset = UINT64_MAX,
-                .copy_blocks_fd = -1,
+                .copy_blocks_fd = -EBADF,
                 .copy_blocks_size = UINT64_MAX,
                 .no_auto = -1,
                 .read_only = -1,
@@ -3079,7 +3079,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(PartitionTarget*, partition_target_free);
 
 static int prepare_temporary_file(PartitionTarget *t, uint64_t size) {
         _cleanup_(unlink_and_freep) char *temp = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *vt;
         int r;
 
@@ -3128,8 +3128,8 @@ static int partition_target_prepare(
         if (!t)
                 return log_oom();
         *t = (PartitionTarget) {
-                .fd = -1,
-                .whole_fd = -1,
+                .fd = -EBADF,
+                .whole_fd = -EBADF,
         };
 
         if (!need_path) {
@@ -3736,7 +3736,7 @@ static int do_copy_files(
         assert(root);
 
         STRV_FOREACH_PAIR(source, target, p->copy_files) {
-                _cleanup_close_ int sfd = -1, pfd = -1, tfd = -1;
+                _cleanup_close_ int sfd = -EBADF, pfd = -EBADF, tfd = -EBADF;
 
                 sfd = chase_symlinks_and_open(*source, arg_root, CHASE_PREFIX_ROOT, O_CLOEXEC|O_NOCTTY, NULL);
                 if (sfd < 0)
@@ -3858,7 +3858,7 @@ static bool partition_needs_populate(Partition *p) {
 
 static int partition_populate_directory(Partition *p, const Set *denylist, char **ret) {
         _cleanup_(rm_rf_physical_and_freep) char *root = NULL;
-        _cleanup_close_ int rfd = -1;
+        _cleanup_close_ int rfd = -EBADF;
         int r;
 
         assert(ret);
@@ -4627,7 +4627,7 @@ static int split_name_resolve(Context *context) {
 }
 
 static int context_split(Context *context) {
-        int fd = -1, r;
+        int fd = -EBADF, r;
 
         if (!arg_split)
                 return 0;
@@ -4642,7 +4642,7 @@ static int context_split(Context *context) {
                 return r;
 
         LIST_FOREACH(partitions, p, context->partitions) {
-                _cleanup_close_ int fdt = -1;
+                _cleanup_close_ int fdt = -EBADF;
 
                 if (p->dropped)
                         continue;
@@ -4766,7 +4766,7 @@ static int context_read_seed(Context *context, const char *root) {
                 return 0;
 
         if (!arg_randomize) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 fd = chase_symlinks_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC, NULL);
                 if (fd == -ENOENT)
@@ -4856,7 +4856,7 @@ static int resolve_copy_blocks_auto_candidate(
                 sd_id128_t *ret_uuid) {
 
         _cleanup_(blkid_free_probep) blkid_probe b = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *p = NULL;
         const char *pttype, *t;
         sd_id128_t pt_parsed, u;
@@ -5141,7 +5141,7 @@ static int context_open_copy_block_paths(
         assert(context);
 
         LIST_FOREACH(partitions, p, context->partitions) {
-                _cleanup_close_ int source_fd = -1;
+                _cleanup_close_ int source_fd = -EBADF;
                 _cleanup_free_ char *opened = NULL;
                 sd_id128_t uuid = SD_ID128_NULL;
                 uint64_t size;
@@ -5302,7 +5302,7 @@ static int context_minimize(Context *context) {
                 _cleanup_(rm_rf_physical_and_freep) char *root = NULL;
                 _cleanup_(unlink_and_freep) char *temp = NULL;
                 _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 sd_id128_t fs_uuid;
                 uint64_t fsz;
 
@@ -6005,7 +6005,7 @@ static int acquire_root_devno(
 
         _cleanup_free_ char *found_path = NULL;
         dev_t devno, fd_devno = MODE_INVALID;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
         int r;
 
@@ -6076,7 +6076,7 @@ static int find_root(Context *context) {
 
         if (arg_node) {
                 if (arg_empty == EMPTY_CREATE) {
-                        _cleanup_close_ int fd = -1;
+                        _cleanup_close_ int fd = -EBADF;
                         _cleanup_free_ char *s = NULL;
 
                         s = strdup(arg_node);
@@ -6176,7 +6176,7 @@ static int resize_backing_fd(
                 const char *backing_file,   /* If the above refers to a loopback device, the backing regular file for that, which we can grow */
                 LoopDevice *loop_device) {
 
-        _cleanup_close_ int writable_fd = -1;
+        _cleanup_close_ int writable_fd = -EBADF;
         uint64_t current_size;
         struct stat st;
         int r;
index 0909e14aab664885853b6ba93c4540ac6e5b6651..45dd70b13d7256fe59a3c35bd19457aaf9d900c9 100644 (file)
@@ -150,7 +150,7 @@ static int send_one_fd_iov_with_data_fd(
                 size_t iovlen,
                 int fd) {
 
-        _cleanup_close_ int data_fd = -1;
+        _cleanup_close_ int data_fd = -EBADF;
 
         assert(iov || iovlen == 0);
         assert(socket_fd >= 0);
@@ -179,7 +179,7 @@ static int extract_now(
         _cleanup_hashmap_free_ Hashmap *unit_files = NULL;
         _cleanup_(portable_metadata_unrefp) PortableMetadata *os_release = NULL;
         _cleanup_(lookup_paths_free) LookupPaths paths = {};
-        _cleanup_close_ int os_release_fd = -1;
+        _cleanup_close_ int os_release_fd = -EBADF;
         _cleanup_free_ char *os_release_path = NULL;
         const char *os_release_id;
         int r;
@@ -224,7 +224,7 @@ static int extract_now(
                         if (!os_release)
                                 return -ENOMEM;
 
-                        os_release_fd = -1;
+                        os_release_fd = -EBADF;
                         os_release->source = TAKE_PTR(os_release_path);
                 }
         }
@@ -253,7 +253,7 @@ static int extract_now(
                 FOREACH_DIRENT(de, d, return log_debug_errno(errno, "Failed to read directory: %m")) {
                         _cleanup_(portable_metadata_unrefp) PortableMetadata *m = NULL;
                         _cleanup_(mac_selinux_freep) char *con = NULL;
-                        _cleanup_close_ int fd = -1;
+                        _cleanup_close_ int fd = -EBADF;
 
                         if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
                                 continue;
@@ -298,7 +298,7 @@ static int extract_now(
                         m = portable_metadata_new(de->d_name, where, con, fd);
                         if (!m)
                                 return -ENOMEM;
-                        fd = -1;
+                        fd = -EBADF;
 
                         m->source = path_join(resolved, de->d_name);
                         if (!m->source)
@@ -428,7 +428,7 @@ static int portable_extract_by_path(
 
                 for (;;) {
                         _cleanup_(portable_metadata_unrefp) PortableMetadata *add = NULL;
-                        _cleanup_close_ int fd = -1;
+                        _cleanup_close_ int fd = -EBADF;
                         /* We use NAME_MAX space for the SELinux label here. The kernel currently enforces no limit, but
                          * according to suggestions from the SELinux people this will change and it will probably be
                          * identical to NAME_MAX. For now we use that, but this should be updated one day when the final
@@ -461,7 +461,7 @@ static int portable_extract_by_path(
                         add = portable_metadata_new(iov_buffer, path, selinux_label, fd);
                         if (!add)
                                 return -ENOMEM;
-                        fd = -1;
+                        fd = -EBADF;
 
                         /* Note that we do not initialize 'add->source' here, as the source path is not usable here as
                          * it refers to a path only valid in the short-living namespaced child process we forked
@@ -594,7 +594,7 @@ static int extract_image_and_extensions(
                 _cleanup_(portable_metadata_unrefp) PortableMetadata *extension_release_meta = NULL;
                 _cleanup_hashmap_free_ Hashmap *extra_unit_files = NULL;
                 _cleanup_strv_free_ char **extension_release = NULL;
-                _cleanup_close_ int extension_release_fd = -1;
+                _cleanup_close_ int extension_release_fd = -EBADF;
                 _cleanup_fclose_ FILE *f = NULL;
                 const char *e;
 
@@ -1172,7 +1172,7 @@ static int attach_unit_file(
 
         } else {
                 _cleanup_(unlink_and_freep) char *tmp = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 (void) mac_selinux_create_file_prepare_label(path, m->selinux_label);
 
@@ -1502,7 +1502,7 @@ static int test_chroot_dropin(
 
         _cleanup_free_ char *line = NULL, *marker = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *p, *e, *k;
         int r;
 
index be321b8f0317ca210d2f271f71687e8073001e64..768964231a16e99494b40fff2cca6fd1ac1265a8 100644 (file)
@@ -41,7 +41,7 @@ static int property_get_pool_usage(
                 void *userdata,
                 sd_bus_error *error) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         uint64_t usage = UINT64_MAX;
 
         assert(bus);
@@ -67,7 +67,7 @@ static int property_get_pool_limit(
                 void *userdata,
                 sd_bus_error *error) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         uint64_t size = UINT64_MAX;
 
         assert(bus);
index b108fd34af6c74fcf384537230173ed30f09abe2..704b51d81d86a38954d4ad65235cabdae340909c 100644 (file)
@@ -553,7 +553,7 @@ int bus_image_common_remove(
                 return r;
 
         child = 0;
-        errno_pipe_fd[0] = -1;
+        errno_pipe_fd[0] = -EBADF;
 
         return 1;
 }
index 26adb9091a6368fdb7d742637da982b2de550e2a..6897ed0b2809bcc8b2abacf967e910e021c8bacb 100644 (file)
@@ -80,7 +80,7 @@ int operation_new(Manager *manager, pid_t child, sd_bus_message *message, int er
         if (!o)
                 return -ENOMEM;
 
-        o->extra_fd = -1;
+        o->extra_fd = -EBADF;
 
         r = sd_event_add_child(manager->event, &o->event_source, child, WEXITED, operation_done, o);
         if (r < 0) {
index 6c3d5775077a07e8a1134397a5b23b8c1b4e960b..306540650fd6fa10c62ab2003678071241231160 100644 (file)
@@ -174,7 +174,7 @@ static int move_file(PStoreEntry *pe, const char *subdir1, const char *subdir2)
 static int append_dmesg(PStoreEntry *pe, const char *subdir1, const char *subdir2) {
         /* Append dmesg chunk to end, create if needed */
         _cleanup_free_ char *ofd_path = NULL;
-        _cleanup_close_ int ofd = -1;
+        _cleanup_close_ int ofd = -EBADF;
         ssize_t wr;
 
         assert(pe);
index 020840e0dfdaf84173133dfae98375ec1a8b61f0..90890e33f291e41655b334a0b2bf6139b1f0cf09 100644 (file)
@@ -320,7 +320,7 @@ static int refresh_boot_seed(void) {
         struct sha256_ctx hash_state;
         _cleanup_free_ void *seed_file_bytes = NULL;
         _cleanup_free_ char *esp_path = NULL;
-        _cleanup_close_ int seed_fd = -1, dir_fd = -1;
+        _cleanup_close_ int seed_fd = -EBADF, dir_fd = -EBADF;
         size_t len;
         ssize_t n;
         int r;
@@ -485,7 +485,7 @@ static int parse_argv(int argc, char *argv[]) {
 
 static int run(int argc, char *argv[]) {
         _cleanup_free_ struct sha256_ctx *hash_state = NULL;
-        _cleanup_close_ int seed_fd = -1, random_fd = -1;
+        _cleanup_close_ int seed_fd = -EBADF, random_fd = -EBADF;
         bool read_seed_file, write_seed_file, synchronous;
         size_t seed_size;
         int r;
index feb1d1ef7c48efd4012675b9937976d52ec1b3a1..ce4582afe8634418f6c402837115b02269d472d0 100644 (file)
@@ -34,7 +34,7 @@ static int send_on_socket(int fd, const char *socket_name, const void *packet, s
 
 static int run(int argc, char *argv[]) {
         _cleanup_(erase_and_freep) char *packet = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         size_t length = 0;
         int r;
 
index 635763954be360677f451a156a388aa73d7225fd..0c062efc985c0c8ca0bf27bb5392df04823d92ab 100644 (file)
@@ -351,7 +351,7 @@ static int dns_scope_socket(
                 uint16_t port,
                 union sockaddr_union *ret_socket_address) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union sockaddr_union sa;
         socklen_t salen;
         int r, ifindex;
index 95fbb56cd7af324d61c0cac2f0968b8b955f9944..0a10a0d17e50ca98e04e0d1fb6534fc27437e323 100644 (file)
@@ -523,7 +523,7 @@ int dns_stream_new(
 
         *s = (DnsStream) {
                 .n_ref = 1,
-                .fd = -1,
+                .fd = -EBADF,
                 .protocol = protocol,
                 .type = type,
         };
index 8a8a0b19eee53f561388214c9c68c0512edfbf68..facd95aeb8ae9dfde1886aa9db9030a17f5762ff 100644 (file)
@@ -1138,7 +1138,7 @@ static int manager_dns_stub_fd(
                 int type) {
 
         sd_event_source **event_source;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union sockaddr_union sa;
         int r;
 
@@ -1225,7 +1225,7 @@ static int manager_dns_stub_fd(
 
 static int manager_dns_stub_fd_extra(Manager *m, DnsStubListenerExtra *l, int type) {
         _cleanup_free_ char *pretty = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union sockaddr_union sa;
         int r;
 
index 0212569fb030ef2b61fe7683f59fae246949bdc6..8d76630adb686ad867e342432a206720856cbd8c 100644 (file)
@@ -273,7 +273,7 @@ int dns_transaction_new(
                 return -ENOMEM;
 
         *t = (DnsTransaction) {
-                .dns_udp_fd = -1,
+                .dns_udp_fd = -EBADF,
                 .answer_source = _DNS_TRANSACTION_SOURCE_INVALID,
                 .answer_dnssec_result = _DNSSEC_RESULT_INVALID,
                 .answer_nsec_ttl = UINT32_MAX,
@@ -669,7 +669,7 @@ static uint16_t dns_transaction_port(DnsTransaction *t) {
 static int dns_transaction_emit_tcp(DnsTransaction *t) {
         usec_t stream_timeout_usec = DNS_STREAM_DEFAULT_TIMEOUT_USEC;
         _cleanup_(dns_stream_unrefp) DnsStream *s = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union sockaddr_union sa;
         DnsStreamType type;
         int r;
@@ -753,7 +753,7 @@ static int dns_transaction_emit_tcp(DnsTransaction *t) {
                 if (r < 0)
                         return r;
 
-                fd = -1;
+                fd = -EBADF;
 
 #if ENABLE_DNS_OVER_TLS
                 if (t->scope->protocol == DNS_PROTOCOL_DNS &&
index 1c9048670bf0e4cede5fe03ab85e88e1c775f0f6..6c6c98566f1b28ad07b925e5d14faaea772eae32 100644 (file)
@@ -554,13 +554,13 @@ int manager_new(Manager **ret) {
                 return -ENOMEM;
 
         *m = (Manager) {
-                .llmnr_ipv4_udp_fd = -1,
-                .llmnr_ipv6_udp_fd = -1,
-                .llmnr_ipv4_tcp_fd = -1,
-                .llmnr_ipv6_tcp_fd = -1,
-                .mdns_ipv4_fd = -1,
-                .mdns_ipv6_fd = -1,
-                .hostname_fd = -1,
+                .llmnr_ipv4_udp_fd = -EBADF,
+                .llmnr_ipv6_udp_fd = -EBADF,
+                .llmnr_ipv4_tcp_fd = -EBADF,
+                .llmnr_ipv6_tcp_fd = -EBADF,
+                .mdns_ipv4_fd = -EBADF,
+                .mdns_ipv6_fd = -EBADF,
+                .hostname_fd = -EBADF,
 
                 .llmnr_support = DEFAULT_LLMNR_MODE,
                 .mdns_support = DEFAULT_MDNS_MODE,
index 96395ad27a71a50a4b0d0a669d7216d3c60f9f31..c708eb4da8de7b943a6567a02960e67da4e8ccfb 100644 (file)
@@ -107,7 +107,7 @@ static void server_handle(int fd) {
 }
 
 static void *tcp_dns_server(void *p) {
-        _cleanup_close_ int bindfd = -1, acceptfd = -1;
+        _cleanup_close_ int bindfd = -EBADF, acceptfd = -EBADF;
 
         assert_se((bindfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)) >= 0);
         assert_se(setsockopt(bindfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) >= 0);
@@ -125,7 +125,7 @@ static void *tcp_dns_server(void *p) {
 static void *tls_dns_server(void *p) {
         pid_t openssl_pid;
         int r;
-        _cleanup_close_ int fd_server = -1, fd_tls = -1;
+        _cleanup_close_ int fd_server = -EBADF, fd_tls = -EBADF;
         _cleanup_free_ char *cert_path = NULL, *key_path = NULL;
         _cleanup_free_ char *bind_str = NULL;
 
@@ -213,7 +213,7 @@ static void test_dns_stream(bool tls) {
         Manager manager = {};
          _cleanup_(dns_stream_unrefp) DnsStream *stream = NULL;
         _cleanup_(sd_event_unrefp) sd_event *event = NULL;
-        _cleanup_close_ int clientfd = -1;
+        _cleanup_close_ int clientfd = -EBADF;
         int r;
 
         void *(*server_entrypoint)(void *);
@@ -331,7 +331,7 @@ static void test_dns_stream(bool tls) {
 }
 
 static void try_isolate_network(void) {
-        _cleanup_close_ int socket_fd = -1;
+        _cleanup_close_ int socket_fd = -EBADF;
         int r;
 
         /* First test if CLONE_NEWUSER/CLONE_NEWNET can actually work for us, i.e. we can open the namespaces
index 9f77997d5a59843a2e87449a68cbb70b8654f9f9..22a36bdd2432bd073b94d282a259844cf898486c 100644 (file)
@@ -100,7 +100,7 @@ int acpi_get_boot_usec(usec_t *ret_loader_start, usec_t *ret_loader_exit) {
         struct acpi_fpdt_header *rec;
         int r;
         uint64_t ptr = 0;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct acpi_fpdt_boot_header hbrec;
         struct acpi_fpdt_boot brec;
 
index 0b1b9c6861b13f14a7c3aef75a075a0203ca3b5a..dc3d70bf1f37362faf3203a5e2ef96656f053fc7 100644 (file)
@@ -213,7 +213,7 @@ int ask_password_plymouth(
                 char ***ret) {
 
         static const union sockaddr_union sa = PLYMOUTH_SOCKET;
-        _cleanup_close_ int fd = -1, notify = -1;
+        _cleanup_close_ int fd = -EBADF, notify = -EBADF;
         _cleanup_free_ char *packet = NULL;
         ssize_t k;
         int r, n;
@@ -394,7 +394,7 @@ int ask_password_tty(
         };
 
         bool reset_tty = false, dirty = false, use_color = false, press_tab_visible = false;
-        _cleanup_close_ int cttyfd = -1, notify = -1;
+        _cleanup_close_ int cttyfd = -EBADF, notify = -EBADF;
         struct termios old_termios, new_termios;
         char passphrase[LINE_MAX + 1] = {}, *x;
         _cleanup_strv_free_erase_ char **l = NULL;
@@ -670,7 +670,7 @@ static int create_socket(char **ret) {
         _cleanup_free_ char *path = NULL;
         union sockaddr_union sa;
         socklen_t sa_len;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(ret);
@@ -715,7 +715,7 @@ int ask_password_agent(
                 _FD_MAX
         };
 
-        _cleanup_close_ int socket_fd = -1, signal_fd = -1, notify = -1, fd = -1;
+        _cleanup_close_ int socket_fd = -EBADF, signal_fd = -EBADF, notify = -EBADF, fd = -EBADF;
         char temp[] = "/run/systemd/ask-password/tmp.XXXXXX";
         char final[sizeof(temp)] = "";
         _cleanup_free_ char *socket_name = NULL;
index 9b7270ae535b9bac4b83a160389e319ea7498deb..c3f6c1f9f49950345a41427dc88b356057f6f1a0 100644 (file)
@@ -123,7 +123,7 @@ static const BaseFilesystem table[] = {
 #endif
 
 int base_filesystem_create(const char *root, uid_t uid, gid_t gid) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         fd = open(root, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
index eb9f54306f60fd63370a617d337239112999b9f5..85ae8ff8078bc424e041ed3cbf0318dbf45d998d 100644 (file)
@@ -198,7 +198,7 @@ int block_device_new_from_fd(int fd, BlockDeviceLookupFlag flags, sd_device **re
 }
 
 int block_device_new_from_path(const char *path, BlockDeviceLookupFlag flags, sd_device **ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(path);
         assert(ret);
@@ -283,7 +283,7 @@ int get_block_device_fd(int fd, dev_t *ret) {
 }
 
 int get_block_device(const char *path, dev_t *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(path);
         assert(ret);
@@ -333,7 +333,7 @@ int get_block_device_harder_fd(int fd, dev_t *ret) {
 }
 
 int get_block_device_harder(const char *path, dev_t *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(path);
         assert(ret);
@@ -346,7 +346,7 @@ int get_block_device_harder(const char *path, dev_t *ret) {
 }
 
 int lock_whole_block_device(dev_t devt, int operation) {
-        _cleanup_close_ int lock_fd = -1;
+        _cleanup_close_ int lock_fd = -EBADF;
         dev_t whole_devt;
         int r;
 
@@ -519,7 +519,7 @@ int fd_get_whole_disk(int fd, bool backing, dev_t *ret) {
 }
 
 int path_get_whole_disk(const char *path, bool backing, dev_t *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_CLOEXEC|O_PATH);
         if (fd < 0)
@@ -662,7 +662,7 @@ int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret) {
 int block_device_remove_all_partitions(sd_device *dev, int fd) {
         _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
         _cleanup_(sd_device_unrefp) sd_device *dev_unref = NULL;
-        _cleanup_close_ int fd_close = -1;
+        _cleanup_close_ int fd_close = -EBADF;
         bool has_partitions = false;
         sd_device *part;
         int r, k = 0;
@@ -740,7 +740,7 @@ int block_device_has_partitions(sd_device *dev) {
 }
 
 int blockdev_reread_partition_table(sd_device *dev) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(dev);
 
index 4cced23adcbd3303f4c48a1ba537d6c0d38ddee2..2a47f30b8f3d9ca4aaa2e8743221be0aa28ef43f 100644 (file)
@@ -585,7 +585,7 @@ static int boot_entries_find_type1(
 
         _cleanup_free_ DirectoryEntries *dentries = NULL;
         _cleanup_free_ char *full = NULL;
-        _cleanup_close_ int dir_fd = -1;
+        _cleanup_close_ int dir_fd = -EBADF;
         int r;
 
         assert(config);
@@ -860,7 +860,7 @@ static int boot_entries_find_unified(
 
         FOREACH_DIRENT(de, d, return log_error_errno(errno, "Failed to read %s: %m", full)) {
                 _cleanup_free_ char *j = NULL, *osrelease = NULL, *cmdline = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 if (!dirent_is_file(de))
                         continue;
index 31fa4448b03e1bf6b76adce41c29be119ea92a3a..531ae9b6805e667f82aa24936a8ba2a22476bada 100644 (file)
@@ -98,7 +98,7 @@ int bpf_program_new(uint32_t prog_type, const char *prog_name, BPFProgram **ret)
 
         *p = (BPFProgram) {
                 .prog_type = prog_type,
-                .kernel_fd = -1,
+                .kernel_fd = -EBADF,
                 .prog_name = TAKE_PTR(name),
         };
 
@@ -121,7 +121,7 @@ int bpf_program_new_from_bpffs_path(const char *path, BPFProgram **ret) {
 
         *p = (BPFProgram) {
                 .prog_type = BPF_PROG_TYPE_UNSPEC,
-                .kernel_fd = -1,
+                .kernel_fd = -EBADF,
         };
 
         r = bpf_program_load_from_bpf_fs(p, path);
@@ -207,7 +207,7 @@ int bpf_program_load_from_bpf_fs(BPFProgram *p, const char *path) {
 
 int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags) {
         _cleanup_free_ char *copy = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         union bpf_attr attr;
         int r;
 
@@ -268,7 +268,7 @@ int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_
 }
 
 int bpf_program_cgroup_detach(BPFProgram *p) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(p);
 
@@ -420,7 +420,7 @@ int bpf_program_serialize_attachment_set(FILE *f, FDSet *fds, const char *key, S
 int bpf_program_deserialize_attachment(const char *v, FDSet *fds, BPFProgram **bpfp) {
         _cleanup_free_ char *sfd = NULL, *sat = NULL, *unescaped = NULL;
         _cleanup_(bpf_program_freep) BPFProgram *p = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         ssize_t l;
         int ifd, at, r;
 
index b1aaf746cf91e251e7aa70c0c1e0c62de8db3fae..0a4bd48b880ffc65c2b9e05a213f3701ace14b11 100644 (file)
@@ -85,7 +85,7 @@ int btrfs_is_subvol_fd(int fd) {
 }
 
 int btrfs_is_subvol(const char *path) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(path);
 
@@ -98,7 +98,7 @@ int btrfs_is_subvol(const char *path) {
 
 int btrfs_subvol_make_fd(int fd, const char *subvolume) {
         struct btrfs_ioctl_vol_args args = {};
-        _cleanup_close_ int real_fd = -1;
+        _cleanup_close_ int real_fd = -EBADF;
         int r;
 
         assert(subvolume);
@@ -119,7 +119,7 @@ int btrfs_subvol_make_fd(int fd, const char *subvolume) {
 }
 
 int btrfs_subvol_make(const char *path) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *subvolume;
         int r;
 
@@ -184,7 +184,7 @@ int btrfs_subvol_set_read_only_fd(int fd, bool b) {
 }
 
 int btrfs_subvol_set_read_only(const char *path, bool b) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY);
         if (fd < 0)
@@ -247,7 +247,7 @@ int btrfs_clone_range(int infd, uint64_t in_offset, int outfd, uint64_t out_offs
 
 int btrfs_get_block_device_fd(int fd, dev_t *dev) {
         struct btrfs_ioctl_fs_info_args fsi = {};
-        _cleanup_close_ int regfd = -1;
+        _cleanup_close_ int regfd = -EBADF;
         uint64_t id;
         int r;
 
@@ -312,7 +312,7 @@ int btrfs_get_block_device_fd(int fd, dev_t *dev) {
 }
 
 int btrfs_get_block_device(const char *path, dev_t *dev) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(path);
         assert(dev);
@@ -347,7 +347,7 @@ int btrfs_subvol_get_id_fd(int fd, uint64_t *ret) {
 }
 
 int btrfs_subvol_get_id(int fd, const char *subvol, uint64_t *ret) {
-        _cleanup_close_ int subvol_fd = -1;
+        _cleanup_close_ int subvol_fd = -EBADF;
 
         assert(fd >= 0);
         assert(ret);
@@ -629,7 +629,7 @@ finish:
 }
 
 int btrfs_qgroup_get_quota(const char *path, uint64_t qgroupid, BtrfsQuotaInfo *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
         if (fd < 0)
@@ -722,7 +722,7 @@ int btrfs_subvol_get_subtree_quota_fd(int fd, uint64_t subvol_id, BtrfsQuotaInfo
 }
 
 int btrfs_subvol_get_subtree_quota(const char *path, uint64_t subvol_id, BtrfsQuotaInfo *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
         if (fd < 0)
@@ -744,7 +744,7 @@ int btrfs_defrag_fd(int fd) {
 }
 
 int btrfs_defrag(const char *p) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
         if (fd < 0)
@@ -771,7 +771,7 @@ int btrfs_quota_enable_fd(int fd, bool b) {
 }
 
 int btrfs_quota_enable(const char *path, bool b) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
         if (fd < 0)
@@ -822,7 +822,7 @@ int btrfs_qgroup_set_limit_fd(int fd, uint64_t qgroupid, uint64_t referenced_max
 }
 
 int btrfs_qgroup_set_limit(const char *path, uint64_t qgroupid, uint64_t referenced_max) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
         if (fd < 0)
@@ -845,7 +845,7 @@ int btrfs_subvol_set_subtree_quota_limit_fd(int fd, uint64_t subvol_id, uint64_t
 }
 
 int btrfs_subvol_set_subtree_quota_limit(const char *path, uint64_t subvol_id, uint64_t referenced_max) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
         if (fd < 0)
@@ -1049,7 +1049,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
         };
 
         struct btrfs_ioctl_vol_args vol_args = {};
-        _cleanup_close_ int subvol_fd = -1;
+        _cleanup_close_ int subvol_fd = -EBADF;
         struct stat st;
         bool made_writable = false;
         int r;
@@ -1149,7 +1149,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
                                  * directory of the subvolume. */
                                 r = subvol_remove_children(subvol_fd, p, sh->objectid, flags);
                         else {
-                                _cleanup_close_ int child_fd = -1;
+                                _cleanup_close_ int child_fd = -EBADF;
 
                                 /* Subvolume is somewhere further down,
                                  * hence we need to open the
@@ -1180,7 +1180,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
 }
 
 int btrfs_subvol_remove(const char *path, BtrfsRemoveFlags flags) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *subvolume;
         int r;
 
@@ -1414,7 +1414,7 @@ static int subvol_snapshot_children(
                 .flags = flags & BTRFS_SNAPSHOT_READ_ONLY ? BTRFS_SUBVOL_RDONLY : 0,
                 .fd = old_fd,
         };
-        _cleanup_close_ int subvolume_fd = -1;
+        _cleanup_close_ int subvolume_fd = -EBADF;
         uint64_t new_subvol_id;
         int r;
 
@@ -1468,7 +1468,7 @@ static int subvol_snapshot_children(
                 FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) {
                         _cleanup_free_ char *p = NULL, *c = NULL, *np = NULL;
                         const struct btrfs_root_ref *ref;
-                        _cleanup_close_ int old_child_fd = -1, new_child_fd = -1;
+                        _cleanup_close_ int old_child_fd = -EBADF, new_child_fd = -EBADF;
 
                         btrfs_ioctl_search_args_set(&args, sh);
 
@@ -1578,7 +1578,7 @@ int btrfs_subvol_snapshot_fd_full(
                 copy_progress_bytes_t progress_bytes,
                 void *userdata) {
 
-        _cleanup_close_ int new_fd = -1;
+        _cleanup_close_ int new_fd = -EBADF;
         const char *subvolume;
         int r;
 
@@ -1661,7 +1661,7 @@ int btrfs_subvol_snapshot_full(
                 copy_progress_bytes_t progress_bytes,
                 void *userdata) {
 
-        _cleanup_close_ int old_fd = -1;
+        _cleanup_close_ int old_fd = -EBADF;
 
         assert(old_path);
         assert(new_path);
@@ -1762,7 +1762,7 @@ int btrfs_qgroup_find_parents(int fd, uint64_t qgroupid, uint64_t **ret) {
 
 int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermediary_qgroup) {
         _cleanup_free_ uint64_t *qgroups = NULL;
-        _cleanup_close_ int real_fd = -1;
+        _cleanup_close_ int real_fd = -EBADF;
         uint64_t parent_subvol;
         bool changed = false;
         int n = 0, r;
@@ -1914,7 +1914,7 @@ int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermed
 }
 
 int btrfs_subvol_auto_qgroup(const char *path, uint64_t subvol_id, bool create_intermediary_qgroup) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY);
         if (fd < 0)
index e6f67fc714920e5a61a868202157b3f0b670a27b..2d2858c3b48a8de6fa65fdbc876fae92b0dddb37 100644 (file)
@@ -161,7 +161,7 @@ static int show_cgroup_name(
 
         uint64_t cgroupid = UINT64_MAX;
         _cleanup_free_ char *b = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         bool delegate;
         int r;
 
index bbc270d34b2ced165b1f6b05837f6c6b2aa5d301..883c1ccee4e820b78f4ef0e651ae46174bc7cfef 100644 (file)
@@ -63,7 +63,7 @@ static int chown_recursive_internal(
         }
 
         FOREACH_DIRENT_ALL(de, d, return -errno) {
-                _cleanup_close_ int path_fd = -1;
+                _cleanup_close_ int path_fd = -EBADF;
                 struct stat fst;
 
                 if (dot_or_dot_dot(de->d_name))
@@ -113,7 +113,7 @@ int path_chown_recursive(
                 gid_t gid,
                 mode_t mask) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
 
         fd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
@@ -142,7 +142,7 @@ int fd_chown_recursive(
                 gid_t gid,
                 mode_t mask) {
 
-        int duplicated_fd = -1;
+        int duplicated_fd = -EBADF;
         struct stat st;
 
         /* Note that the slightly different order of fstat() and the checks here and in
index a4c00d713e3887dd8aca49fbc490b6b5673bfb23..b0cbe3007202325f5847034da9f760dc960f7aea 100644 (file)
@@ -19,7 +19,7 @@
 #include "string-util.h"
 
 int clock_get_hwclock(struct tm *tm) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(tm);
 
@@ -40,7 +40,7 @@ int clock_get_hwclock(struct tm *tm) {
 }
 
 int clock_set_hwclock(const struct tm *tm) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(tm);
 
index e2ce4b29074bfc2ad8a209f5944f3bd92793ab68..e103aa0f7ff0deaa4d623daa5de7840b267989ce 100644 (file)
@@ -713,7 +713,7 @@ static int fd_copy_regular(
                 copy_progress_bytes_t progress,
                 void *userdata) {
 
-        _cleanup_close_ int fdf = -1, fdt = -1;
+        _cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
         int r, q;
 
         assert(from);
@@ -904,11 +904,11 @@ static int fd_copy_directory(
                 void *userdata) {
 
         _cleanup_(hardlink_context_destroy) HardlinkContext our_hardlink_context = {
-                .dir_fd = -1,
-                .parent_fd = -1,
+                .dir_fd = -EBADF,
+                .parent_fd = -EBADF,
         };
 
-        _cleanup_close_ int fdf = -1, fdt = -1;
+        _cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
         _cleanup_closedir_ DIR *d = NULL;
         bool exists, created;
         int r;
@@ -1286,7 +1286,7 @@ int copy_file_fd_full(
                 copy_progress_bytes_t progress_bytes,
                 void *userdata) {
 
-        _cleanup_close_ int fdf = -1;
+        _cleanup_close_ int fdf = -EBADF;
         struct stat st;
         int r;
 
@@ -1339,7 +1339,7 @@ int copy_file_full(
                 copy_progress_bytes_t progress_bytes,
                 void *userdata) {
 
-        _cleanup_close_ int fdf = -1, fdt = -1;
+        _cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
         struct stat st;
         int r;
 
@@ -1428,7 +1428,7 @@ int copy_file_atomic_full(
                 void *userdata) {
 
         _cleanup_(unlink_and_freep) char *t = NULL;
-        _cleanup_close_ int fdt = -1;
+        _cleanup_close_ int fdt = -EBADF;
         int r;
 
         assert(from);
index f6811ce9aa7ea797bfd561cbdbb84ec063a4f526..9f4d0832abf480efc68b00816d362c41d5307d9a 100644 (file)
@@ -167,7 +167,7 @@ static int make_credential_host_secret(
 
         struct credential_host_secret_format buf;
         _cleanup_free_ char *t = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(dfd >= 0);
@@ -251,7 +251,7 @@ finish:
 
 int get_credential_host_secret(CredentialSecretFlags flags, void **ret, size_t *ret_size) {
         _cleanup_free_ char *_dirname = NULL, *_filename = NULL;
-        _cleanup_close_ int dfd = -1;
+        _cleanup_close_ int dfd = -EBADF;
         sd_id128_t machine_id;
         const char *dirname, *filename;
         int r;
@@ -298,7 +298,7 @@ int get_credential_host_secret(CredentialSecretFlags flags, void **ret, size_t *
 
         for (unsigned attempt = 0;; attempt++) {
                 _cleanup_(erase_and_freep) struct credential_host_secret_format *f = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 size_t l = 0;
                 ssize_t n = 0;
                 struct stat st;
index 58ee1845afd6ca61117edfc31876b9ef03d1b326..15d31ac20ce2488e4cb3e281fe6f5eecaad22f60 100644 (file)
@@ -28,7 +28,7 @@
 int acquire_data_fd(const void *data, size_t size, unsigned flags) {
         _cleanup_close_pair_ int pipefds[2] = { -1, -1 };
         char pattern[] = "/dev/shm/data-fd-XXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int isz = 0, r;
         ssize_t n;
         off_t f;
@@ -163,7 +163,7 @@ try_dev_shm_without_o_tmpfile:
 }
 
 int copy_data_fd(int fd) {
-        _cleanup_close_ int copy_fd = -1, tmp_fd = -1;
+        _cleanup_close_ int copy_fd = -EBADF, tmp_fd = -EBADF;
         _cleanup_free_ void *remains = NULL;
         size_t remains_size = 0;
         const char *td;
@@ -376,7 +376,7 @@ int memfd_clone_fd(int fd, const char *name, int mode) {
                 return r;
 
         if (ro) {
-                _cleanup_close_ int rfd = -1;
+                _cleanup_close_ int rfd = -EBADF;
 
                 r = memfd_set_sealed(mfd);
                 if (r < 0)
index eb4d23f0e8a71afe635e235735d708f24beb26c8..1f0f7ca7da0d02235d6cabab78533dff9fed925c 100644 (file)
@@ -247,7 +247,7 @@ static int image_make(
                 (faccessat(dfd, filename, W_OK, AT_EACCESS) < 0 && errno == EROFS);
 
         if (S_ISDIR(st->st_mode)) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 unsigned file_attr = 0;
                 usec_t crtime = 0;
 
@@ -367,7 +367,7 @@ static int image_make(
                 return 0;
 
         } else if (S_ISBLK(st->st_mode)) {
-                _cleanup_close_ int block_fd = -1;
+                _cleanup_close_ int block_fd = -EBADF;
                 uint64_t size = UINT64_MAX;
 
                 /* A block device */
@@ -984,7 +984,7 @@ int image_read_only(Image *i, bool b) {
         }
 
         case IMAGE_BLOCK: {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 struct stat st;
                 int state = b;
 
@@ -1152,7 +1152,7 @@ int image_read_metadata(Image *i) {
                 if (r < 0 && r != -ENOENT)
                         log_debug_errno(r, "Failed to chase /etc/machine-id in image %s: %m", i->name);
                 else if (r >= 0) {
-                        _cleanup_close_ int fd = -1;
+                        _cleanup_close_ int fd = -EBADF;
 
                         fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
                         if (fd < 0)
index b3d35e9fbf34c6545160a80b4fbf80b2640c3f4d..c9acc2e3063200afae6988e4e41bebf4b9a8b12e 100644 (file)
@@ -88,7 +88,7 @@ int probe_filesystem_full(
 #if HAVE_BLKID
         _cleanup_(blkid_free_probep) blkid_probe b = NULL;
         _cleanup_free_ char *path_by_fd = NULL;
-        _cleanup_close_ int fd_close = -1;
+        _cleanup_close_ int fd_close = -EBADF;
         const char *fstype;
         int r;
 
@@ -313,7 +313,7 @@ static int make_partition_devname(
 
 static int open_partition(const char *node, bool is_partition, const LoopDevice *loop) {
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         dev_t devnum;
         int r;
 
@@ -477,7 +477,7 @@ static int dissect_image(
                 if (STRPTR_IN_SET(usage, "filesystem", "crypto")) {
                         _cleanup_free_ char *t = NULL, *n = NULL, *o = NULL;
                         const char *fstype = NULL, *options = NULL, *suuid = NULL;
-                        _cleanup_close_ int mount_node_fd = -1;
+                        _cleanup_close_ int mount_node_fd = -EBADF;
                         sd_id128_t uuid = SD_ID128_NULL;
 
                         if (FLAGS_SET(flags, DISSECT_IMAGE_PIN_PARTITION_DEVICES)) {
@@ -872,7 +872,7 @@ static int dissect_image(
 
                         if (type.designator != _PARTITION_DESIGNATOR_INVALID) {
                                 _cleanup_free_ char *t = NULL, *o = NULL, *l = NULL;
-                                _cleanup_close_ int mount_node_fd = -1;
+                                _cleanup_close_ int mount_node_fd = -EBADF;
                                 const char *options = NULL;
 
                                 if (m->partitions[type.designator].found) {
@@ -958,7 +958,7 @@ static int dissect_image(
                                 break;
 
                         case 0xEA: { /* Boot Loader Spec extended $BOOT partition */
-                                _cleanup_close_ int mount_node_fd = -1;
+                                _cleanup_close_ int mount_node_fd = -EBADF;
                                 _cleanup_free_ char *o = NULL;
                                 sd_id128_t id = SD_ID128_NULL;
                                 const char *options = NULL;
@@ -1043,7 +1043,7 @@ static int dissect_image(
 
                 /* If we didn't find a generic node, then we can't fix this up either */
                 if (generic_node) {
-                        _cleanup_close_ int mount_node_fd = -1;
+                        _cleanup_close_ int mount_node_fd = -EBADF;
                         _cleanup_free_ char *o = NULL;
                         const char *options;
 
@@ -1152,7 +1152,7 @@ int dissect_image_file(
 
 #if HAVE_BLKID
         _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(path);
@@ -1282,7 +1282,7 @@ static int run_fsck(int node_fd, const char *fstype) {
 }
 
 static int fs_grow(const char *node_path, const char *mount_path) {
-        _cleanup_close_ int mount_fd = -1, node_fd = -1;
+        _cleanup_close_ int mount_fd = -EBADF, node_fd = -EBADF;
         uint64_t size, newsize;
         int r;
 
@@ -1736,7 +1736,7 @@ static int decrypt_partition(
 
         _cleanup_free_ char *node = NULL, *name = NULL;
         _cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(m);
@@ -2026,7 +2026,7 @@ static int verity_partition(
         _cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
         _cleanup_(dm_deferred_remove_cleanp) char *restore_deferred_remove = NULL;
         _cleanup_free_ char *node = NULL, *name = NULL;
-        _cleanup_close_ int mount_node_fd = -1;
+        _cleanup_close_ int mount_node_fd = -EBADF;
         int r;
 
         assert(m);
@@ -2088,7 +2088,7 @@ static int verity_partition(
          * retry a few times before giving up. */
         for (unsigned i = 0; i < N_DEVICE_NODE_LIST_ATTEMPTS; i++) {
                 _cleanup_(sym_crypt_freep) struct crypt_device *existing_cd = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 /* First, check if the device already exists. */
                 fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
@@ -2712,7 +2712,7 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
 
         for (; n_meta_initialized < _META_MAX; n_meta_initialized ++) {
                 if (!paths[n_meta_initialized]) {
-                        fds[2*n_meta_initialized] = fds[2*n_meta_initialized+1] = -1;
+                        fds[2*n_meta_initialized] = fds[2*n_meta_initialized+1] = -EBADF;
                         continue;
                 }
 
index 059b9aecbb9e36dcfc4faf32157995698c8385f3..37a41e050a9b16a6c6b30aa6b63fe1ca67352b69 100644 (file)
@@ -40,7 +40,7 @@ struct DissectedPartition {
         ((DissectedPartition) {                                         \
                 .partno = -1,                                           \
                 .architecture = _ARCHITECTURE_INVALID,                  \
-                .mount_node_fd = -1,                                    \
+                .mount_node_fd = -EBADF,                                \
         })
 #define TAKE_PARTITION(p)                                       \
         ({                                                      \
index b48b9b5cbcf08a8c194fc96a12e1152fd72ec87b..66c1e134397c43e8bca6aad6bf6e38dc3a6cc48e 100644 (file)
@@ -9,7 +9,7 @@
 #include "string-util.h"
 
 int dm_deferred_remove_cancel(const char *name) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct message {
                 struct dm_ioctl dm_ioctl;
                 struct dm_target_msg dm_target_msg;
index e39b2f754bbe2dcd5a25d79afea4e8caee756864..e2b2ca235298b23af3b47f77bb60b5d21bd88c81 100644 (file)
@@ -349,7 +349,7 @@ int ethtool_get_link_info(
 }
 
 int ethtool_get_permanent_hw_addr(int *ethtool_fd, const char *ifname, struct hw_addr_data *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct {
                 struct ethtool_perm_addr addr;
                 uint8_t space[HW_ADDR_MAX_SIZE];
index cd57016964efc412c522a42348dc1005b8558934..cd922b84d4d40ca965fff1348c616c8e5fa11bbb 100644 (file)
@@ -123,7 +123,7 @@ static int do_execute(
 
         STRV_FOREACH(path, paths) {
                 _cleanup_free_ char *t = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 pid_t pid;
 
                 t = strdup(*path);
@@ -158,7 +158,7 @@ static int do_execute(
                                         return log_error_errno(errno, "Failed to seek on serialization fd: %m");
 
                                 r = callbacks[STDOUT_GENERATE](fd, callback_args[STDOUT_GENERATE]);
-                                fd = -1;
+                                fd = -EBADF;
                                 if (r < 0)
                                         return log_error_errno(r, "Failed to process output from %s: %m", *path);
                         }
@@ -199,7 +199,7 @@ int execute_directories(
                 ExecDirFlags flags) {
 
         char **dirs = (char**) directories;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char *name;
         int r;
         pid_t executor_pid;
@@ -245,7 +245,7 @@ int execute_directories(
                 return log_error_errno(errno, "Failed to rewind serialization fd: %m");
 
         r = callbacks[STDOUT_CONSUME](fd, callback_args[STDOUT_CONSUME]);
-        fd = -1;
+        fd = -EBADF;
         if (r < 0)
                 return log_error_errno(r, "Failed to parse returned data: %m");
         return 0;
index 183fa239b6d2cd1ba00d374374eb351ad7e6747b..cfa12a509e30a2b483a9f94b6932ec9d23ec7fdb 100644 (file)
@@ -131,7 +131,7 @@ int fdset_new_fill(FDSet **_s) {
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
-                int fd = -1;
+                int fd = -EBADF;
 
                 r = safe_atoi(de->d_name, &fd);
                 if (r < 0)
index e019b816205f330bfef8d87d033fc9172a8f6677..084dd1c1e2a9483a33d2332cfca58667b327ed56 100644 (file)
@@ -243,7 +243,7 @@ static int verify_fsroot_dir(
                 bool unprivileged_mode,
                 dev_t *ret_dev) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         STRUCT_NEW_STATX_DEFINE(sxa);
         STRUCT_NEW_STATX_DEFINE(sxb);
         int r;
@@ -328,7 +328,7 @@ success:
                 return 0;
 
         if (sxa.sx.stx_dev_major == 0) { /* Hmm, maybe a btrfs device, and the caller asked for the backing device? Then let's try to get it. */
-                _cleanup_close_ int real_fd = -1;
+                _cleanup_close_ int real_fd = -EBADF;
 
                 /* The statx() above we can execute on an O_PATH fd. But the btrfs ioctl we cannot. Hence
                  * acquire a "real" fd first, without the O_PATH flag. */
index 5187d71beca0fe28bbef2779c720acc130cba9dc..ffcf86e057d5815a51ef63194c953ab15a93b908 100644 (file)
@@ -98,7 +98,7 @@ int install_file(int source_atfd, const char *source_name,
                  int target_atfd, const char *target_name,
                  InstallFileFlags flags) {
 
-        _cleanup_close_ int rofd = -1;
+        _cleanup_close_ int rofd = -EBADF;
         int r;
 
         /* Moves a file or directory tree into place, with some bells and whistles:
@@ -118,7 +118,7 @@ int install_file(int source_atfd, const char *source_name,
          * target_name=NULL and flags=0 this call is a NOP */
 
         if ((flags & (INSTALL_FSYNC|INSTALL_FSYNC_FULL|INSTALL_SYNCFS|INSTALL_READ_ONLY)) != 0) {
-                _cleanup_close_ int pfd = -1;
+                _cleanup_close_ int pfd = -EBADF;
                 struct stat st;
 
                 /* Open an O_PATH fd for the source if we need to sync things or mark things read only. */
@@ -133,7 +133,7 @@ int install_file(int source_atfd, const char *source_name,
                 switch (st.st_mode & S_IFMT) {
 
                 case S_IFREG: {
-                        _cleanup_close_ int regfd = -1;
+                        _cleanup_close_ int regfd = -EBADF;
 
                         regfd = fd_reopen(pfd, O_RDONLY|O_CLOEXEC);
                         if (regfd < 0)
@@ -158,7 +158,7 @@ int install_file(int source_atfd, const char *source_name,
                 }
 
                 case S_IFDIR: {
-                        _cleanup_close_ int dfd = -1;
+                        _cleanup_close_ int dfd = -EBADF;
 
                         dfd = fd_reopen(pfd, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
                         if (dfd < 0)
@@ -203,7 +203,7 @@ int install_file(int source_atfd, const char *source_name,
                 if (flags & INSTALL_REPLACE) {
                         /* First, try a simple renamat(), maybe that's enough */
                         if (renameat(source_atfd, source_name, target_atfd, target_name) < 0) {
-                                _cleanup_close_ int dfd = -1;
+                                _cleanup_close_ int dfd = -EBADF;
 
                                 if (!IN_SET(errno, EEXIST, ENOTDIR, ENOTEMPTY, EISDIR, EBUSY))
                                         return -errno;
index c38ba1bd7aa4aa35b99f634b22f50a4f0d597508..db150247fc94bf2be59a96f9f6e8339492ed3d5f 100644 (file)
@@ -739,7 +739,7 @@ static int remove_marked_symlinks(
                 InstallChange **changes,
                 size_t *n_changes) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         bool restart;
         int r = 0;
 
@@ -1330,7 +1330,7 @@ static int unit_file_load(
 
         UnitType type;
         _cleanup_fclose_ FILE *f = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
         int r;
 
index 2876f72d16fae7efe36164ce592baf53e82057e7..a1577de0df205a8aaf76b16220fcbfb8a79bc64b 100644 (file)
@@ -390,7 +390,7 @@ int local_outbounds(
         }
 
         for (int i = 0; i < n_gateways; i++) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 union sockaddr_union sa;
                 socklen_t salen;
 
index 6f059abfffa8463a1e9aef6bc59f23a5c068a045..b920f3fe9be309abd6fcf9de25f72948514aa3f9 100644 (file)
@@ -16,7 +16,7 @@
 #include "path-util.h"
 
 int make_lock_file(const char *p, int operation, LockFile *ret) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *t = NULL;
         int r;
 
@@ -76,7 +76,7 @@ int make_lock_file(const char *p, int operation, LockFile *ret) {
         ret->fd = fd;
         ret->operation = operation;
 
-        fd = -1;
+        fd = -EBADF;
         t = NULL;
 
         return r;
index 36063270dd2f3230268a4521dc97ec5915f7065e..20e19c01d4d3e114e9cb9a4d0301228dbc0d6689 100644 (file)
@@ -11,4 +11,4 @@ int make_lock_file(const char *p, int operation, LockFile *ret);
 int make_lock_file_for(const char *p, int operation, LockFile *ret);
 void release_lock_file(LockFile *f);
 
-#define LOCK_FILE_INIT { .fd = -1, .path = NULL }
+#define LOCK_FILE_INIT { .fd = -EBADF, .path = NULL }
index 7972fc009e582a732e88b1c678d2f466eae63290..535b61704482370b6117008e0116cc0a78d48e21 100644 (file)
@@ -1625,7 +1625,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
 
 static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
-        _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
+        _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, rootfd = -EBADF;
         char buf[SD_ID128_UUID_STRING_MAX];
         pid_t pid, child;
         ssize_t k;
index ed31454e313d08510f8c646fca291df6184da225..eb1a5bb59fdb394a870c335311e68c5ce67c240d 100644 (file)
@@ -73,7 +73,7 @@ static int get_current_uevent_seqnum(uint64_t *ret) {
 }
 
 static int open_lock_fd(int primary_fd, int operation) {
-        _cleanup_close_ int lock_fd = -1;
+        _cleanup_close_ int lock_fd = -EBADF;
 
         assert(primary_fd >= 0);
         assert(IN_SET(operation & ~LOCK_NB, LOCK_SH, LOCK_EX));
@@ -238,8 +238,8 @@ static int loop_configure(
         static bool loop_configure_broken = false;
 
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
-        _cleanup_(cleanup_clear_loop_close) int loop_with_fd = -1; /* This must be declared before lock_fd. */
-        _cleanup_close_ int fd = -1, lock_fd = -1;
+        _cleanup_(cleanup_clear_loop_close) int loop_with_fd = -EBADF; /* This must be declared before lock_fd. */
+        _cleanup_close_ int fd = -EBADF, lock_fd = -EBADF;
         _cleanup_free_ char *node = NULL;
         uint64_t diskseq = 0, seqnum = UINT64_MAX;
         usec_t timestamp = USEC_INFINITY;
@@ -409,7 +409,7 @@ static int loop_device_make_internal(
                 LoopDevice **ret) {
 
         _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
-        _cleanup_close_ int direct_io_fd = -1, control = -1;
+        _cleanup_close_ int direct_io_fd = -EBADF, control = -EBADF;
         _cleanup_free_ char *backing_file = NULL;
         struct loop_config config;
         int r, f_flags;
@@ -588,7 +588,7 @@ int loop_device_make_by_path(
                 LoopDevice **ret) {
 
         int r, basic_flags, direct_flags, rdwr_flags;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         bool direct = false;
 
         assert(path);
@@ -776,7 +776,7 @@ int loop_device_open(
                 int lock_op,
                 LoopDevice **ret) {
 
-        _cleanup_close_ int fd = -1, lock_fd = -1;
+        _cleanup_close_ int fd = -EBADF, lock_fd = -EBADF;
         _cleanup_free_ char *node = NULL, *backing_file = NULL;
         struct loop_info64 info;
         uint64_t diskseq = 0;
@@ -896,7 +896,7 @@ static int resize_partition(int partition_fd, uint64_t offset, uint64_t size) {
         char sysfs[STRLEN("/sys/dev/block/:/partition") + 2*DECIMAL_STR_MAX(dev_t) + 1];
         _cleanup_free_ char *buffer = NULL;
         uint64_t current_offset, current_size, partno;
-        _cleanup_close_ int whole_fd = -1;
+        _cleanup_close_ int whole_fd = -EBADF;
         struct stat st;
         dev_t devno;
         int r;
index 0bdaba00e64d2c6e0648e2e05d6073072abd1c4b..4b4309037b47f946084bd733d482da533d8a01c9 100644 (file)
@@ -28,7 +28,7 @@
 
 static int generate_machine_id(const char *root, sd_id128_t *ret) {
         const char *dbus_machine_id;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(ret);
@@ -83,7 +83,7 @@ static int generate_machine_id(const char *root, sd_id128_t *ret) {
 
 int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_id, sd_id128_t *ret) {
         const char *etc_machine_id, *run_machine_id;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         bool writable;
         int r;
 
@@ -195,7 +195,7 @@ finish:
 }
 
 int machine_id_commit(const char *root) {
-        _cleanup_close_ int fd = -1, initial_mntns_fd = -1;
+        _cleanup_close_ int fd = -EBADF, initial_mntns_fd = -EBADF;
         const char *etc_machine_id;
         sd_id128_t id;
         int r;
index 59d851ba0f8589c23f92b8e33178cf2d65d9fab0..9e240d41f4305b51baead46048d3c45168949336 100644 (file)
@@ -130,7 +130,7 @@ static int setup_userns(uid_t uid, gid_t gid) {
 static int do_mcopy(const char *node, const char *root) {
         _cleanup_free_ char *mcopy = NULL;
         _cleanup_strv_free_ char **argv = NULL;
-        _cleanup_close_ int rfd = -1;
+        _cleanup_close_ int rfd = -EBADF;
         _cleanup_free_ DirectoryEntries *de = NULL;
         struct stat st;
         int r;
index 8fce74297bd2ee5e60dd434abc213507a9178804..6e4fa4a486907b2302663f80bc3a8edb99256ae5 100644 (file)
@@ -807,7 +807,7 @@ static int mount_in_namespace(
                 bool is_image) {
 
         _cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
-        _cleanup_close_ int mntns_fd = -1, root_fd = -1, pidns_fd = -1, chased_src_fd = -1;
+        _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF, chased_src_fd = -EBADF;
         char mount_slave[] = "/tmp/propagate.XXXXXX", *mount_tmp, *mount_outside, *p;
         bool mount_slave_created = false, mount_slave_mounted = false,
                 mount_tmp_created = false, mount_tmp_mounted = false,
@@ -1067,7 +1067,7 @@ int make_mount_point(const char *path) {
 }
 
 static int make_userns(uid_t uid_shift, uid_t uid_range, uid_t owner, RemountIdmapping idmapping) {
-        _cleanup_close_ int userns_fd = -1;
+        _cleanup_close_ int userns_fd = -EBADF;
         _cleanup_free_ char *line = NULL;
 
         /* Allocates a userns file descriptor with the mapping we need. For this we'll fork off a child
@@ -1118,7 +1118,7 @@ int remount_idmap(
                 uid_t owner,
                 RemountIdmapping idmapping) {
 
-        _cleanup_close_ int mount_fd = -1, userns_fd = -1;
+        _cleanup_close_ int mount_fd = -EBADF, userns_fd = -EBADF;
         int r;
 
         assert(p);
index 9b0ba2d67a0826099d674779ec1829fb8323ab5a..dfc7db6964dc6e849c4d90ec4f41c40c1cf973e2 100644 (file)
@@ -23,7 +23,7 @@ struct nscdInvalidateRequest {
 static int nscd_flush_cache_one(const char *database, usec_t end) {
         size_t req_size, has_written = 0, has_read = 0, l;
         struct nscdInvalidateRequest *req;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int32_t resp;
         int events, r;
 
index 6ffe86ef7f00e5305a3a351c0b84e873dcb01d50..195e6032243ede8e4b7a705272be16df127ed045 100644 (file)
@@ -412,9 +412,9 @@ int pty_forward_new(
 
         *f = (struct PTYForward) {
                 .flags = flags,
-                .master = -1,
-                .input_fd = -1,
-                .output_fd = -1,
+                .master = -EBADF,
+                .input_fd = -EBADF,
+                .output_fd = -EBADF,
         };
 
         if (event)
index b11040556830574a4df15f094cb512aba842964d..a010bf6e7f28c5f6a470afda3c041b1a6daaef54 100644 (file)
@@ -122,7 +122,7 @@ int shall_restore_state(void) {
 
 static int xen_kexec_loaded(void) {
 #if HAVE_XENCTRL
-        _cleanup_close_ int privcmd_fd = -1, buf_fd = -1;
+        _cleanup_close_ int privcmd_fd = -EBADF, buf_fd = -EBADF;
         xen_kexec_status_t *buffer;
         size_t size;
         int r;
index e240cdc2c32702a616189fc58b8a18eb81ef7959..a74883ab81ef4c5b2eacfedcfae126ef8cce0444 100644 (file)
@@ -297,7 +297,7 @@ int mac_selinux_fix_full(
         assert(atfd >= 0 || inode_path);
 
 #if HAVE_SELINUX
-        _cleanup_close_ int opened_fd = -1;
+        _cleanup_close_ int opened_fd = -EBADF;
         _cleanup_free_ char *p = NULL;
         int inode_fd, r;
 
index 0b1470ca01361832ac40c4d184b8382f84ae90fa..9c5602d617d21929ad945ed455599ba26db08875 100644 (file)
@@ -718,7 +718,7 @@ static int swap_device_to_device_id(const SwapEntry *swap, dev_t *ret_dev) {
  * filesystems, a debug message is logged and ret_offset is set to UINT64_MAX.
  */
 static int calculate_swap_file_offset(const SwapEntry *swap, uint64_t *ret_offset) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ struct fiemap *fiemap = NULL;
         struct stat sb;
         int r;
index 9ffee5a5eb6962dd80bd432df52f0ae75b9d418d..b3b5c905ad8f601a203c2c28f8568912609895e6 100644 (file)
@@ -188,7 +188,7 @@ int mac_smack_fix_full(
                 const char *label_path,
                 LabelFixFlags flags) {
 
-        _cleanup_close_ int opened_fd = -1;
+        _cleanup_close_ int opened_fd = -EBADF;
         _cleanup_free_ char *p = NULL;
         int r, inode_fd;
 
index 5195ca410c99c37d419b584c78569b3d2e185c59..b86a6adbb96ed1881ac250ea82c0c8209eddeef6 100644 (file)
@@ -32,7 +32,7 @@ int socket_address_listen(
                 mode_t socket_mode,
                 const char *label) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *p;
         int r;
 
index cd651768bd80725c11e4bead8c942cca370f890d..05f5b28bb648d0a9eb2d1bfe49679cbe121d1260 100644 (file)
@@ -188,7 +188,7 @@ int specifier_machine_id(char specifier, const void *data, const char *root, con
         assert(ret);
 
         if (root) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 fd = chase_symlinks_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
                 if (fd < 0)
index 8d4c07150e2279a97ec5f3b4ba9389133c567336..2aa30bd9f0213a8485e43be685a18f27e5407704 100644 (file)
@@ -31,7 +31,7 @@ int switch_root(const char *new_root,
                 unsigned long mount_flags) {  /* MS_MOVE or MS_BIND */
 
         _cleanup_free_ char *resolved_old_root_after = NULL;
-        _cleanup_close_ int old_root_fd = -1;
+        _cleanup_close_ int old_root_fd = -EBADF;
         int r;
 
         assert(new_root);
index ad6f978f98b70d6444c59fd41e668d53a231a994..54e80decd1bee2945c997de145429f1acd9f97a9 100644 (file)
@@ -137,7 +137,7 @@ int log_tests_skipped_errno(int r, const char *message) {
 }
 
 int write_tmpfile(char *pattern, const char *contents) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(pattern);
         assert(contents);
index 7d953534520b9b7e04e9b96aa927d948f1252355..a4b17be097929da24ee1566d737bff081d1eeca3 100644 (file)
@@ -570,7 +570,7 @@ int udev_queue_is_empty(void) {
 }
 
 int udev_queue_init(void) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = inotify_init1(IN_CLOEXEC);
         if (fd < 0)
index 37a5bf79904504d07fbfa2d848f704582f0e3ca7..3a68cf801691c2f464c2524870ee5da85cd5ea6c 100644 (file)
@@ -284,7 +284,7 @@ int utmp_put_runlevel(int runlevel, int previous) {
 #define TIMEOUT_USEC (50 * USEC_PER_MSEC)
 
 static int write_to_terminal(const char *tty, const char *message) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *p;
         size_t left;
         usec_t end;
index 7ff81973e1c1d3b55387991f193751ec1d393626..80820fcad214542620d7b6fa0f75bcfdb2d2c42f 100644 (file)
@@ -258,7 +258,7 @@ static int varlink_new(Varlink **ret) {
 
         *v = (Varlink) {
                 .n_ref = 1,
-                .fd = -1,
+                .fd = -EBADF,
 
                 .state = _VARLINK_STATE_INVALID,
 
@@ -2194,7 +2194,7 @@ int varlink_server_add_connection(VarlinkServer *server, int fd, Varlink **ret)
                 r = varlink_attach_event(v, server->event, server->event_priority);
                 if (r < 0) {
                         varlink_log_errno(v, r, "Failed to attach new connection: %m");
-                        v->fd = -1; /* take the fd out of the connection again */
+                        v->fd = -EBADF; /* take the fd out of the connection again */
                         varlink_close(v);
                         return r;
                 }
@@ -2218,7 +2218,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkServerSocket *, varlink_server_socket_free);
 
 static int connect_callback(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
         VarlinkServerSocket *ss = ASSERT_PTR(userdata);
-        _cleanup_close_ int cfd = -1;
+        _cleanup_close_ int cfd = -EBADF;
         Varlink *v = NULL;
         int r;
 
@@ -2306,7 +2306,7 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t
         _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
         union sockaddr_union sockaddr;
         socklen_t sockaddr_len;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert_return(s, -EINVAL);
@@ -2619,7 +2619,7 @@ int varlink_server_deserialize_one(VarlinkServer *s, const char *value, FDSet *f
         _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
         _cleanup_free_ char *address = NULL;
         const char *v = ASSERT_PTR(value);
-        int r, fd = -1;
+        int r, fd = -EBADF;
         char *buf;
         size_t n;
 
index cb44e96dae98c3584b0e96780c04f9f229dd68e4..4445efb125f4f4de8332891cceee8bdf56a21f73 100644 (file)
@@ -17,7 +17,7 @@
 #include "time-util.h"
 #include "watchdog.h"
 
-static int watchdog_fd = -1;
+static int watchdog_fd = -EBADF;
 static char *watchdog_device = NULL;
 static usec_t watchdog_timeout = 0; /* 0 → close device and USEC_INFINITY → don't change timeout */
 static usec_t watchdog_pretimeout = 0; /* 0 → disable pretimeout and USEC_INFINITY → don't change pretimeout */
index c6fa64c344b55828e7f9d9fe7c78fdbcb310e44c..3ccd7173e3ccf13efe3296d86c069a5c954f15b8 100644 (file)
@@ -401,7 +401,7 @@ static int md_list_get(MountPoint **head) {
 }
 
 static int delete_loopback(const char *device) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct loop_info64 info;
 
         assert(device);
@@ -476,7 +476,7 @@ static int delete_loopback(const char *device) {
 }
 
 static int delete_dm(MountPoint *m) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(m);
@@ -503,7 +503,7 @@ static int delete_dm(MountPoint *m) {
 }
 
 static int delete_md(MountPoint *m) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(m);
         assert(major(m->devnum) != 0);
index 9b69a2a10d1fcd315c87d7bb083b2d07ec670d12..20d3a9470444cd0f39c59b560dd562986aa22731 100644 (file)
@@ -273,7 +273,7 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
         assert(sleep_config);
 
         while (battery_is_low() == 0) {
-                _cleanup_close_ int tfd = -1;
+                _cleanup_close_ int tfd = -EBADF;
                 struct itimerspec ts = {};
                 usec_t suspend_interval = sleep_config->hibernate_delay_sec, before_timestamp = 0, after_timestamp = 0, total_suspend_interval;
                 bool woken_by_timer;
index fb262842d88f5ef26f8ed1f8b9209700d81cf595..c3bb293520a8c36c04211da62b651dbbc671a70b 100644 (file)
@@ -486,7 +486,7 @@ static int add_connection_socket(Context *context, int fd) {
         *c = (Connection) {
                .context = context,
                .server_fd = fd,
-               .client_fd = -1,
+               .client_fd = -EBADF,
                .server_to_client_buffer = {-1, -1},
                .client_to_server_buffer = {-1, -1},
         };
@@ -504,7 +504,7 @@ static int add_connection_socket(Context *context, int fd) {
 static int accept_cb(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
         _cleanup_free_ char *peer = NULL;
         Context *context = ASSERT_PTR(userdata);
-        int nfd = -1, r;
+        int nfd = -EBADF, r;
 
         assert(s);
         assert(fd >= 0);
index 606f602c3acf3720c06e8373a2a736c2238a3028..a97db68d2dc4ce0e54f4c4cbbe585fd20d9d144e 100644 (file)
@@ -16,7 +16,7 @@
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         _cleanup_strv_free_ char **argv = NULL;
-        _cleanup_close_ int orig_stdout_fd = -1;
+        _cleanup_close_ int orig_stdout_fd = -EBADF;
         int r;
 
         if (size > 16*1024)
index 0412b0c62661c5c5b4377fd6ee5f9bb14568f73d..fc73830a0757e05672473dbdf193585dfc5742d7 100644 (file)
@@ -18,7 +18,7 @@
 
 int talk_initctl(char rl) {
 #if HAVE_SYSV_COMPAT
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *path;
         int r;
 
index 2814fdb6fa307a77eb52c602f3e3cb2f76bbc041..56ce9b31cf50f13ac28298a43c878ecb735219a5 100644 (file)
@@ -563,7 +563,7 @@ int resource_resolve_path(
                         d = orig_root_stats.st_rdev;
 
         } else if (rr->type == RESOURCE_PARTITION) {
-                _cleanup_close_ int fd = -1, real_fd = -1;
+                _cleanup_close_ int fd = -EBADF, real_fd = -EBADF;
                 _cleanup_free_ char *resolved = NULL;
                 struct stat st;
 
index cdce5ccef142e0450fef806a3a6bae49b84cdffa..2c406893df882a059d6b7300f4c4cbdb777ac2e2 100644 (file)
@@ -16,7 +16,7 @@
 
 TEST_RET(add_acls_for_user) {
         char fn[] = "/tmp/test-empty.XXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char *cmd;
         uid_t uid;
         int r;
index 9e50c5c7490875345c8392e6912de93abe91a160..d94173f27be55d8eb47a9f3c585279c8ca211dd7 100644 (file)
@@ -92,7 +92,7 @@ static int run(int argc, char **argv) {
 
         for (int i = optind; i < argc; i++) {
                 _cleanup_free_ char *p = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 printf("%s ", argv[i]);
                 fflush(stdout);
@@ -105,7 +105,7 @@ static int run(int argc, char **argv) {
                         if (arg_open)
                                 assert_se(fd >= 0);
                         else
-                                assert_se(fd == -1);
+                                assert_se(fd == -EBADF);
                 }
         }
 
index 8177f6e33b87e50dca66e806b4db73b69ac80d5b..2568b9b384e0e7f6a817a8ee327745acce8d31e1 100644 (file)
@@ -110,7 +110,7 @@ TEST(copy_tree_replace_dirs) {
 TEST(copy_file_fd) {
         char in_fn[] = "/tmp/test-copy-file-fd-XXXXXX";
         char out_fn[] = "/tmp/test-copy-file-fd-XXXXXX";
-        _cleanup_close_ int in_fd = -1, out_fd = -1;
+        _cleanup_close_ int in_fd = -EBADF, out_fd = -EBADF;
         const char *text = "boohoo\nfoo\n\tbar\n";
         char buf[64] = {};
 
@@ -258,7 +258,7 @@ TEST(copy_tree) {
 
 TEST(copy_bytes) {
         _cleanup_close_pair_ int pipefd[2] = {-1, -1};
-        _cleanup_close_ int infd = -1;
+        _cleanup_close_ int infd = -EBADF;
         int r, r2;
         char buf[1024], buf2[1024];
 
@@ -295,7 +295,7 @@ TEST(copy_bytes) {
 static void test_copy_bytes_regular_file_one(const char *src, bool try_reflink, uint64_t max_bytes) {
         char fn2[] = "/tmp/test-copy-file-XXXXXX";
         char fn3[] = "/tmp/test-copy-file-XXXXXX";
-        _cleanup_close_ int fd = -1, fd2 = -1, fd3 = -1;
+        _cleanup_close_ int fd = -EBADF, fd2 = -EBADF, fd3 = -EBADF;
         int r;
         struct stat buf, buf2, buf3;
 
index 432ba14825f435b8dac6cc3574e3786321dbd353..d466ba93150f07b1420899f23ca701dd798aa9c2 100644 (file)
@@ -80,7 +80,7 @@ static void assert_equal_fd(int fd1, int fd2) {
 }
 
 TEST(copy_data_fd) {
-        _cleanup_close_ int fd1 = -1, fd2 = -1;
+        _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
         _cleanup_(close_pairp) int sfd[2] = { -1, -1 };
         _cleanup_(sigkill_waitp) pid_t pid = -1;
         int r;
index df6ca13785faa5a1c5138ba8b5f49962488511a9..b546933ea45a19f8235905beefc1a59dc8986f9c 100644 (file)
@@ -59,7 +59,7 @@ TEST(close_nointr) {
 
 TEST(same_fd) {
         _cleanup_close_pair_ int p[2] = { -1, -1 };
-        _cleanup_close_ int a = -1, b = -1, c = -1;
+        _cleanup_close_ int a, b, c;
 
         assert_se(pipe2(p, O_CLOEXEC) >= 0);
         assert_se((a = fcntl(p[0], F_DUPFD, 3)) >= 0);
@@ -92,7 +92,7 @@ TEST(same_fd) {
 }
 
 TEST(open_serialization_fd) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open_serialization_fd("test");
         assert_se(fd >= 0);
@@ -389,7 +389,7 @@ TEST(format_proc_fd_path) {
 }
 
 TEST(fd_reopen) {
-        _cleanup_close_ int fd1 = -1, fd2 = -1;
+        _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
         struct stat st1, st2;
         int fl;
 
@@ -480,11 +480,11 @@ TEST(fd_reopen) {
         /* Also check the right error is generated if the fd is already closed */
         safe_close(fd1);
         assert_se(fd_reopen(fd1, O_RDONLY|O_CLOEXEC) == -EBADF);
-        fd1 = -1;
+        fd1 = -EBADF;
 }
 
 TEST(fd_reopen_condition) {
-        _cleanup_close_ int fd1 = -1, fd3 = -1;
+        _cleanup_close_ int fd1 = -EBADF, fd3 = -EBADF;
         int fd2, fl;
 
         /* Open without O_PATH */
@@ -531,42 +531,42 @@ TEST(fd_reopen_condition) {
 }
 
 TEST(take_fd) {
-        _cleanup_close_ int fd1 = -1, fd2 = -1;
-        int array[2] = { -1, -1 }, i = 0;
+        _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
+        int array[2] = { -EBADF, -EBADF }, i = 0;
 
-        assert_se(fd1 == -1);
-        assert_se(fd2 == -1);
+        assert_se(fd1 == -EBADF);
+        assert_se(fd2 == -EBADF);
 
         fd1 = eventfd(0, EFD_CLOEXEC);
         assert_se(fd1 >= 0);
 
         fd2 = TAKE_FD(fd1);
-        assert_se(fd1 == -1);
+        assert_se(fd1 == -EBADF);
         assert_se(fd2 >= 0);
 
-        assert_se(array[0] == -1);
-        assert_se(array[1] == -1);
+        assert_se(array[0] == -EBADF);
+        assert_se(array[1] == -EBADF);
 
         array[0] = TAKE_FD(fd2);
-        assert_se(fd1 == -1);
-        assert_se(fd2 == -1);
+        assert_se(fd1 == -EBADF);
+        assert_se(fd2 == -EBADF);
         assert_se(array[0] >= 0);
-        assert_se(array[1] == -1);
+        assert_se(array[1] == -EBADF);
 
         array[1] = TAKE_FD(array[i]);
-        assert_se(array[0] == -1);
+        assert_se(array[0] == -EBADF);
         assert_se(array[1] >= 0);
 
         i = 1 - i;
         array[0] = TAKE_FD(*(array + i));
         assert_se(array[0] >= 0);
-        assert_se(array[1] == -1);
+        assert_se(array[1] == -EBADF);
 
         i = 1 - i;
         fd1 = TAKE_FD(array[i]);
         assert_se(fd1 >= 0);
-        assert_se(array[0] == -1);
-        assert_se(array[1] == -1);
+        assert_se(array[0] == -EBADF);
+        assert_se(array[1] == -EBADF);
 }
 
 DEFINE_TEST_MAIN(LOG_DEBUG);
index b6ad290eef91dd055f612be8cfd92e7caf75ea51..67c99d85012eaf539c3fc17bd3c4720585084937 100644 (file)
@@ -10,7 +10,7 @@
 #include "tmpfile-util.h"
 
 TEST(fdset_new_fill) {
-        int fd = -1;
+        int fd = -EBADF;
         _cleanup_fdset_free_ FDSet *fdset = NULL;
         char name[] = "/tmp/test-fdset_new_fill.XXXXXX";
 
@@ -23,8 +23,8 @@ TEST(fdset_new_fill) {
 }
 
 TEST(fdset_put_dup) {
-        _cleanup_close_ int fd = -1;
-        int copyfd = -1;
+        _cleanup_close_ int fd = -EBADF;
+        int copyfd = -EBADF;
         _cleanup_fdset_free_ FDSet *fdset = NULL;
         char name[] = "/tmp/test-fdset_put_dup.XXXXXX";
 
@@ -42,7 +42,7 @@ TEST(fdset_put_dup) {
 }
 
 TEST(fdset_cloexec) {
-        int fd = -1;
+        int fd = -EBADF;
         _cleanup_fdset_free_ FDSet *fdset = NULL;
         int flags = -1;
         char name[] = "/tmp/test-fdset_cloexec.XXXXXX";
@@ -68,8 +68,8 @@ TEST(fdset_cloexec) {
 }
 
 TEST(fdset_close_others) {
-        int fd = -1;
-        int copyfd = -1;
+        int fd = -EBADF;
+        int copyfd = -EBADF;
         _cleanup_fdset_free_ FDSet *fdset = NULL;
         int flags = -1;
         char name[] = "/tmp/test-fdset_close_others.XXXXXX";
@@ -92,7 +92,7 @@ TEST(fdset_close_others) {
 }
 
 TEST(fdset_remove) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         FDSet *fdset = NULL;
         char name[] = "/tmp/test-fdset_remove.XXXXXX";
 
@@ -112,7 +112,7 @@ TEST(fdset_remove) {
 }
 
 TEST(fdset_iterate) {
-        int fd = -1;
+        int fd = -EBADF;
         FDSet *fdset = NULL;
         char name[] = "/tmp/test-fdset_iterate.XXXXXX";
         int c = 0;
index 6f27cd43d674fc7dc84fbd3a46727815290fe2b6..2009c0f972b9faf7614b7514cf39e9e08c77ab61 100644 (file)
@@ -525,7 +525,7 @@ TEST(search_and_fopen) {
         char name[] = "/tmp/test-search_and_fopen.XXXXXX";
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_free_ char *p = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *e;
         int r;
 
@@ -573,7 +573,7 @@ TEST(search_and_fopen_nulstr) {
         _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-search_and_fopen.XXXXXX";
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_free_ char *p = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *e;
         int r;
 
@@ -610,7 +610,7 @@ TEST(writing_tmpfile) {
         _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
         _cleanup_free_ char *contents = NULL;
         size_t size;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         struct iovec iov[] = {
@@ -909,7 +909,7 @@ TEST(read_full_file_socket) {
         if (r == 0) {
                 union sockaddr_union peer = {};
                 socklen_t peerlen = sizeof(peer);
-                _cleanup_close_ int rfd = -1;
+                _cleanup_close_ int rfd = -EBADF;
                 /* child */
 
                 rfd = accept4(listener, NULL, 0, SOCK_CLOEXEC);
index 69f630399021cc4cbcf2023cbe7bf4a818cd35d0..38299ce7298291f5f458be7e1547393b1351e9c6 100644 (file)
@@ -28,7 +28,7 @@ static const char *arg_test_dir = NULL;
 
 TEST(chase_symlinks) {
         _cleanup_free_ char *result = NULL, *pwd = NULL;
-        _cleanup_close_ int pfd = -1;
+        _cleanup_close_ int pfd = -EBADF;
         char *temp;
         const char *top, *p, *pslash, *q, *qslash;
         struct stat st;
@@ -316,7 +316,7 @@ TEST(chase_symlinks) {
 
         r = chase_symlinks(p, NULL, 0, NULL, &pfd);
         if (r != -ENOENT && sd_id128_get_machine(NULL) >= 0) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 sd_id128_t a, b;
 
                 assert_se(pfd >= 0);
@@ -553,7 +553,7 @@ TEST(dot_or_dot_dot) {
 
 TEST(access_fd) {
         _cleanup_(rmdir_and_freep) char *p = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *a;
 
         a = strjoina(arg_test_dir ?: "/tmp", "/access-fd.XXXXXX");
@@ -679,7 +679,7 @@ TEST(touch_file) {
 
 TEST(unlinkat_deallocate) {
         _cleanup_free_ char *p = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
 
         assert_se(tempfn_random_child(arg_test_dir, "unlink-deallocation", &p) >= 0);
@@ -704,7 +704,7 @@ TEST(unlinkat_deallocate) {
 }
 
 TEST(fsync_directory_of_file) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open_tmpfile_unlinkable(arg_test_dir, O_RDWR);
         assert_se(fd >= 0);
@@ -821,7 +821,7 @@ TEST(chmod_and_chown) {
 }
 
 static void create_binary_file(const char *p, const void *data, size_t l) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = open(p, O_CREAT|O_WRONLY|O_EXCL|O_CLOEXEC, 0600);
         assert_se(fd >= 0);
@@ -961,7 +961,7 @@ TEST(parse_cifs_service) {
 }
 
 TEST(open_mkdir_at) {
-        _cleanup_close_ int fd = -1, subdir_fd = -1, subsubdir_fd = -1;
+        _cleanup_close_ int fd = -EBADF, subdir_fd = -EBADF, subsubdir_fd = -EBADF;
         _cleanup_(rm_rf_physical_and_freep) char *t = NULL;
 
         assert_se(open_mkdir_at(AT_FDCWD, "/proc", O_EXCL|O_CLOEXEC, 0) == -EEXIST);
@@ -1005,7 +1005,7 @@ TEST(open_mkdir_at) {
 TEST(openat_report_new) {
         _cleanup_free_ char *j = NULL;
         _cleanup_(rm_rf_physical_and_freep) char *d = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         bool b;
 
         assert_se(mkdtemp_malloc(NULL, &d) >= 0);
index 566b68b5892dd652db250337155455518e0b7fa7..9b3e73cce017231ae6ef6a1164619a7daf46738e 100644 (file)
@@ -15,7 +15,7 @@
 
 TEST(glob_first) {
         char *first, name[] = "/tmp/test-glob_first.XXXXXX";
-        int fd = -1;
+        int fd = -EBADF;
         int r;
 
         fd = mkostemp_safe(name);
@@ -36,7 +36,7 @@ TEST(glob_first) {
 
 TEST(glob_exists) {
         char name[] = "/tmp/test-glob_exists.XXXXXX";
-        int fd = -1;
+        int fd = -EBADF;
         int r;
 
         fd = mkostemp_safe(name);
index afdbf1e4b9016329846d77c7fcfdf7e6a62c6321..0a97366b6daa37f930b60dd61c41116d8b3c3948 100644 (file)
@@ -23,7 +23,7 @@ TEST(id128) {
         sd_id128_t id, id2;
         char t[SD_ID128_STRING_MAX], q[SD_ID128_UUID_STRING_MAX];
         _cleanup_free_ char *b = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert_se(sd_id128_randomize(&id) == 0);
         printf("random: %s\n", sd_id128_to_string(id, t));
index 38ca3d858ccb5dbc1d6edc16aa9720a74fbea6ff..fd41a2a4d109f09c1773a88cdd08797b9fd33421 100644 (file)
@@ -32,7 +32,7 @@ TEST(sparse_write) {
         const char test_c[] = "\0\0test\0\0\0\0";
         const char test_d[] = "\0\0test\0\0\0test\0\0\0\0test\0\0\0\0\0test\0\0\0test\0\0\0\0test\0\0\0\0\0\0\0\0";
         const char test_e[] = "test\0\0\0\0test";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char fn[] = "/tmp/sparseXXXXXX";
 
         fd = mkostemp(fn, O_CLOEXEC);
index 6e15e1accbfb59788fd13c8070307805c97c6667..bfc327264368d010e186b03905df1a13d50cc217 100644 (file)
@@ -145,7 +145,7 @@ static int run(int argc, char *argv[]) {
         _cleanup_free_ char *p = NULL, *cmd = NULL;
         _cleanup_(pclosep) FILE *sfdisk = NULL;
         _cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         test_setup_logging(LOG_DEBUG);
index c4a87d253e915dd45e59d51f373f4545b751c6a7..ea47c3a5b3ae1bafd9d1a34250fe604b6c4f7b53 100644 (file)
@@ -276,7 +276,7 @@ TEST(path_is_mount_point) {
 }
 
 TEST(fd_is_mount_point) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
index e4d763ecd57fc5c72bc60686a8b3243ef40e029b..74f3c9c7c825da3e8feea866f363dc340a520f1f 100644 (file)
@@ -170,7 +170,7 @@ TEST(protect_kernel_logs) {
         assert_se(pid >= 0);
 
         if (pid == 0) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 fd = open("/dev/kmsg", O_RDONLY | O_CLOEXEC);
                 assert_se(fd > 0);
index 06b9793fe31a4d19f36d623d70b856d58dbe8d75..3669dcbb1230d2f2afd1b5a6e9ff2bfd9482f5c9 100644 (file)
@@ -195,7 +195,7 @@ TEST(path_equal_root) {
 TEST(find_executable_full) {
         char *p;
         char* test_file_name;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char fn[] = "/tmp/test-XXXXXX";
 
         assert_se(find_executable_full("sh", NULL, NULL, true, &p, NULL) == 0);
@@ -278,7 +278,7 @@ TEST(find_executable) {
 
 static void test_find_executable_exec_one(const char *path) {
         _cleanup_free_ char *t = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         pid_t pid;
         int r;
 
index 7e4b5d82557204f12c67fd0603fdd3823550f6a0..1864f8a750b6d43437072c60a9404344fa59daea 100644 (file)
@@ -240,7 +240,7 @@ TEST(personality) {
 
 TEST(get_process_cmdline_harder) {
         char path[] = "/tmp/test-cmdlineXXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ char *line = NULL;
         pid_t pid;
 
index 111671c5a9fc73150d82b9ea154dbb00bb8ba60d..4ce0811a8d9cdd73a163a53f549264436a6d1b89 100644 (file)
@@ -11,7 +11,7 @@
 
 TEST(read_mem_pressure) {
         _cleanup_(unlink_tempfilep) char path[] = "/tmp/pressurereadtestXXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         ResourcePressure rp;
 
         if (geteuid() != 0)
index ae311c56868295d88aa44799008e7bae63ff5963..2d06098dddfe431b41e6e313fa6b55d062754744 100644 (file)
@@ -1020,7 +1020,7 @@ TEST(restrict_suid_sgid) {
 
         if (pid == 0) {
                 char path[] = "/tmp/suidsgidXXXXXX", dir[] = "/tmp/suidsgiddirXXXXXX";
-                int fd = -1, k = -1;
+                int fd = -EBADF, k = -EBADF;
                 const char *z;
 
                 fd = mkostemp_safe(path);
index 717cb0db16d37f5898e82154a2146509e4e96935..04b5ba146d9282123a1bb1a9279d768eb91bdf8c 100644 (file)
@@ -56,7 +56,7 @@ static void test_cleanup(void) {
 static void test_misc(const char* fname) {
         _cleanup_(mac_selinux_freep) char *label = NULL, *label2 = NULL, *label3 = NULL;
         int r;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         log_info("============ %s ==========", __func__);
 
index 5262947c087e450202ebd73756f8231ccee0be5f..299463c243565de94eb08e2bea4f163be14a090d 100644 (file)
@@ -15,7 +15,7 @@
 #include "tests.h"
 
 int main(int argc, char *argv[]) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char template[] = "/tmp/sigbus-test-XXXXXX";
         void *addr = NULL;
         uint8_t *p;
index de64f920d17c6bc2d8b49132d8f659bc206ad3a3..abaae43e7240735267bdbfaa4e21f3588f98a9f2 100644 (file)
@@ -43,7 +43,7 @@ TEST(parse_sleep_config) {
 
 static int test_fiemap_one(const char *path) {
         _cleanup_free_ struct fiemap *fiemap = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         log_info("/* %s */", __func__);
index cd1e374ec82bb06bdb4414655e4fca32e4a158f1..6456316aae641ba0d3681986d5d152e806d1bbf4 100644 (file)
@@ -249,7 +249,7 @@ TEST(passfd_read) {
         /* Parent */
         char buf[64];
         struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1);
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd;
 
         pair[1] = safe_close(pair[1]);
 
@@ -293,7 +293,7 @@ TEST(passfd_contents_read) {
         /* Parent */
         char buf[64];
         struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1);
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd;
         ssize_t k;
 
         pair[1] = safe_close(pair[1]);
@@ -344,7 +344,7 @@ TEST(receive_nopassfd) {
         assert_se(streq(buf, wire_contents));
 
         /* no fd passed here, confirm it was reset */
-        assert_se(fd == -1);
+        assert_se(fd == -EBADF);
 }
 
 TEST(send_nodata_nofd) {
@@ -418,7 +418,7 @@ TEST(send_emptydata) {
 }
 
 TEST(flush_accept) {
-        _cleanup_close_ int listen_stream = -1, listen_dgram = -1, listen_seqpacket = 1, connect_stream = -1, connect_dgram = -1, connect_seqpacket = -1;
+        _cleanup_close_ int listen_stream, listen_dgram, listen_seqpacket, connect_stream, connect_dgram, connect_seqpacket;
         static const union sockaddr_union sa = { .un.sun_family = AF_UNIX };
         union sockaddr_union lsa;
         socklen_t l;
@@ -488,7 +488,7 @@ TEST(sockaddr_un_set_path) {
         _cleanup_(unlink_and_freep) char *sh = NULL;
         _cleanup_free_ char *j = NULL;
         union sockaddr_union sa;
-        _cleanup_close_ int fd1 = -1, fd2 = -1, fd3 = -1;
+        _cleanup_close_ int fd1, fd2, fd3;
 
         assert_se(mkdtemp_malloc("/tmp/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaXXXXXX", &t) >= 0);
         assert_se(strlen(t) > SUN_PATH_LEN);
index 04d52d364fd857fcaadbb09c6571fa22fe6b16bf..6b0f2d803371c3a8b50899135e0854216aa17a1f 100644 (file)
@@ -43,7 +43,7 @@ TEST(null_or_empty_path_with_root) {
 }
 
 TEST(files_same) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char name[] = "/tmp/test-files_same.XXXXXX";
         char name_alias[] = "/tmp/test-files_same.alias";
 
@@ -63,7 +63,7 @@ TEST(files_same) {
 TEST(is_symlink) {
         char name[] = "/tmp/test-is_symlink.XXXXXX";
         char name_link[] = "/tmp/test-is_symlink.link";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = mkostemp_safe(name);
         assert_se(fd >= 0);
@@ -125,7 +125,7 @@ TEST(path_is_read_only_fs) {
 }
 
 TEST(fd_is_ns) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert_se(fd_is_ns(STDIN_FILENO, CLONE_NEWNET) == 0);
         assert_se(fd_is_ns(STDERR_FILENO, CLONE_NEWNET) == 0);
index c58ac933bbf2b9d9994fe122e469c8e788e0021d..83d11f5cf65682120b8a8dc0141fedb3bb84cdfc 100644 (file)
@@ -18,7 +18,7 @@
 
 TEST(tmpfiles) {
         _cleanup_free_ char *cmd = NULL, *cmd2 = NULL, *ans = NULL, *ans2 = NULL, *d = NULL, *tmp = NULL, *line = NULL;
-        _cleanup_close_ int fd = -1, fd2 = -1;
+        _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
         const char *p = saved_argv[1] ?: "/tmp";
         char *pattern;
 
index 634baf1ae854159ffa7e840a6fecf72acf0e552a..7515da52ba98bfbc4177a04bba4664043e00b270 100644 (file)
@@ -21,7 +21,7 @@
 #define OVERLOAD_CONNECTIONS 333
 
 static int n_done = 0;
-static int block_write_fd = -1;
+static int block_write_fd = -EBADF;
 
 static int method_something(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
         _cleanup_(json_variant_unrefp) JsonVariant *ret = NULL;
index 02fba3d6ff3165f7ceff4d04aa7d4d79556a2c0e..04d23ef09b267f2fd76b4c9dec58009e2e9fcd47 100644 (file)
@@ -18,7 +18,7 @@
 TEST(getxattr_at_malloc) {
         char t[] = "/var/tmp/xattrtestXXXXXX";
         _cleanup_free_ char *value = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *x;
         int r;
 
@@ -60,7 +60,7 @@ cleanup:
 }
 
 TEST(getcrtime) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *vt;
         usec_t usec, k;
         int r;
index 999d1d385237834d1a99fdd5e08d7e7accc8429e..887b323d96a5373f0c0f770df993a765598f5184 100644 (file)
@@ -23,7 +23,7 @@
 
 static int load_clock_timestamp(uid_t uid, gid_t gid) {
         usec_t min = TIME_EPOCH * USEC_PER_SEC, ct;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         /* Let's try to make sure that the clock is always
index 44de4932fd7a3265c05340d1ff2c54d6a2e00eda..832e117096062b2b49884a1e7321d7da04510f2c 100644 (file)
@@ -177,8 +177,8 @@ static int clock_state_update(
 static int run(int argc, char * argv[]) {
         _cleanup_(sd_event_unrefp) sd_event *event = NULL;
         _cleanup_(clock_state_release) ClockState state = {
-                .timerfd_fd = -1,
-                .inotify_fd = -1,
+                .timerfd_fd = -EBADF,
+                .inotify_fd = -EBADF,
                 .run_systemd_wd = -1,
                 .run_systemd_timesync_wd = -1,
         };
index c847266ed4a5ce0da6c6d9cd7cbec4da51d06d01..f7d3978c935099eef9ee7258e9021aff85b67dfd 100644 (file)
@@ -10,7 +10,7 @@ DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(uid_gid_hash_ops, char, string_hash_
 
 static int open_passwd_file(const char *root, const char *fname, FILE **ret_file) {
         _cleanup_free_ char *p = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = chase_symlinks_and_open(fname, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC, &p);
         if (fd < 0)
index efe0e107b1467cdf381e375624b3281014f630bf..538d5273cff96230e83727961d9a3f2308ce74a4 100644 (file)
@@ -1021,7 +1021,7 @@ static int path_set_perms(
                 const char *path,
                 CreationMode creation) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(i);
         assert(path);
@@ -1094,7 +1094,7 @@ static int path_set_xattrs(
                 const char *path,
                 CreationMode creation) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(i);
         assert(path);
@@ -1240,7 +1240,7 @@ static int fd_set_acls(
 static int path_set_acls(Item *item, const char *path, CreationMode creation) {
         int r = 0;
 #if HAVE_ACL
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(item);
         assert(path);
@@ -1345,7 +1345,7 @@ static int fd_set_attribute(
                 const struct stat *st,
                 CreationMode creation) {
 
-        _cleanup_close_ int procfs_fd = -1;
+        _cleanup_close_ int procfs_fd = -EBADF;
         struct stat stbuf;
         unsigned f;
         int r;
@@ -1395,7 +1395,7 @@ static int fd_set_attribute(
 }
 
 static int path_set_attribute(Item *item, const char *path, CreationMode creation) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         if (!item->attribute_set || item->attribute_mask == 0)
                 return 0;
@@ -1429,7 +1429,7 @@ static int write_argument_data(Item *i, int fd, const char *path) {
 }
 
 static int write_one_file(Item *i, const char *path, CreationMode creation) {
-        _cleanup_close_ int fd = -1, dir_fd = -1;
+        _cleanup_close_ int fd = -EBADF, dir_fd = -EBADF;
         _cleanup_free_ char *bn = NULL;
         int r;
 
@@ -1475,7 +1475,7 @@ static int write_one_file(Item *i, const char *path, CreationMode creation) {
 }
 
 static int create_file(Item *i, const char *path) {
-        _cleanup_close_ int fd = -1, dir_fd = -1;
+        _cleanup_close_ int fd = -EBADF, dir_fd = -EBADF;
         _cleanup_free_ char *bn = NULL;
         struct stat stbuf, *st = NULL;
         CreationMode creation;
@@ -1540,7 +1540,7 @@ static int create_file(Item *i, const char *path) {
 }
 
 static int truncate_file(Item *i, const char *path) {
-        _cleanup_close_ int fd = -1, dir_fd = -1;
+        _cleanup_close_ int fd = -EBADF, dir_fd = -EBADF;
         _cleanup_free_ char *bn = NULL;
         struct stat stbuf, *st = NULL;
         CreationMode creation;
@@ -1629,7 +1629,7 @@ static int truncate_file(Item *i, const char *path) {
 }
 
 static int copy_files(Item *i) {
-        _cleanup_close_ int dfd = -1, fd = -1;
+        _cleanup_close_ int dfd = -EBADF, fd = -EBADF;
         _cleanup_free_ char *bn = NULL;
         struct stat st, a;
         int r;
@@ -1684,7 +1684,7 @@ static int create_directory_or_subvolume(
                 CreationMode *ret_creation) {
 
         _cleanup_free_ char *bn = NULL;
-        _cleanup_close_ int pfd = -1;
+        _cleanup_close_ int pfd = -EBADF;
         CreationMode creation;
         struct stat st;
         int r, fd;
@@ -1761,7 +1761,7 @@ static int create_directory_or_subvolume(
 }
 
 static int create_directory(Item *i, const char *path) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         CreationMode creation;
         struct stat st;
 
@@ -1778,7 +1778,7 @@ static int create_directory(Item *i, const char *path) {
 }
 
 static int create_subvolume(Item *i, const char *path) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         CreationMode creation;
         struct stat st;
         int r, q = 0;
@@ -1817,7 +1817,7 @@ static int create_subvolume(Item *i, const char *path) {
 }
 
 static int empty_directory(Item *i, const char *path, CreationMode creation) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
         int r;
 
@@ -1847,7 +1847,7 @@ static int empty_directory(Item *i, const char *path, CreationMode creation) {
 }
 
 static int create_device(Item *i, mode_t file_type) {
-        _cleanup_close_ int dfd = -1, fd = -1;
+        _cleanup_close_ int dfd = -EBADF, fd = -EBADF;
         _cleanup_free_ char *bn = NULL;
         CreationMode creation;
         struct stat st;
@@ -1952,7 +1952,7 @@ handle_privilege:
 }
 
 static int create_fifo(Item *i) {
-        _cleanup_close_ int pfd = -1, fd = -1;
+        _cleanup_close_ int pfd = -EBADF, fd = -EBADF;
         _cleanup_free_ char *bn = NULL;
         CreationMode creation;
         struct stat st;
@@ -2037,7 +2037,7 @@ static int create_fifo(Item *i) {
 }
 
 static int create_symlink(Item *i) {
-        _cleanup_close_ int pfd = -1, fd = -1;
+        _cleanup_close_ int pfd = -EBADF, fd = -EBADF;
         _cleanup_free_ char *bn = NULL;
         CreationMode creation;
         struct stat st;
@@ -2223,7 +2223,7 @@ static int glob_item_recursively(Item *i, fdaction_t action) {
                 return log_error_errno(k, "glob(%s) failed: %m", i->path);
 
         STRV_FOREACH(fn, g.gl_pathv) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 /* Make sure we won't trigger/follow file object (such as
                  * device nodes, automounts, ...) pointed out by 'fn' with
@@ -2243,7 +2243,7 @@ static int glob_item_recursively(Item *i, fdaction_t action) {
                         r = k;
 
                 /* we passed fd ownership to the previous call */
-                fd = -1;
+                fd = -EBADF;
         }
 
         return r;
@@ -2306,7 +2306,7 @@ static int rm_if_wrong_type_safe(
                                 "Not removing  \"%s/%s\" because it is a mount point.", strna(parent_name), name);
 
         if ((st.st_mode & S_IFMT) == S_IFDIR) {
-                _cleanup_close_ int child_fd = -1;
+                _cleanup_close_ int child_fd = -EBADF;
 
                 child_fd = openat(parent_fd, name, O_NOCTTY | O_CLOEXEC | O_DIRECTORY);
                 if (child_fd < 0)
@@ -2329,7 +2329,7 @@ static int rm_if_wrong_type_safe(
 
 /* If child_mode is non-zero, rm_if_wrong_type_safe will be executed for the last path component. */
 static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
-        _cleanup_close_ int parent_fd = -1;
+        _cleanup_close_ int parent_fd = -EBADF;
         struct stat parent_st;
         size_t path_len;
         int r;
@@ -2357,7 +2357,7 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
 
         /* Check every parent directory in the path, except the last component */
         for (const char *e = path;;) {
-                _cleanup_close_ int next_fd = -1;
+                _cleanup_close_ int next_fd = -EBADF;
                 char t[path_len + 1];
                 const char *s;
 
index c7609d7d79ddbd99ef608219ac33942fa5c4d918..9166e1f9ecd09c7c349268701e21101609ed7e06 100644 (file)
@@ -56,7 +56,7 @@ static const char *arg_device = NULL;
 
 static int send_passwords(const char *socket_name, char **passwords) {
         _cleanup_(erase_and_freep) char *packet = NULL;
-        _cleanup_close_ int socket_fd = -1;
+        _cleanup_close_ int socket_fd = -EBADF;
         union sockaddr_union sa;
         socklen_t sa_len;
         size_t packet_length = 1;
@@ -97,7 +97,7 @@ static int send_passwords(const char *socket_name, char **passwords) {
 
 static bool wall_tty_match(const char *path, bool is_local, void *userdata) {
         _cleanup_free_ char *p = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
 
         assert(path_is_absolute(path));
@@ -142,7 +142,7 @@ static int agent_ask_password_tty(
                 const char *flag_file,
                 char ***ret) {
 
-        int tty_fd = -1, r;
+        int tty_fd = -EBADF, r;
         const char *con = arg_device ?: "/dev/console";
 
         if (arg_console) {
@@ -337,8 +337,8 @@ static int process_and_watch_password_files(bool watch) {
                 _FD_MAX
         };
 
-        _unused_ _cleanup_close_ int tty_block_fd = -1;
-        _cleanup_close_ int notify = -1, signal_fd = -1;
+        _unused_ _cleanup_close_ int tty_block_fd = -EBADF;
+        _cleanup_close_ int notify = -1, signal_fd = -EBADF;
         struct pollfd pollfd[_FD_MAX];
         sigset_t mask;
         int r;
index bae4d03b4f43b66fdbc0b551ca9e1b15e8ccda56..6a631e515cd5739dd32548a3fdfa5a226f926d90 100644 (file)
@@ -399,7 +399,7 @@ int main(int argc, char *argv[]) {
         char revision[9];
         const char *node = NULL;
         int export = 0;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         uint16_t word;
         int is_packet_device = 0;
         static const struct option options[] = {
index 5945dcbbaec304405b7bd4e6e234e7fac7636e72..ea420a961716a45bd53ff278a5d33664abf12f91 100644 (file)
@@ -103,7 +103,7 @@ typedef struct Context {
 } Context;
 
 #define CONTEXT_EMPTY {                                 \
-                .fd = -1,                               \
+                .fd = -EBADF,                           \
                 .media_feature = _FEATURE_INVALID,      \
                 .media_state = _MEDIA_STATE_INVALID,    \
         }
index 58a282781809ca44442d2d894cbad6cd3c62ee8b..f2fbc38003a697ae152837606893b33ed6f683b4 100644 (file)
@@ -28,7 +28,7 @@
 static int run(int argc, char **argv) {
         _cleanup_(sd_device_unrefp) struct sd_device *device = NULL;
         _cleanup_free_ char *desc_path = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         struct sd_device *hid_device;
         const char *sys_path;
index d5fb64f1948a31f16718c61b1227b3a3fbb474b6..a7210a05e3cc4f28bb73fa22cc96aee1054d5c8e 100644 (file)
@@ -33,7 +33,7 @@
 #include "mtd_probe.h"
 
 int main(int argc, char** argv) {
-        _cleanup_close_ int mtd_fd = -1;
+        _cleanup_close_ int mtd_fd = -EBADF;
         mtd_info_t mtd_info;
 
         if (argc != 2) {
index 25edb49d28a81584c0ae3707812f629f7d40e603..5f18ba35fc38b4ae9ea9564e9e8b17b96a6e4b3b 100644 (file)
@@ -97,7 +97,7 @@ int link_config_ctx_new(LinkConfigContext **ret) {
                 return -ENOMEM;
 
         *ctx = (LinkConfigContext) {
-                .ethtool_fd = -1,
+                .ethtool_fd = -EBADF,
         };
 
         *ret = TAKE_PTR(ctx);
index f1ce8601bd8257dabe32ba8600268425ddb663e4..c619506877c8cba092f4478ac26a3f3c1ca5aa05 100644 (file)
@@ -786,7 +786,7 @@ out:
 int scsi_get_serial(struct scsi_id_device *dev_scsi, const char *devname,
                     int page_code, int len) {
         unsigned char page0[SCSI_INQ_BUFF_LEN];
-        int fd = -1;
+        int fd = -EBADF;
         int cnt;
         int ind;
         int retval;
index 9b5dfbe33be4c6dd4eefde258e354457a403e7d9..d2de03d5f9b23e21e507e0e6efd5b32fb0c71fd5 100644 (file)
@@ -238,7 +238,7 @@ static int builtin_blkid(sd_device *dev, sd_netlink **rtnl, int argc, char *argv
         const char *devnode, *root_partition = NULL, *data, *name;
         _cleanup_(blkid_free_probep) blkid_probe pr = NULL;
         bool noraid = false, is_gpt = false;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int64_t offset = 0;
         int r;
 
index faaafb23f665958eb8ec5f7a16e31e7c2e565830..79f91ea2ae52184d6cf0fdef8616858392adea74 100644 (file)
@@ -14,7 +14,7 @@
 
 static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
         struct btrfs_ioctl_vol_args args = {};
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         if (argc != 3 || !streq(argv[1], "ready"))
index 465913ce31f9f850978b1d14c261c2aded1d03eb..33184b024f4c4fc965bd2ca3067d28cecbf36860 100644 (file)
@@ -47,7 +47,7 @@ static int abs_size_mm(const struct input_absinfo *absinfo) {
 static void extract_info(sd_device *dev, bool test) {
         char width[DECIMAL_STR_MAX(int)], height[DECIMAL_STR_MAX(int)];
         struct input_absinfo xabsinfo = {}, yabsinfo = {};
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0)
index e67a02aee6e063e91f38b24990688b062da7ad9c..80cfdee0c188e99099b0a261927c773747b4552a 100644 (file)
@@ -162,7 +162,7 @@ static int set_trackpoint_sensitivity(sd_device *dev, const char *value) {
 static int builtin_keyboard(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
         unsigned release[1024];
         unsigned release_count = 0;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *node, *key, *value;
         int has_abs = -1, r;
 
index 847c2b8316b2b1e517e8f8696ca25ea3369812e5..91deb64292e81c01406abd9ba2509a722cb64c9c 100644 (file)
@@ -134,7 +134,7 @@ static void set_scsi_type(char *to, const char *from, size_t len) {
 #define USB_DT_INTERFACE                0x04
 
 static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         ssize_t size;
         unsigned char buf[18 + 65535];
         size_t pos = 0;
index 9e34ea6b01f4ffbe50aed3931aa660164f46ba9d..1990282c75427e6678836f6485f8f7a2a1b3d6c2 100644 (file)
@@ -281,7 +281,7 @@ static int stack_directory_update(sd_device *dev, int fd, bool add) {
 }
 
 static int stack_directory_open(const char *dirname) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         int r;
 
         assert(dirname);
@@ -298,7 +298,7 @@ static int stack_directory_open(const char *dirname) {
 }
 
 static int stack_directory_lock(int dirfd) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
 
         assert(dirfd >= 0);
 
@@ -387,7 +387,7 @@ static int stack_directory_get_name(const char *slink, char **ret) {
 
 static int link_update(sd_device *dev, const char *slink, bool add) {
         _cleanup_free_ char *dirname = NULL, *devnode = NULL;
-        _cleanup_close_ int dirfd = -1, lockfd = -1;
+        _cleanup_close_ int dirfd = -EBADF, lockfd = -EBADF;
         int r;
 
         assert(dev);
@@ -624,7 +624,7 @@ int udev_node_apply_permissions(
                 OrderedHashmap *seclabel_list) {
 
         const char *devnode;
-        _cleanup_close_ int node_fd = -1;
+        _cleanup_close_ int node_fd = -EBADF;
         int r;
 
         assert(dev);
@@ -654,7 +654,7 @@ int static_node_apply_permissions(
                 char **tags) {
 
         _cleanup_free_ char *unescaped_filename = NULL;
-        _cleanup_close_ int node_fd = -1;
+        _cleanup_close_ int node_fd = -EBADF;
         const char *devnode;
         struct stat stats;
         int r;
index 6bb013c094f8452722d6d30d28f3b7262296a207..d00226cd7a42c2f7c4b4bf3b5defdecf3c994f7e 100644 (file)
@@ -174,7 +174,7 @@ finalize:
 
 int udev_watch_begin(int inotify_fd, sd_device *dev) {
         char wd_str[DECIMAL_STR_MAX(int)];
-        _cleanup_close_ int dirfd = -1;
+        _cleanup_close_ int dirfd = -EBADF;
         const char *devnode, *id;
         int wd, r;
 
@@ -229,7 +229,7 @@ on_failure:
 }
 
 int udev_watch_end(int inotify_fd, sd_device *dev) {
-        _cleanup_close_ int dirfd = -1;
+        _cleanup_close_ int dirfd = -EBADF;
         int wd, r;
 
         assert(dev);
index 35e9999c015e9577b2955c3e3348e709f3e432ca..d19e7561f81f166cabefc3007f732d8ee3d56e6c 100644 (file)
@@ -176,7 +176,7 @@ static int lock_device(
                 dev_t devno,
                 usec_t deadline) {
 
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         struct stat st;
         int r;
 
@@ -328,7 +328,7 @@ int lock_main(int argc, char *argv[], void *userdata) {
                 if (arg_print)
                         printf("%s\n", node);
                 else {
-                        _cleanup_close_ int fd = -1;
+                        _cleanup_close_ int fd = -EBADF;
 
                         fd = lock_device(node, devnos[i], deadline);
                         if (fd < 0)
index eb15b250d56f30e1d787f890d257d78b1aa847c2..0de5b4ec643f35785ac05c7c409acf36fda67767 100644 (file)
@@ -513,7 +513,7 @@ irrelevant:
 }
 
 static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         sd_device *dev_whole_disk;
         const char *val;
         int r;
@@ -550,12 +550,12 @@ static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) {
         return 1;
 
 nolock:
-        *ret_fd = -1;
+        *ret_fd = -EBADF;
         return 0;
 }
 
 static int worker_mark_block_device_read_only(sd_device *dev) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         const char *val;
         int state = 1, r;
 
@@ -600,7 +600,7 @@ static int worker_mark_block_device_read_only(sd_device *dev) {
 
 static int worker_process_device(Manager *manager, sd_device *dev) {
         _cleanup_(udev_event_freep) UdevEvent *udev_event = NULL;
-        _cleanup_close_ int fd_lock = -1;
+        _cleanup_close_ int fd_lock = -EBADF;
         int r;
 
         assert(manager);
@@ -1561,7 +1561,7 @@ static int on_post(sd_event_source *s, void *userdata) {
 }
 
 static int listen_fds(int *ret_ctrl, int *ret_netlink) {
-        int ctrl_fd = -1, netlink_fd = -1;
+        int ctrl_fd = -EBADF, netlink_fd = -EBADF;
         int fd, n;
 
         assert(ret_ctrl);
@@ -1847,7 +1847,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent) {
                 return log_oom();
 
         *manager = (Manager) {
-                .inotify_fd = -1,
+                .inotify_fd = -EBADF,
                 .worker_watch = { -1, -1 },
                 .cgroup = TAKE_PTR(cgroup),
         };
@@ -1993,7 +1993,7 @@ static int main_loop(Manager *manager) {
 
 int run_udevd(int argc, char *argv[]) {
         _cleanup_(manager_freep) Manager *manager = NULL;
-        int fd_ctrl = -1, fd_uevent = -1;
+        int fd_ctrl = -EBADF, fd_uevent = -EBADF;
         int r;
 
         log_set_target(LOG_TARGET_AUTO);
index 13b4839989f919842c1f414e4d4fc6e1568c765f..4f163c43509e66567bd120b1274084da9cae6fc0 100644 (file)
@@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
                 { "help", no_argument, NULL, 'h' },
                 {}
         };
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char *device;
         struct v4l2_capability v2cap;
         int c;
index 675526f3ace066cc11bc0dd7c2ee6afd7c3f3940..7449a2321c5a715e95d2876499cf127587dc55db 100644 (file)
@@ -39,7 +39,7 @@ static void context_clear(Context *c) {
 #if HAVE_AUDIT
         if (c->audit_fd >= 0)
                 audit_close(c->audit_fd);
-        c->audit_fd = -1;
+        c->audit_fd = -EBADF;
 #endif
 }
 
@@ -221,7 +221,7 @@ static int on_runlevel(Context *c) {
 static int run(int argc, char *argv[]) {
         _cleanup_(context_clear) Context c = {
 #if HAVE_AUDIT
-                .audit_fd = -1,
+                .audit_fd = -EBADF,
 #endif
         };
         int r;
index 49bdaf666f646db16070b2d91c26856d436bfb65..b728cdc1c369d5100efa5be2c70f64c745bfacb6 100644 (file)
@@ -931,7 +931,7 @@ static int display_services(int argc, char *argv[], void *userdata) {
 
         FOREACH_DIRENT(de, d, return -errno) {
                 _cleanup_free_ char *j = NULL, *no = NULL;
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 j = path_join("/run/systemd/userdb/", de->d_name);
                 if (!j)
index 81d3f6407c9d5f61e2d960a8840f1a8eb8e9ad5e..7890d047c49742b21e66c6500780a7b967164367 100644 (file)
@@ -83,7 +83,7 @@ int manager_new(Manager **ret) {
                 return -ENOMEM;
 
         *m = (Manager) {
-                .listen_fd = -1,
+                .listen_fd = -EBADF,
                 .worker_ratelimit = {
                         .interval = 5 * USEC_PER_SEC,
                         .burst = 50,
index 21a869df1b5ce5a068466046e6d9c978ef76317d..9fccadc9501a263f446c629436ccbbfb056a5ce0 100644 (file)
@@ -503,7 +503,7 @@ static int run(int argc, char *argv[]) {
         start_time = now(CLOCK_MONOTONIC);
 
         for (;;) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
                 usec_t n;
 
                 /* Exit the worker in regular intervals, to flush out all memory use */
index 98f978df0af0208ca2d6927ebf7d22391623a6cf..ecc859a2c35bc8e7aa7333cf1438ab6a7c78c2ab 100644 (file)
@@ -278,7 +278,7 @@ static void setup_remaining_vcs(int src_fd, unsigned src_idx, bool utf8) {
 
         for (i = 1; i <= 63; i++) {
                 char ttyname[sizeof("/dev/tty63")];
-                _cleanup_close_ int fd_d = -1;
+                _cleanup_close_ int fd_d = -EBADF;
 
                 if (i == src_idx || verify_vc_allocation(i) < 0)
                         continue;
@@ -350,7 +350,7 @@ static int find_source_vc(char **ret_path, unsigned *ret_idx) {
                 return log_oom();
 
         for (i = 1; i <= 63; i++) {
-                _cleanup_close_ int fd = -1;
+                _cleanup_close_ int fd = -EBADF;
 
                 r = verify_vc_allocation(i);
                 if (r < 0) {
@@ -383,7 +383,7 @@ static int find_source_vc(char **ret_path, unsigned *ret_idx) {
 }
 
 static int verify_source_vc(char **ret_path, const char *src_vc) {
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         char *path;
         int r;
 
@@ -416,7 +416,7 @@ int main(int argc, char **argv) {
                 *vc = NULL,
                 *vc_keymap = NULL, *vc_keymap_toggle = NULL,
                 *vc_font = NULL, *vc_font_map = NULL, *vc_font_unimap = NULL;
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         bool utf8, keyboard_ok;
         unsigned idx = 0;
         int r;
index 084c9073070e7e608b9f5bbb3f464adad1e52c83..b1b035d94e777bbb0f7f27824a7cc04f27915530 100644 (file)
@@ -13,7 +13,7 @@
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         _cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-xdg-desktop.XXXXXX";
-        _cleanup_close_ int fd = -1;
+        _cleanup_close_ int fd = -EBADF;
         _cleanup_(xdg_autostart_service_freep) XdgAutostartService *service = NULL;
         _cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;