From a1de7e8e08246a6842e62da82383eb8920689ee4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 20 May 2020 18:20:47 -0700 Subject: [PATCH] ircd::fs::fd: Replace open(2) with openat(2); additional constructor. --- include/ircd/fs/fd.h | 1 + ircd/fs.cc | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/ircd/fs/fd.h b/include/ircd/fs/fd.h index 282f86a93..80b81b207 100644 --- a/include/ircd/fs/fd.h +++ b/include/ircd/fs/fd.h @@ -42,6 +42,7 @@ struct ircd::fs::fd int release() noexcept; explicit fd(const int &); + fd(const int &dirfd, const string_view &path, const opts &); fd(const string_view &path, const opts &); fd(const string_view &path); fd() = default; diff --git a/ircd/fs.cc b/ircd/fs.cc index 1a33fe259..30155afdf 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -1994,19 +1994,38 @@ ircd::fs::fd::opts::opts(const std::ios::openmode &mode) // ircd::fs::fd::fd(const int &fdno) -:fdno{fdno} +:fdno +{ + fdno +} { } ircd::fs::fd::fd(const string_view &path) -:fd{path, opts{}} +:fd +{ + path, opts{} +} { } ircd::fs::fd::fd(const string_view &path, const opts &opts) +:fd +{ + AT_FDCWD, path, opts +} +{ +} + +ircd::fs::fd::fd(const int &dirfd, + const string_view &path, + const opts &opts) try -:fdno{-1} +:fdno +{ + -1 // sentinel value for inert dtor +} { const mode_t mode { @@ -2033,11 +2052,11 @@ try const prof::syscall_usage_warning message { - "fs::fs::fd(): open(2): %s", path + "fs::fs::fd(): openat(2): %s", path }; assert((flags & ~O_CREAT) || mode != 0); - fdno = syscall(::open, path_cstr(path), flags, mode); + fdno = syscall(::openat, dirfd, path_cstr(path), flags, mode); if(advise) fs::advise(*this, advise);