chiark / gitweb /
udev: add some O_CLOEXEC
authorKay Sievers <kay@vrfy.org>
Thu, 5 Jul 2012 15:33:24 +0000 (17:33 +0200)
committerKay Sievers <kay@vrfy.org>
Thu, 5 Jul 2012 15:33:24 +0000 (17:33 +0200)
src/libudev/libudev-queue-private.c
src/udev/cdrom_id/cdrom_id.c
src/udev/keymap/keymap.c
src/udev/scsi_id/scsi_id.c
src/udev/udev-event.c
src/udev/udev-rules.c
src/udev/udevd.c

index 3df99bef3a39fe293b597a79808aaf4a40d6d910..367395d9849062d2ede9ed248836a2d57f69aee4 100644 (file)
@@ -212,7 +212,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export)
         }
 
         /* create new queue file */
-        new_queue_file = fopen("/run/udev/queue.tmp", "w+");
+        new_queue_file = fopen("/run/udev/queue.tmp", "w+e");
         if (new_queue_file == NULL)
                 goto error;
         seqnum = udev_queue_export->seqnum_max;
index a199dd7ddcf2074374565dd0f800a50604a89dcb..74c5165e2a3e1d56d6ada0d5551aa2c38260e94b 100644 (file)
@@ -125,7 +125,7 @@ static bool is_mounted(const char *device)
         if (stat(device, &statbuf) < 0)
                 return -ENODEV;
 
-        fp = fopen("/proc/self/mountinfo", "r");
+        fp = fopen("/proc/self/mountinfo", "re");
         if (fp == NULL)
                 return -ENOSYS;
         while (fscanf(fp, "%*s %*s %i:%i %*[^\n]", &maj, &min) == 2) {
index a2e43f92c02a12798d619d5efbbe66efe9574e59..051aa42552f2e8428349ff12aab27c7219d14c7d 100644 (file)
@@ -410,7 +410,7 @@ int main(int argc, char **argv)
                 const char *filearg = argv[optind+1];
                 if (strchr(filearg, '/')) {
                         /* Keymap file argument is a path */
-                        FILE *f = fopen(filearg, "r");
+                        FILE *f = fopen(filearg, "re");
                         if (f)
                                 merge_table(fd, f);
                         else
@@ -421,12 +421,12 @@ int main(int argc, char **argv)
                         char keymap_path[PATH_MAX];
                         FILE *f;
                         snprintf(keymap_path, sizeof(keymap_path), "%s%s", SYSCONFDIR "/udev/keymaps/", filearg);
-                        f = fopen(keymap_path, "r");
+                        f = fopen(keymap_path, "re");
                         if (f) {
                                 merge_table(fd, f);
                         } else {
                                 snprintf(keymap_path, sizeof(keymap_path), "%s%s", UDEVLIBEXECDIR "/keymaps/", filearg);
-                                f = fopen(keymap_path, "r");
+                                f = fopen(keymap_path, "re");
                                 if (f)
                                         merge_table(fd, f);
                                 else
index dd8517ba96505678e72c45b1fe6a75daca7278cc..6fc41e94fb3ad9bb92b274d6a6bbd388783cbaa3 100644 (file)
@@ -180,7 +180,7 @@ static int get_file_options(struct udev *udev,
         int c;
         int retval = 0;
 
-        fd = fopen(config_file, "r");
+        fd = fopen(config_file, "re");
         if (fd == NULL) {
                 if (errno == ENOENT) {
                         return 1;
index e6f405b74a48d0055381fdb60d859932f2012c6a..aff14878a709a9fb5c925bd0657ecbee98a4dda9 100644 (file)
@@ -750,7 +750,7 @@ static void rename_netif_kernel_log(struct ifreq ifr)
         int klog;
         FILE *f;
 
-        klog = open("/dev/kmsg", O_WRONLY);
+        klog = open("/dev/kmsg", O_WRONLY|O_CLOEXEC);
         if (klog < 0)
                 return;
 
index b5b54dd0431d5e021ef1cabac629869eb7203d4a..c571c828773f66a75a17c58ec991a46c2112e6c6 100644 (file)
@@ -745,7 +745,7 @@ static int import_file_into_properties(struct udev_device *dev, const char *file
         FILE *f;
         char line[UTIL_LINE_SIZE];
 
-        f = fopen(filename, "r");
+        f = fopen(filename, "re");
         if (f == NULL)
                 return -1;
         while (fgets(line, sizeof(line), f) != NULL)
@@ -1645,7 +1645,7 @@ static int parse_file(struct udev_rules *rules, const char *filename)
         }
         log_debug("read rules file: %s\n", filename);
 
-        f = fopen(filename, "r");
+        f = fopen(filename, "re");
         if (f == NULL)
                 return -1;
 
@@ -2322,7 +2322,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
                         FILE *f;
                         bool imported = false;
 
-                        f = fopen("/proc/cmdline", "r");
+                        f = fopen("/proc/cmdline", "re");
                         if (f != NULL) {
                                 char cmdline[4096];
 
@@ -2607,7 +2607,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
                         log_debug("ATTR '%s' writing '%s' %s:%u\n", attr, value,
                                   &rules->buf[rule->rule.filename_off],
                                   rule->rule.filename_line);
-                        f = fopen(attr, "w");
+                        f = fopen(attr, "we");
                         if (f != NULL) {
                                 if (fprintf(f, "%s", value) <= 0)
                                         log_error("error writing ATTR{%s}: %m\n", attr);
index 393e2a920c889f491b6f31ece0f10ddb29b46f7e..176e4e293052e4ced91eadbdd43aec988d78bacf 100644 (file)
@@ -807,7 +807,7 @@ static void static_dev_create_from_modules(struct udev *udev)
 
         uname(&kernel);
         util_strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", kernel.release, "/modules.devname", NULL);
-        f = fopen(modules, "r");
+        f = fopen(modules, "re");
         if (f == NULL)
                 return;
 
@@ -871,7 +871,7 @@ static int mem_size_mb(void)
         char buf[4096];
         long int memsize = -1;
 
-        f = fopen("/proc/meminfo", "r");
+        f = fopen("/proc/meminfo", "re");
         if (f == NULL)
                 return -1;
 
@@ -907,7 +907,7 @@ static int convert_db(struct udev *udev)
         if (access(filename, F_OK) < 0)
                 return 0;
 
-        f = fopen("/dev/kmsg", "w");
+        f = fopen("/dev/kmsg", "we");
         if (f != NULL) {
                 fprintf(f, "<30>systemd-udevd[%u]: converting old udev database\n", getpid());
                 fclose(f);
@@ -1264,7 +1264,7 @@ int main(int argc, char *argv[])
                 sd_notify(1, "READY=1");
         }
 
-        f = fopen("/dev/kmsg", "w");
+        f = fopen("/dev/kmsg", "we");
         if (f != NULL) {
                 fprintf(f, "<30>systemd-udevd[%u]: starting version " VERSION "\n", getpid());
                 fclose(f);