Merge pull request #25786 from keszybz/ebadf

Use -EBADF for fd initialization
This commit is contained in:
Yu Watanabe
2022-12-20 10:02:10 +09:00
committed by GitHub
301 changed files with 878 additions and 878 deletions
+8 -8
View 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);
+2 -2
View 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);
+2 -2
View 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;
+1 -1
View File
@@ -381,7 +381,7 @@ int parse_env_file_fd_sentinel(
const char *fname, /* only used for logging */
...) {
_cleanup_close_ int fd_ro = -EBADFD;
_cleanup_close_ int fd_ro = -EBADF;
_cleanup_fclose_ FILE *f = NULL;
va_list ap;
int r;
+25 -29
View 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;
@@ -631,25 +629,23 @@ int fd_move_above_stdio(int fd) {
}
int rearrange_stdio(int original_input_fd, int original_output_fd, int original_error_fd) {
int fd[3] = { /* Put together an array of fds we work on */
original_input_fd,
original_output_fd,
original_error_fd
};
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 */
int fd[3] = { original_input_fd, /* Put together an array of fds we work on */
original_output_fd,
original_error_fd },
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. */
r;
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!
*
@@ -685,7 +681,7 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
}
/* Let's assemble fd[] with the fds to install in place of stdin/stdout/stderr */
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
if (fd[i] < 0)
fd[i] = null_fd; /* A negative parameter means: connect this one to /dev/null */
@@ -701,10 +697,10 @@ 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. */
for (i = 0; i < 3; i++) {
/* 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 (int i = 0; i < 3; i++) {
if (fd[i] == i) {
@@ -735,7 +731,7 @@ finish:
safe_close_above_stdio(original_error_fd);
/* Close the copies we moved > 2 */
for (i = 0; i < 3; i++)
for (int i = 0; i < 3; i++)
safe_close(copy_fd[i]);
/* Close our null fd, if it's > 2 */
@@ -800,7 +796,7 @@ int fd_reopen_condition(
return -errno;
if ((r & mask) == (flags & mask)) {
*ret_new_fd = -1;
*ret_new_fd = -EBADF;
return fd;
}
+1 -1
View File
@@ -94,7 +94,7 @@ static inline int make_null_stdio(void) {
({ \
int *_fd_ = &(fd); \
int _ret_ = *_fd_; \
*_fd_ = -1; \
*_fd_ = -EBADF; \
_ret_; \
})
+5 -5
View 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);
+5 -5
View 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;
+1 -1
View 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;
+4 -4
View 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) {
+1 -1
View 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);
+2 -2
View 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)
+3 -3
View 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
+4 -4
View 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);
+1 -1
View 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;
+2 -2
View 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;
+4 -4
View 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);
+2 -2
View 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);
+2 -2
View 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,
};
+2 -2
View 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;
@@ -183,7 +183,7 @@ static int fd_is_read_only_fs(int fd) {
}
int path_is_read_only_fs(const char *path) {
_cleanup_close_ int fd = -EBADFD;
_cleanup_close_ int fd = -EBADF;
assert(path);
+5 -5
View 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)
+12 -12
View 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,8 +1129,8 @@ 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_pair_ int pair[2] = { -1, -1 };
_cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF, fd = -EBADF;
_cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
pid_t child;
int r;
@@ -1182,8 +1182,8 @@ 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_pair_ int pair[2] = { -1, -1 };
_cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
_cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
pid_t child;
int r;
+2 -2
View 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));
+3 -3
View 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);
+2 -2
View 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;