File 0017-udev-add-some-O_CLOEXEC.patch of Package libudev0

From 47ef94ac5f39db6c5c18be10afe32397a0a8d5cc Mon Sep 17 00:00:00 2001
From: Kay Sievers <kay@vrfy.org>
Date: Thu, 5 Jul 2012 17:33:24 +0200
Subject: [PATCH] udev: add some O_CLOEXEC

Index: udev-182/src/cdrom_id/cdrom_id.c
===================================================================
--- udev-182.orig/src/cdrom_id/cdrom_id.c
+++ udev-182/src/cdrom_id/cdrom_id.c
@@ -125,7 +125,7 @@ static bool is_mounted(const char *devic
         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: udev-182/src/keymap/keymap.c
===================================================================
--- udev-182.orig/src/keymap/keymap.c
+++ udev-182/src/keymap/keymap.c
@@ -409,7 +409,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
@@ -419,12 +419,12 @@ int main(int argc, char **argv)
                         /* Open override file if present, otherwise default file */
                         char keymap_path[PATH_MAX];
                         snprintf(keymap_path, sizeof(keymap_path), "%s%s", SYSCONFDIR "/udev/keymaps/", filearg);
-                        FILE *f = fopen(keymap_path, "r");
+                        FILE *f = fopen(keymap_path, "re");
                         if (f) {
                                 merge_table(fd, f);
                         } else {
                                 snprintf(keymap_path, sizeof(keymap_path), "%s%s", PKGLIBEXECDIR "/keymaps/", filearg);
-                                f = fopen(keymap_path, "r");
+                                f = fopen(keymap_path, "re");
                                 if (f)
                                         merge_table(fd, f);
                                 else
Index: udev-182/src/libudev-queue-private.c
===================================================================
--- udev-182.orig/src/libudev-queue-private.c
+++ udev-182/src/libudev-queue-private.c
@@ -223,7 +223,7 @@ static int rebuild_queue_file(struct ude
 
         /* create new queue file */
         util_strscpyl(filename_tmp, sizeof(filename_tmp), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL);
-        new_queue_file = fopen(filename_tmp, "w+");
+        new_queue_file = fopen(filename_tmp, "w+e");
         if (new_queue_file == NULL)
                 goto error;
         seqnum = udev_queue_export->seqnum_max;
Index: udev-182/src/udev-event.c
===================================================================
--- udev-182.orig/src/udev-event.c
+++ udev-182/src/udev-event.c
@@ -789,7 +789,7 @@ static void rename_netif_kernel_log(stru
         int klog;
         FILE *f;
 
-        klog = open("/dev/kmsg", O_WRONLY);
+        klog = open("/dev/kmsg", O_WRONLY|O_CLOEXEC);
         if (klog < 0)
                 return;
 
Index: udev-182/src/udev-rules.c
===================================================================
--- udev-182.orig/src/udev-rules.c
+++ udev-182/src/udev-rules.c
@@ -749,7 +749,7 @@ static int import_file_into_properties(s
         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)
@@ -1641,7 +1641,7 @@ static int parse_file(struct udev_rules
 
         info(rules->udev, "reading '%s' as rules file\n", filename);
 
-        f = fopen(filename, "r");
+        f = fopen(filename, "re");
         if (f == NULL)
                 return -1;
 
@@ -2350,7 +2350,7 @@ int udev_rules_apply_to_event(struct ude
                         FILE *f;
                         bool imported = false;
 
-                        f = fopen("/proc/cmdline", "r");
+                        f = fopen("/proc/cmdline", "re");
                         if (f != NULL) {
                                 char cmdline[4096];
 
@@ -2639,7 +2639,7 @@ int udev_rules_apply_to_event(struct ude
                         info(event->udev, "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)
                                         err(event->udev, "error writing ATTR{%s}: %m\n", attr);
Index: udev-182/src/udevd.c
===================================================================
--- udev-182.orig/src/udevd.c
+++ udev-182/src/udevd.c
@@ -838,7 +838,7 @@ static void static_dev_create_from_modul
 
         uname(&kernel);
         util_strscpyl(modules, sizeof(modules), "/lib/modules/", kernel.release, "/modules.devname", NULL);
-        f = fopen(modules, "r");
+        f = fopen(modules, "re");
         if (f == NULL)
                 return;
 
@@ -1016,7 +1016,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;
 
@@ -1054,7 +1054,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>udevd[%u]: converting old udev database\n", getpid());
                 fclose(f);
@@ -1285,7 +1285,7 @@ int main(int argc, char *argv[])
          *   udev.children-max=<number of workers>  events are fully serialized if set to 1
          *
          */
-        f = fopen("/proc/cmdline", "r");
+        f = fopen("/proc/cmdline", "re");
         if (f != NULL) {
                 char cmdline[4096];
 
@@ -1445,7 +1445,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>udevd[%u]: starting version " VERSION "\n", getpid());
                 fclose(f);
openSUSE Build Service is sponsored by