]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Library must use O_CLOEXEC whenever it opens file descriptors
authorCristian Rodríguez <crrodriguez@opensuse.org>
Fri, 16 Dec 2011 05:49:54 +0000 (02:49 -0300)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 16 Dec 2011 06:16:09 +0000 (04:16 -0200)
libkmod/libkmod-config.c
libkmod/libkmod-index.c
libkmod/libkmod-module.c

index efeb89dc2d4e7bb0a2a5ec9cb3ac9d05a9fabc6d..1ba14cc5d8c9c0a9a36566f0fdddba23710a4912 100644 (file)
@@ -270,7 +270,7 @@ static int kmod_config_parse_kcmdline(struct kmod_config *config)
        int fd, err;
        char *p, *modname,  *param = NULL, *value = NULL;
 
-       fd = open("/proc/cmdline", O_RDONLY);
+       fd = open("/proc/cmdline", O_RDONLY|O_CLOEXEC);
        err = read_str_safe(fd, buf, sizeof(buf));
        close(fd);
        if (err < 0) {
index 5c25266b491fd3e83fd3e140374275d1bcf9c321..7f0c0923a39fd9174f024a3e4bc27dc6bd783b00 100644 (file)
@@ -336,7 +336,7 @@ struct index_file *index_file_open(const char *filename)
        uint32_t magic, version;
        struct index_file *new;
 
-       file = fopen(filename, "r");
+       file = fopen(filename, "re");
        if (!file)
                return NULL;
        errno = EINVAL;
@@ -733,7 +733,7 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
                return NULL;
        }
 
-       if ((fd = open(filename, O_RDONLY)) < 0) {
+       if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) {
                ERR(ctx, "%m\n");
                goto fail_open;
        }
index 6b6911bb7f30619471c43fd5d4cdd91d8bd3048f..8d7031412e62152e9b44b9bab43a639403f5b292 100644 (file)
@@ -710,7 +710,7 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod,
        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 @@ KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx,
        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 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod)
 
        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 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod)
        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 @@ KMOD_EXPORT int kmod_module_get_refcnt(const struct kmod_module *mod)
                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",