diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-12-19 13:07:42 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-12-19 15:00:57 +0100 |
commit | 254d1313ae5a69c08c9b93032aaaf3d6083cfc07 (patch) | |
tree | 067102a36abe6bf597c26a42d79018a1060c9007 /src/tmpfiles | |
parent | sd-event: never pass negative errnos as signalfd to signalfd (diff) | |
download | systemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.tar.xz systemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.zip |
tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.
Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state
Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.
In some places, initialization is dropped if unnecessary.
Diffstat (limited to 'src/tmpfiles')
-rw-r--r-- | src/tmpfiles/offline-passwd.c | 2 | ||||
-rw-r--r-- | src/tmpfiles/tmpfiles.c | 42 |
2 files changed, 22 insertions, 22 deletions
diff --git a/src/tmpfiles/offline-passwd.c b/src/tmpfiles/offline-passwd.c index c847266ed4..f7d3978c93 100644 --- a/src/tmpfiles/offline-passwd.c +++ b/src/tmpfiles/offline-passwd.c @@ -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) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index efe0e107b1..538d5273cf 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -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; |