Skip to content

Commit c8a202b

Browse files
committed
everywhere: always use O_CLOEXEC where it makes sense
1 parent 955d98c commit c8a202b

File tree

14 files changed

+19
-20
lines changed

14 files changed

+19
-20
lines changed

src/bootchart/bootchart.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static void do_journal_append(char *file) {
259259

260260
memcpy(p, "BOOTCHART=", 10);
261261

262-
f = open(file, O_RDONLY);
262+
f = open(file, O_RDONLY|O_CLOEXEC);
263263
if (f < 0) {
264264
log_error("Failed to read bootchart data: %m");
265265
return;
@@ -356,11 +356,11 @@ int main(int argc, char *argv[]) {
356356
t = time(NULL);
357357
strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t));
358358
snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", arg_output_path, datestr);
359-
of = fopen(output_file, "w");
359+
of = fopen(output_file, "we");
360360
}
361361

362362
if (sysfd < 0)
363-
sysfd = open("/sys", O_RDONLY);
363+
sysfd = open("/sys", O_RDONLY|O_CLOEXEC);
364364

365365
if (!build)
366366
parse_env_file("/etc/os-release", NEWLINE,
@@ -424,7 +424,7 @@ int main(int argc, char *argv[]) {
424424
t = time(NULL);
425425
strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t));
426426
snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", arg_output_path, datestr);
427-
of = fopen(output_file, "w");
427+
of = fopen(output_file, "we");
428428
}
429429

430430
if (!of) {

src/bootchart/store.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void log_uptime(void) {
6161
char str[32];
6262
double uptime;
6363

64-
f = fopen("/proc/uptime", "r");
64+
f = fopen("/proc/uptime", "re");
6565

6666
if (!f)
6767
return;

src/fsck/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static int process_progress(int fd) {
155155
return -errno;
156156
}
157157

158-
console = fopen("/dev/console", "w");
158+
console = fopen("/dev/console", "we");
159159
if (!console)
160160
return -ENOMEM;
161161

src/shared/fileio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ ssize_t sendfile_full(int out_fd, const char *fn) {
130130
assert(out_fd > 0);
131131
assert(fn);
132132

133-
f = fopen(fn, "r");
133+
f = fopen(fn, "re");
134134
if (!f)
135135
return -errno;
136136

src/shared/sleep-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int hibernation_partition_size(size_t *size, size_t *used) {
174174
assert(size);
175175
assert(used);
176176

177-
f = fopen("/proc/swaps", "r");
177+
f = fopen("/proc/swaps", "re");
178178
if (!f) {
179179
log_full(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
180180
"Failed to retrieve open /proc/swaps: %m");

src/udev/accelerometer/accelerometer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static void test_orientation(struct udev *udev,
197197

198198
old = get_prev_orientation(dev);
199199

200-
fd = open(devpath, O_RDONLY);
200+
fd = open(devpath, O_RDONLY|O_CLOEXEC);
201201
if (fd < 0)
202202
return;
203203

src/udev/ata_id/ata_id.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ int main(int argc, char *argv[])
468468
goto exit;
469469
}
470470

471-
fd = open(node, O_RDONLY|O_NONBLOCK);
471+
fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
472472
if (fd < 0) {
473473
log_error("unable to open '%s'", node);
474474
rc = 1;

src/udev/cdrom_id/cdrom_id.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ int main(int argc, char *argv[])
930930
for (cnt = 20; cnt > 0; cnt--) {
931931
struct timespec duration;
932932

933-
fd = open(node, O_RDONLY|O_NONBLOCK|(is_mounted(node) ? 0 : O_EXCL));
933+
fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|(is_mounted(node) ? 0 : O_EXCL));
934934
if (fd >= 0 || errno != EBUSY)
935935
break;
936936
duration.tv_sec = 0;

src/udev/collect/collect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static int prepare(char *dir, char *filename)
9595

9696
snprintf(buf, sizeof(buf), "%s/%s", dir, filename);
9797

98-
fd = open(buf,O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
98+
fd = open(buf,O_RDWR|O_CREAT|O_CLOEXEC, S_IRUSR|S_IWUSR);
9999
if (fd < 0)
100100
fprintf(stderr, "Cannot open %s: %m\n", buf);
101101

src/udev/mtd_probe/mtd_probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int main(int argc, char** argv)
3737
return 1;
3838
}
3939

40-
mtd_fd = open(argv[1], O_RDONLY);
40+
mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC);
4141
if (mtd_fd == -1) {
4242
perror("open");
4343
exit(-1);

0 commit comments

Comments
 (0)