mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
fs-util: check for /proc mounted in access_fd()
It's a very basic function very similar to other cases where we go via /proc/self/fd/, hence do the explicit proc_mounted() check here too.
This commit is contained in:
parent
48d837cd92
commit
4265a66a5e
@ -1298,16 +1298,25 @@ int chase_symlinks_and_stat(
|
||||
|
||||
int access_fd(int fd, int mode) {
|
||||
char p[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(fd) + 1];
|
||||
int r;
|
||||
|
||||
/* Like access() but operates on an already open fd */
|
||||
|
||||
xsprintf(p, "/proc/self/fd/%i", fd);
|
||||
r = access(p, mode);
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
if (access(p, mode) < 0) {
|
||||
if (errno != ENOENT)
|
||||
return -errno;
|
||||
|
||||
return r;
|
||||
/* ENOENT can mean two things: that the fd does not exist or that /proc is not mounted. Let's
|
||||
* make things debuggable and distinguish the two. */
|
||||
|
||||
if (proc_mounted() == 0)
|
||||
return -ENOSYS; /* /proc is not available or not set up properly, we're most likely in some chroot
|
||||
* environment. */
|
||||
|
||||
return -EBADF; /* The directory exists, hence it's the fd that doesn't. */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unlink_tempfilep(char (*p)[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user