summaryrefslogtreecommitdiff
path: root/src/basic/fd-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/fd-util.c')
-rw-r--r--src/basic/fd-util.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c
index 9130d023d7..8b466cff15 100644
--- a/src/basic/fd-util.c
+++ b/src/basic/fd-util.c
@@ -361,8 +361,14 @@ bool fdname_is_valid(const char *s) {
int fd_get_path(int fd, char **ret) {
char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
+ int r;
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
- return readlink_malloc(procfs_path, ret);
+ r = readlink_malloc(procfs_path, ret);
+
+ if (r == -ENOENT) /* If the file doesn't exist the fd is invalid */
+ return -EBADF;
+
+ return r;
}