Loading init/bootchart.c +6 −14 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ static int proc_read(const char* filename, char* buff, size_t buffsize) { int len = 0; int fd = open(filename, O_RDONLY); int fd = open(filename, O_RDONLY | O_CLOEXEC); if (fd >= 0) { len = unix_read(fd, buff, buffsize-1); close(fd); Loading Loading @@ -144,7 +144,7 @@ log_header(void) struct tm now = *localtime(&now_t); strftime(date, sizeof(date), "%x %X", &now); out = fopen( LOG_HEADER, "w" ); out = fopen( LOG_HEADER, "we" ); if (out == NULL) return; Loading @@ -169,12 +169,6 @@ log_header(void) fclose(out); } static void close_on_exec(int fd) { fcntl(fd, F_SETFD, FD_CLOEXEC); } static void open_log_file(int* plogfd, const char* logfile) { Loading @@ -183,12 +177,11 @@ open_log_file(int* plogfd, const char* logfile) /* create log file if needed */ if (logfd < 0) { logfd = open(logfile,O_WRONLY|O_CREAT|O_TRUNC,0755); logfd = open(logfile,O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC,0755); if (logfd < 0) { *plogfd = -2; return; } close_on_exec(logfd); *plogfd = logfd; } } Loading Loading @@ -220,9 +213,8 @@ do_log_file(FileBuff log, const char* procfile) do_log_uptime(log); /* append file content */ fd = open(procfile,O_RDONLY); fd = open(procfile,O_RDONLY|O_CLOEXEC); if (fd >= 0) { close_on_exec(fd); for (;;) { int ret; ret = unix_read(fd, buff, sizeof(buff)); Loading Loading @@ -264,7 +256,7 @@ do_log_procs(FileBuff log) /* read process stat line */ snprintf(filename,sizeof(filename),"/proc/%d/stat",pid); fd = open(filename,O_RDONLY); fd = open(filename,O_RDONLY|O_CLOEXEC); if (fd >= 0) { len = unix_read(fd, buff, sizeof(buff)-1); close(fd); Loading Loading @@ -340,7 +332,7 @@ int bootchart_init( void ) /* create kernel process accounting file */ { int fd = open( LOG_ACCT, O_WRONLY|O_CREAT|O_TRUNC,0644); int fd = open( LOG_ACCT, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC,0644); if (fd >= 0) { close(fd); acct( LOG_ACCT ); Loading init/builtins.c +7 −7 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ static int write_file(const char *path, const char *value) { int fd, ret, len; fd = open(path, O_WRONLY|O_CREAT|O_NOFOLLOW, 0600); fd = open(path, O_WRONLY|O_CREAT|O_NOFOLLOW|O_CLOEXEC, 0600); if (fd < 0) return -errno; Loading Loading @@ -99,7 +99,7 @@ static int setkey(struct kbentry *kbe) { int fd, ret; fd = open("/dev/tty0", O_RDWR | O_SYNC); fd = open("/dev/tty0", O_RDWR | O_SYNC | O_CLOEXEC); if (fd < 0) return -1; Loading Loading @@ -370,14 +370,14 @@ int do_mount(int nargs, char **args) struct loop_info info; mode = (flags & MS_RDONLY) ? O_RDONLY : O_RDWR; fd = open(source + 5, mode); fd = open(source + 5, mode | O_CLOEXEC); if (fd < 0) { return -1; } for (n = 0; ; n++) { sprintf(tmp, "/dev/block/loop%d", n); loop = open(tmp, mode); loop = open(tmp, mode | O_CLOEXEC); if (loop < 0) { close(fd); return -1; Loading Loading @@ -423,7 +423,7 @@ exit_success: static int wipe_data_via_recovery() { mkdir("/cache/recovery", 0700); int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC, 0600); int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0600); if (fd >= 0) { write(fd, "--wipe_data\n", strlen("--wipe_data\n") + 1); write(fd, "--reason=wipe_data_via_recovery\n", strlen("--reason=wipe_data_via_recovery\n") + 1); Loading Loading @@ -709,10 +709,10 @@ int do_copy(int nargs, char **args) if (stat(args[1], &info) < 0) return -1; if ((fd1 = open(args[1], O_RDONLY)) < 0) if ((fd1 = open(args[1], O_RDONLY|O_CLOEXEC)) < 0) goto out_err; if ((fd2 = open(args[2], O_WRONLY|O_CREAT|O_TRUNC, 0660)) < 0) if ((fd2 = open(args[2], O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0660)) < 0) goto out_err; if (!(buffer = malloc(info.st_size))) Loading init/devices.c +6 −6 Original line number Diff line number Diff line Loading @@ -865,20 +865,20 @@ static void process_firmware_event(struct uevent *uevent) if (l == -1) goto data_free_out; loading_fd = open(loading, O_WRONLY); loading_fd = open(loading, O_WRONLY|O_CLOEXEC); if(loading_fd < 0) goto file_free_out; data_fd = open(data, O_WRONLY); data_fd = open(data, O_WRONLY|O_CLOEXEC); if(data_fd < 0) goto loading_close_out; try_loading_again: fw_fd = open(file1, O_RDONLY); fw_fd = open(file1, O_RDONLY|O_CLOEXEC); if(fw_fd < 0) { fw_fd = open(file2, O_RDONLY); fw_fd = open(file2, O_RDONLY|O_CLOEXEC); if (fw_fd < 0) { fw_fd = open(file3, O_RDONLY); fw_fd = open(file3, O_RDONLY|O_CLOEXEC); if (fw_fd < 0) { if (booting) { /* If we're not fully booted, we may be missing Loading Loading @@ -1044,7 +1044,7 @@ void device_init(void) coldboot("/sys/block"); coldboot("/sys/devices"); t1 = get_usecs(); fd = open(COLDBOOT_DONE, O_WRONLY|O_CREAT, 0000); fd = open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000); close(fd); log_event_print("coldboot %ld uS\n", ((long) (t1 - t0))); // t0 & t1 are unused if the log isn't doing anything. Loading init/init.c +5 −5 Original line number Diff line number Diff line Loading @@ -608,7 +608,7 @@ static int mix_hwrng_into_linux_rng_action(int nargs, char **args) size_t total_bytes_written = 0; hwrandom_fd = TEMP_FAILURE_RETRY( open("/dev/hw_random", O_RDONLY | O_NOFOLLOW)); open("/dev/hw_random", O_RDONLY | O_NOFOLLOW | O_CLOEXEC)); if (hwrandom_fd == -1) { if (errno == ENOENT) { ERROR("/dev/hw_random not found\n"); Loading @@ -621,7 +621,7 @@ static int mix_hwrng_into_linux_rng_action(int nargs, char **args) } urandom_fd = TEMP_FAILURE_RETRY( open("/dev/urandom", O_WRONLY | O_NOFOLLOW)); open("/dev/urandom", O_WRONLY | O_NOFOLLOW | O_CLOEXEC)); if (urandom_fd == -1) { ERROR("Failed to open /dev/urandom: %s\n", strerror(errno)); goto ret; Loading Loading @@ -675,12 +675,12 @@ static int console_init_action(int nargs, char **args) snprintf(console_name, sizeof(console_name), "/dev/%s", console); } fd = open(console_name, O_RDWR); fd = open(console_name, O_RDWR | O_CLOEXEC); if (fd >= 0) have_console = 1; close(fd); fd = open("/dev/tty0", O_WRONLY); fd = open("/dev/tty0", O_WRONLY | O_CLOEXEC); if (fd >= 0) { const char *msg; msg = "\n" Loading Loading @@ -1011,7 +1011,7 @@ int main(int argc, char **argv) mount("sysfs", "/sys", "sysfs", 0, NULL); /* indicate that booting is in progress to background fw loaders, etc */ close(open("/dev/.booting", O_WRONLY | O_CREAT, 0000)); close(open("/dev/.booting", O_WRONLY | O_CREAT | O_CLOEXEC, 0000)); /* We must have some place other than / to create the * device nodes for kmsg and null, otherwise we won't Loading init/keychords.c +1 −2 Original line number Diff line number Diff line Loading @@ -72,12 +72,11 @@ void keychord_init() if (!keychords) return; fd = open("/dev/keychord", O_RDWR); fd = open("/dev/keychord", O_RDWR | O_CLOEXEC); if (fd < 0) { ERROR("could not open /dev/keychord\n"); return; } fcntl(fd, F_SETFD, FD_CLOEXEC); ret = write(fd, keychords, keychords_length); if (ret != keychords_length) { Loading Loading
init/bootchart.c +6 −14 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ static int proc_read(const char* filename, char* buff, size_t buffsize) { int len = 0; int fd = open(filename, O_RDONLY); int fd = open(filename, O_RDONLY | O_CLOEXEC); if (fd >= 0) { len = unix_read(fd, buff, buffsize-1); close(fd); Loading Loading @@ -144,7 +144,7 @@ log_header(void) struct tm now = *localtime(&now_t); strftime(date, sizeof(date), "%x %X", &now); out = fopen( LOG_HEADER, "w" ); out = fopen( LOG_HEADER, "we" ); if (out == NULL) return; Loading @@ -169,12 +169,6 @@ log_header(void) fclose(out); } static void close_on_exec(int fd) { fcntl(fd, F_SETFD, FD_CLOEXEC); } static void open_log_file(int* plogfd, const char* logfile) { Loading @@ -183,12 +177,11 @@ open_log_file(int* plogfd, const char* logfile) /* create log file if needed */ if (logfd < 0) { logfd = open(logfile,O_WRONLY|O_CREAT|O_TRUNC,0755); logfd = open(logfile,O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC,0755); if (logfd < 0) { *plogfd = -2; return; } close_on_exec(logfd); *plogfd = logfd; } } Loading Loading @@ -220,9 +213,8 @@ do_log_file(FileBuff log, const char* procfile) do_log_uptime(log); /* append file content */ fd = open(procfile,O_RDONLY); fd = open(procfile,O_RDONLY|O_CLOEXEC); if (fd >= 0) { close_on_exec(fd); for (;;) { int ret; ret = unix_read(fd, buff, sizeof(buff)); Loading Loading @@ -264,7 +256,7 @@ do_log_procs(FileBuff log) /* read process stat line */ snprintf(filename,sizeof(filename),"/proc/%d/stat",pid); fd = open(filename,O_RDONLY); fd = open(filename,O_RDONLY|O_CLOEXEC); if (fd >= 0) { len = unix_read(fd, buff, sizeof(buff)-1); close(fd); Loading Loading @@ -340,7 +332,7 @@ int bootchart_init( void ) /* create kernel process accounting file */ { int fd = open( LOG_ACCT, O_WRONLY|O_CREAT|O_TRUNC,0644); int fd = open( LOG_ACCT, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC,0644); if (fd >= 0) { close(fd); acct( LOG_ACCT ); Loading
init/builtins.c +7 −7 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ static int write_file(const char *path, const char *value) { int fd, ret, len; fd = open(path, O_WRONLY|O_CREAT|O_NOFOLLOW, 0600); fd = open(path, O_WRONLY|O_CREAT|O_NOFOLLOW|O_CLOEXEC, 0600); if (fd < 0) return -errno; Loading Loading @@ -99,7 +99,7 @@ static int setkey(struct kbentry *kbe) { int fd, ret; fd = open("/dev/tty0", O_RDWR | O_SYNC); fd = open("/dev/tty0", O_RDWR | O_SYNC | O_CLOEXEC); if (fd < 0) return -1; Loading Loading @@ -370,14 +370,14 @@ int do_mount(int nargs, char **args) struct loop_info info; mode = (flags & MS_RDONLY) ? O_RDONLY : O_RDWR; fd = open(source + 5, mode); fd = open(source + 5, mode | O_CLOEXEC); if (fd < 0) { return -1; } for (n = 0; ; n++) { sprintf(tmp, "/dev/block/loop%d", n); loop = open(tmp, mode); loop = open(tmp, mode | O_CLOEXEC); if (loop < 0) { close(fd); return -1; Loading Loading @@ -423,7 +423,7 @@ exit_success: static int wipe_data_via_recovery() { mkdir("/cache/recovery", 0700); int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC, 0600); int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0600); if (fd >= 0) { write(fd, "--wipe_data\n", strlen("--wipe_data\n") + 1); write(fd, "--reason=wipe_data_via_recovery\n", strlen("--reason=wipe_data_via_recovery\n") + 1); Loading Loading @@ -709,10 +709,10 @@ int do_copy(int nargs, char **args) if (stat(args[1], &info) < 0) return -1; if ((fd1 = open(args[1], O_RDONLY)) < 0) if ((fd1 = open(args[1], O_RDONLY|O_CLOEXEC)) < 0) goto out_err; if ((fd2 = open(args[2], O_WRONLY|O_CREAT|O_TRUNC, 0660)) < 0) if ((fd2 = open(args[2], O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0660)) < 0) goto out_err; if (!(buffer = malloc(info.st_size))) Loading
init/devices.c +6 −6 Original line number Diff line number Diff line Loading @@ -865,20 +865,20 @@ static void process_firmware_event(struct uevent *uevent) if (l == -1) goto data_free_out; loading_fd = open(loading, O_WRONLY); loading_fd = open(loading, O_WRONLY|O_CLOEXEC); if(loading_fd < 0) goto file_free_out; data_fd = open(data, O_WRONLY); data_fd = open(data, O_WRONLY|O_CLOEXEC); if(data_fd < 0) goto loading_close_out; try_loading_again: fw_fd = open(file1, O_RDONLY); fw_fd = open(file1, O_RDONLY|O_CLOEXEC); if(fw_fd < 0) { fw_fd = open(file2, O_RDONLY); fw_fd = open(file2, O_RDONLY|O_CLOEXEC); if (fw_fd < 0) { fw_fd = open(file3, O_RDONLY); fw_fd = open(file3, O_RDONLY|O_CLOEXEC); if (fw_fd < 0) { if (booting) { /* If we're not fully booted, we may be missing Loading Loading @@ -1044,7 +1044,7 @@ void device_init(void) coldboot("/sys/block"); coldboot("/sys/devices"); t1 = get_usecs(); fd = open(COLDBOOT_DONE, O_WRONLY|O_CREAT, 0000); fd = open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000); close(fd); log_event_print("coldboot %ld uS\n", ((long) (t1 - t0))); // t0 & t1 are unused if the log isn't doing anything. Loading
init/init.c +5 −5 Original line number Diff line number Diff line Loading @@ -608,7 +608,7 @@ static int mix_hwrng_into_linux_rng_action(int nargs, char **args) size_t total_bytes_written = 0; hwrandom_fd = TEMP_FAILURE_RETRY( open("/dev/hw_random", O_RDONLY | O_NOFOLLOW)); open("/dev/hw_random", O_RDONLY | O_NOFOLLOW | O_CLOEXEC)); if (hwrandom_fd == -1) { if (errno == ENOENT) { ERROR("/dev/hw_random not found\n"); Loading @@ -621,7 +621,7 @@ static int mix_hwrng_into_linux_rng_action(int nargs, char **args) } urandom_fd = TEMP_FAILURE_RETRY( open("/dev/urandom", O_WRONLY | O_NOFOLLOW)); open("/dev/urandom", O_WRONLY | O_NOFOLLOW | O_CLOEXEC)); if (urandom_fd == -1) { ERROR("Failed to open /dev/urandom: %s\n", strerror(errno)); goto ret; Loading Loading @@ -675,12 +675,12 @@ static int console_init_action(int nargs, char **args) snprintf(console_name, sizeof(console_name), "/dev/%s", console); } fd = open(console_name, O_RDWR); fd = open(console_name, O_RDWR | O_CLOEXEC); if (fd >= 0) have_console = 1; close(fd); fd = open("/dev/tty0", O_WRONLY); fd = open("/dev/tty0", O_WRONLY | O_CLOEXEC); if (fd >= 0) { const char *msg; msg = "\n" Loading Loading @@ -1011,7 +1011,7 @@ int main(int argc, char **argv) mount("sysfs", "/sys", "sysfs", 0, NULL); /* indicate that booting is in progress to background fw loaders, etc */ close(open("/dev/.booting", O_WRONLY | O_CREAT, 0000)); close(open("/dev/.booting", O_WRONLY | O_CREAT | O_CLOEXEC, 0000)); /* We must have some place other than / to create the * device nodes for kmsg and null, otherwise we won't Loading
init/keychords.c +1 −2 Original line number Diff line number Diff line Loading @@ -72,12 +72,11 @@ void keychord_init() if (!keychords) return; fd = open("/dev/keychord", O_RDWR); fd = open("/dev/keychord", O_RDWR | O_CLOEXEC); if (fd < 0) { ERROR("could not open /dev/keychord\n"); return; } fcntl(fd, F_SETFD, FD_CLOEXEC); ret = write(fd, keychords, keychords_length); if (ret != keychords_length) { Loading