chiark / gitweb /
everywhere: always use O_CLOEXEC where it makes sense
authorLennart Poettering <lennart@poettering.net>
Thu, 13 Feb 2014 13:59:56 +0000 (14:59 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 13 Feb 2014 13:59:56 +0000 (14:59 +0100)
14 files changed:
src/bootchart/bootchart.c
src/bootchart/store.c
src/fsck/fsck.c
src/shared/fileio.c
src/shared/sleep-config.c
src/udev/accelerometer/accelerometer.c
src/udev/ata_id/ata_id.c
src/udev/cdrom_id/cdrom_id.c
src/udev/collect/collect.c
src/udev/mtd_probe/mtd_probe.c
src/udev/scsi_id/scsi_serial.c
src/udev/udev-builtin-btrfs.c
src/udev/udevadm-trigger.c
src/udev/udevd.c

index 630f9c5d15649d3281d7e59f950b74daa931999d..305a31ae9443a1579b83b79461bfb57ea14eb035 100644 (file)
@@ -259,7 +259,7 @@ static void do_journal_append(char *file) {
 
         memcpy(p, "BOOTCHART=", 10);
 
-        f = open(file, O_RDONLY);
+        f = open(file, O_RDONLY|O_CLOEXEC);
         if (f < 0) {
                 log_error("Failed to read bootchart data: %m");
                 return;
@@ -356,11 +356,11 @@ int main(int argc, char *argv[]) {
                         t = time(NULL);
                         strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t));
                         snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", arg_output_path, datestr);
-                        of = fopen(output_file, "w");
+                        of = fopen(output_file, "we");
                 }
 
                 if (sysfd < 0)
-                        sysfd = open("/sys", O_RDONLY);
+                        sysfd = open("/sys", O_RDONLY|O_CLOEXEC);
 
                 if (!build)
                         parse_env_file("/etc/os-release", NEWLINE,
@@ -424,7 +424,7 @@ int main(int argc, char *argv[]) {
                 t = time(NULL);
                 strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t));
                 snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", arg_output_path, datestr);
-                of = fopen(output_file, "w");
+                of = fopen(output_file, "we");
         }
 
         if (!of) {
index 3e0052d212813309aa3e38ebb3f26ae2cde92df3..78c5cf85ecd3cf70d30b6f90f678816d53800819 100644 (file)
@@ -61,7 +61,7 @@ void log_uptime(void) {
         char str[32];
         double uptime;
 
-        f = fopen("/proc/uptime", "r");
+        f = fopen("/proc/uptime", "re");
 
         if (!f)
                 return;
index 9170768cec957147a9c79390a42115344a9f3030..8facc88bb43149fbbd4233051c36e6aab1d86002 100644 (file)
@@ -155,7 +155,7 @@ static int process_progress(int fd) {
                 return -errno;
         }
 
-        console = fopen("/dev/console", "w");
+        console = fopen("/dev/console", "we");
         if (!console)
                 return -ENOMEM;
 
index b81eeb272a4bdc8aa28d89f97fce7d4d5976b977..0d3f2e90c75d639184307d97cd4101dbb5fa1a84 100644 (file)
@@ -130,7 +130,7 @@ ssize_t sendfile_full(int out_fd, const char *fn) {
         assert(out_fd > 0);
         assert(fn);
 
-        f = fopen(fn, "r");
+        f = fopen(fn, "re");
         if (!f)
                 return -errno;
 
index 70a08960690060abd583c20f5650733e4b3935e4..b9b6643066cc86773e83dbf2a5fde702f6ae4c10 100644 (file)
@@ -174,7 +174,7 @@ static int hibernation_partition_size(size_t *size, size_t *used) {
         assert(size);
         assert(used);
 
-        f = fopen("/proc/swaps", "r");
+        f = fopen("/proc/swaps", "re");
         if (!f) {
                 log_full(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
                          "Failed to retrieve open /proc/swaps: %m");
index babd66f6b5bf4b41193afb28bb3c3c41d60bc32b..925d38de1f3f7e83ac8875c5f2daa0e33abccaaf 100644 (file)
@@ -197,7 +197,7 @@ static void test_orientation(struct udev *udev,
 
         old = get_prev_orientation(dev);
 
-        fd = open(devpath, O_RDONLY);
+        fd = open(devpath, O_RDONLY|O_CLOEXEC);
         if (fd < 0)
                 return;
 
index 649890618e3135b192da48aa9f2bf1904a781029..f84281dd1a2480faab65c7cfbc8d8204fabdb2b1 100644 (file)
@@ -468,7 +468,7 @@ int main(int argc, char *argv[])
                 goto exit;
         }
 
-        fd = open(node, O_RDONLY|O_NONBLOCK);
+        fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
         if (fd < 0) {
                 log_error("unable to open '%s'", node);
                 rc = 1;
index 02a4d399e731ab6aa3b046666e33bcb2bd4c356a..93467c2d35b0b95734570536dd8cb996f9ed8e85 100644 (file)
@@ -930,7 +930,7 @@ int main(int argc, char *argv[])
         for (cnt = 20; cnt > 0; cnt--) {
                 struct timespec duration;
 
-                fd = open(node, O_RDONLY|O_NONBLOCK|(is_mounted(node) ? 0 : O_EXCL));
+                fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|(is_mounted(node) ? 0 : O_EXCL));
                 if (fd >= 0 || errno != EBUSY)
                         break;
                 duration.tv_sec = 0;
index cb5df01c6a66c9269d16bda02e15f390b927d17d..4ecb6b0d19158cefae5366febcb86e4d9edc8008 100644 (file)
@@ -95,7 +95,7 @@ static int prepare(char *dir, char *filename)
 
         snprintf(buf, sizeof(buf), "%s/%s", dir, filename);
 
-        fd = open(buf,O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+        fd = open(buf,O_RDWR|O_CREAT|O_CLOEXEC, S_IRUSR|S_IWUSR);
         if (fd < 0)
                 fprintf(stderr, "Cannot open %s: %m\n", buf);
 
index 70c04db40b615ef8fa87adb34ca9ea3a4f342f3e..13c757bd1cbf94b7affca91b2fedc4a76f74147f 100644 (file)
@@ -37,7 +37,7 @@ int main(int argc, char** argv)
                 return 1;
         }
 
-        mtd_fd = open(argv[1], O_RDONLY);
+        mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC);
         if (mtd_fd == -1) {
                 perror("open");
                 exit(-1);
index 2f2afcee6edfea097b8ba9ada823be2c605708c5..378a73d8639d2f67cbb3f8f1f411bb029e616285 100644 (file)
@@ -818,7 +818,7 @@ int scsi_std_inquiry(struct udev *udev,
         struct stat statbuf;
         int err = 0;
 
-        fd = open(devname, O_RDONLY | O_NONBLOCK);
+        fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
         if (fd < 0) {
                 log_debug("scsi_id: cannot open %s: %m", devname);
                 return 1;
@@ -866,7 +866,7 @@ int scsi_get_serial(struct udev *udev,
         for (cnt = 20; cnt > 0; cnt--) {
                 struct timespec duration;
 
-                fd = open(devname, O_RDONLY | O_NONBLOCK);
+                fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
                 if (fd >= 0 || errno != EBUSY)
                         break;
                 duration.tv_sec = 0;
index f7bea69b26c1acd5c119c13acdf0460146d88441..2baafe61310495ce1bb184ab025a45b5c9cab8aa 100644 (file)
@@ -38,19 +38,18 @@ struct btrfs_ioctl_vol_args {
 static int builtin_btrfs(struct udev_device *dev, int argc, char *argv[], bool test)
 {
         struct  btrfs_ioctl_vol_args args;
-        int fd;
+        _cleanup_close_ int fd = -1;
         int err;
 
         if (argc != 3 || !streq(argv[1], "ready"))
                 return EXIT_FAILURE;
 
-        fd = open("/dev/btrfs-control", O_RDWR);
+        fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
         if (fd < 0)
                 return EXIT_FAILURE;
 
         strscpy(args.name, sizeof(args.name), argv[2]);
         err = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
-        close(fd);
         if (err < 0)
                 return EXIT_FAILURE;
 
index 087ee4bfae5b015baadcf8a5facc175a4065333b..0ee27bb40873d3569f5d3c8a195bf2fdb4139087 100644 (file)
@@ -51,7 +51,7 @@ static void exec_list(struct udev_enumerate *udev_enumerate, const char *action)
                 if (dry_run)
                         continue;
                 strscpyl(filename, sizeof(filename), udev_list_entry_get_name(entry), "/uevent", NULL);
-                fd = open(filename, O_WRONLY);
+                fd = open(filename, O_WRONLY|O_CLOEXEC);
                 if (fd < 0)
                         continue;
                 if (write(fd, action, strlen(action)) < 0)
index 9d7fa033b637f40e55c6cd2816129cc56015540c..f21c227d173c02f53b35dc814593592dac72179e 100644 (file)
@@ -734,7 +734,7 @@ static int handle_inotify(struct udev *udev)
 
                                 log_debug("device %s closed, synthesising 'change'", udev_device_get_devnode(dev));
                                 strscpyl(filename, sizeof(filename), udev_device_get_syspath(dev), "/uevent", NULL);
-                                fd = open(filename, O_WRONLY);
+                                fd = open(filename, O_WRONLY|O_CLOEXEC);
                                 if (fd >= 0) {
                                         if (write(fd, "change", 6) < 0)
                                                 log_debug("error writing uevent: %m");