1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-21 19:34:19 +02:00

(fd_to_subdirp): Open with O_DIRECTORY | O_NOCTTY

| O_NOFOLLOW too, for consistency with other dir-openers.
Use POSIX-preferred O_NONBLOCK rather than O_NDELAY.
(is_empty_dir): Likewise.
This commit is contained in:
Paul Eggert
2005-12-27 07:59:27 +00:00
parent da4c548bbb
commit 40ea51a322

View File

@@ -578,15 +578,16 @@ AD_is_removable (Dirstack_state const *ds, char const *file)
return ! (top->unremovable && hash_lookup (top->unremovable, file));
}
/* Return true if DIR is determined to be an empty directory
or if fdopendir or readdir fails. */
/* Return true if DIR is determined to be an empty directory. */
static bool
is_empty_dir (int fd_cwd, char const *dir)
{
DIR *dirp;
struct dirent const *dp;
int saved_errno;
int fd = openat (fd_cwd, dir, O_RDONLY | O_NDELAY);
int fd = openat (fd_cwd, dir,
(O_RDONLY | O_DIRECTORY
| O_NOCTTY | O_NOFOLLOW | O_NONBLOCK));
if (fd < 0)
return false;
@@ -987,8 +988,8 @@ fd_to_subdirp (int fd_cwd, char const *f,
struct stat *subdir_sb, Dirstack_state *ds,
int *cwd_errno ATTRIBUTE_UNUSED)
{
int fd_sub = openat_permissive (fd_cwd, f, O_RDONLY | O_NOFOLLOW,
0, cwd_errno);
int open_flags = O_RDONLY | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK;
int fd_sub = openat_permissive (fd_cwd, f, open_flags, 0, cwd_errno);
/* Record dev/ino of F. We may compare them against saved values
to thwart any attempt to subvert the traversal. They are also used