@@ -45,6 +45,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
@@ -292,14 +293,23 @@ static void read_config_file(const char *path)
static void read_config(void)
{
+ int conf_dirfd;
DIR *conf_dir;
struct dirent *dent;
char *path;
- conf_dir = opendir(IBV_CONFIG_DIR);
+ conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_CLOEXEC);
+ if (conf_dirfd == -1) {
+ fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n",
+ IBV_CONFIG_DIR);
+ return;
+ }
+
+ conf_dir = fdopendir(conf_dirfd);
if (!conf_dir) {
fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n",
IBV_CONFIG_DIR);
+ close(conf_dirfd);
return;
}
Get a file descriptor pointing to the IBV_CONFIG_DIR, so that it could be used with fstatat() and openat() later. Use fdopendir()[1][2] after open()'ing the directory instead of opendir(). Compatibility note: - According to Gnulib, fdopendir() is not available on older systems. <http://www.gnu.org/software/gnulib/manual/html_node/fdopendir.html> Links: - [1] fdopendir <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopendir.html> - [2] fdopendir(3) <http://man7.org/linux/man-pages/man3/fdopendir.3.html> Signed-off-by: Yann Droneaud <ydroneaud@opteya.com> --- src/init.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)