Message ID | 64fd9c35244a9d3ed56f77b049accb00b9ec95e9.1375952089.git.ydroneaud@opteya.com (mailing list archive) |
---|---|
State | Rejected |
Headers | show |
On Thu, Aug 08, 2013 at 09:40:51PM +0200, Yann Droneaud wrote: > @@ -325,7 +325,7 @@ static void read_config(void) > struct dirent *dent; > struct stat buf; > > - conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_CLOEXEC); > + conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); > if (conf_dirfd == -1) { > fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n", > IBV_CONFIG_DIR); It is much better to keep the original opendir code and then use dirfd to get the directory file no for later use with fstat/openat/etc. glibc already knows to use non-portable things like O_DIRECTORY and O_CLOEXEC inside opendir. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/configure.ac b/configure.ac index b8d4cea..9544726 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,12 @@ AC_CHECK_HEADERS([fcntl.h sys/socket.h]) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST +AC_CHECK_DECLS([O_DIRECTORY],,[AC_DEFINE([O_DIRECTORY],[0], [Defined to 0 if not provided])], +[[ +#ifdef HAVE_FCNTL_H +# include <fcntl.h> +#endif +]]) AC_CHECK_DECLS([O_CLOEXEC],,[AC_DEFINE([O_CLOEXEC],[0], [Defined to 0 if not provided])], [[ #ifdef HAVE_FCNTL_H diff --git a/src/init.c b/src/init.c index 0e3cdf0..c2e7bfb 100644 --- a/src/init.c +++ b/src/init.c @@ -325,7 +325,7 @@ static void read_config(void) struct dirent *dent; struct stat buf; - conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_CLOEXEC); + conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); if (conf_dirfd == -1) { fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n", IBV_CONFIG_DIR);
O_DIRECTORY is an option to open() to ensure the given path is a directory. If IBV_CONFIG_DIR path is not pointing to a directory, open() will failed. Note: if IBV_CONFIG_DIR is a symlink, it will be followed. O_DIRECTORY doesn't disable path resolution. See open()[1][2] for more information. Links: - [1] open <http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html> - [2] open(2) <http://man7.org/linux/man-pages/man2/open.2.html> Signed-off-by: Yann Droneaud <ydroneaud@opteya.com> --- configure.ac | 6 ++++++ src/init.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)