From: Cristian Rodríguez Date: Fri, 16 Dec 2011 05:49:54 +0000 (-0300) Subject: Library must use O_CLOEXEC whenever it opens file descriptors X-Git-Tag: v2~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79e5ea91e04e96bdfde63b02c6859128e9b0a8ad;p=thirdparty%2Fkmod.git Library must use O_CLOEXEC whenever it opens file descriptors --- diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index efeb89dc..1ba14cc5 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -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) { diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index 5c25266b..7f0c0923 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -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; } diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 6b6911bb..8d703141 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -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",