Library must use O_CLOEXEC whenever it opens file descriptors
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 6b6911b..8d70314 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -710,7 +710,7 @@
if (flags != 0)
INFO(mod->ctx, "Flags are not implemented yet\n");
- if ((fd = open(mod->path, O_RDONLY)) < 0) {
+ if ((fd = open(mod->path, O_RDONLY|O_CLOEXEC)) < 0) {
err = -errno;
return err;
}
@@ -984,7 +984,7 @@
if (ctx == NULL || list == NULL)
return -ENOENT;
- fp = fopen("/proc/modules", "r");
+ fp = fopen("/proc/modules", "re");
if (fp == NULL) {
int err = -errno;
ERR(ctx, "could not open /proc/modules: %s\n", strerror(errno));
@@ -1063,7 +1063,7 @@
pathlen = snprintf(path, sizeof(path),
"/sys/module/%s/initstate", mod->name);
- fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
err = -errno;
@@ -1118,7 +1118,7 @@
if (mod == NULL)
return -ENOENT;
- fp = fopen("/proc/modules", "r");
+ fp = fopen("/proc/modules", "re");
if (fp == NULL) {
int err = -errno;
ERR(mod->ctx,
@@ -1174,7 +1174,7 @@
return -ENOENT;
snprintf(path, sizeof(path), "/sys/module/%s/refcnt", mod->name);
- fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
err = -errno;
ERR(mod->ctx, "could not open '%s': %s\n",