summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-02-13 14:59:56 +0100
committerAnthony G. Basile <blueness@gentoo.org>2014-02-21 10:05:34 -0500
commit4e918b7253bd541a76d3d9641d0be86dd8e132d3 (patch)
tree8839977cdc60aa636d33082a8816e7e934c0bfb4
parent9fa108ac48c9b76111589967184436bf63109731 (diff)
everywhere: always use O_CLOEXEC where it makes sense
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r--src/accelerometer/accelerometer.c2
-rw-r--r--src/ata_id/ata_id.c2
-rw-r--r--src/cdrom_id/cdrom_id.c2
-rw-r--r--src/collect/collect.c2
-rw-r--r--src/mtd_probe/mtd_probe.c2
-rw-r--r--src/scsi_id/scsi_serial.c4
-rw-r--r--src/udev/udev-builtin-btrfs.c5
-rw-r--r--src/udev/udevadm-trigger.c2
-rw-r--r--src/udev/udevd.c2
9 files changed, 11 insertions, 12 deletions
diff --git a/src/accelerometer/accelerometer.c b/src/accelerometer/accelerometer.c
index babd66f6b5..925d38de1f 100644
--- a/src/accelerometer/accelerometer.c
+++ b/src/accelerometer/accelerometer.c
@@ -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;
diff --git a/src/ata_id/ata_id.c b/src/ata_id/ata_id.c
index 649890618e..f84281dd1a 100644
--- a/src/ata_id/ata_id.c
+++ b/src/ata_id/ata_id.c
@@ -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;
diff --git a/src/cdrom_id/cdrom_id.c b/src/cdrom_id/cdrom_id.c
index c2c904c0a8..c5239d1fdf 100644
--- a/src/cdrom_id/cdrom_id.c
+++ b/src/cdrom_id/cdrom_id.c
@@ -934,7 +934,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;
diff --git a/src/collect/collect.c b/src/collect/collect.c
index cb5df01c6a..4ecb6b0d19 100644
--- a/src/collect/collect.c
+++ b/src/collect/collect.c
@@ -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);
diff --git a/src/mtd_probe/mtd_probe.c b/src/mtd_probe/mtd_probe.c
index 70c04db40b..13c757bd1c 100644
--- a/src/mtd_probe/mtd_probe.c
+++ b/src/mtd_probe/mtd_probe.c
@@ -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);
diff --git a/src/scsi_id/scsi_serial.c b/src/scsi_id/scsi_serial.c
index 2f2afcee6e..378a73d863 100644
--- a/src/scsi_id/scsi_serial.c
+++ b/src/scsi_id/scsi_serial.c
@@ -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;
diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c
index f7bea69b26..2baafe6131 100644
--- a/src/udev/udev-builtin-btrfs.c
+++ b/src/udev/udev-builtin-btrfs.c
@@ -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;
diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c
index 087ee4bfae..0ee27bb408 100644
--- a/src/udev/udevadm-trigger.c
+++ b/src/udev/udevadm-trigger.c
@@ -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)
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index d9d3d85f8b..850e4f5ef6 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -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");