mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 10:37:38 -04:00
hosted: Use O_CLOEXEC for all open() and "e" for fopen() calls
This way we'll automatically close the files upon exec() Change-Id: Ic0daca8fb56432830de4a2f4a86a77337121ecc7
This commit is contained in:
parent
4f8736909a
commit
5cfd3ae4e6
14 changed files with 27 additions and 31 deletions
|
@ -77,7 +77,7 @@ void button_init_device(void)
|
|||
|
||||
for(int i = 0; i < NR_POLL_DESC; i++)
|
||||
{
|
||||
int fd = open(input_devs[i], O_RDWR);
|
||||
int fd = open(input_devs[i], O_RDWR | O_CLOEXEC);
|
||||
|
||||
if(fd < 0)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
static FILE* open_read(const char* file_name)
|
||||
{
|
||||
FILE *f = fopen(file_name, "r");
|
||||
FILE *f = fopen(file_name, "re");
|
||||
if(f == NULL)
|
||||
{
|
||||
DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name);
|
||||
|
@ -83,7 +83,7 @@ void cpufreq_available_governors(char* governors, int governors_size, int cpu)
|
|||
|
||||
static FILE* open_write(const char* file_name)
|
||||
{
|
||||
FILE *f = fopen(file_name, "w");
|
||||
FILE *f = fopen(file_name, "we");
|
||||
if(f == NULL)
|
||||
{
|
||||
DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name);
|
||||
|
|
|
@ -176,7 +176,7 @@ bool current_scaling_governor(int cpu, char* governor, int governor_size)
|
|||
sizeof(path),
|
||||
"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor",
|
||||
cpu);
|
||||
FILE *f = fopen(path, "r");
|
||||
FILE *f = fopen(path, "re");
|
||||
if(f == NULL)
|
||||
{
|
||||
DEBUGF("ERROR %s: Can not open %s for reading.", __func__, path);
|
||||
|
@ -252,7 +252,7 @@ static int read_cpu_frequency(int cpu, enum cpu_frequency_options freqOpt)
|
|||
}
|
||||
}
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
FILE *f = fopen(path, "re");
|
||||
if(f == NULL)
|
||||
{
|
||||
DEBUGF("ERROR %s: Can not open %s for reading.", __func__, path);
|
||||
|
|
|
@ -226,7 +226,7 @@ void button_init_device(void)
|
|||
|
||||
for(int i = 0; i < NR_POLL_DESC; i++)
|
||||
{
|
||||
int fd = open(input_devs[i], O_RDWR);
|
||||
int fd = open(input_devs[i], O_RDWR | O_CLOEXEC);
|
||||
|
||||
if(fd < 0)
|
||||
{
|
||||
|
|
|
@ -94,7 +94,7 @@ void power_off(void)
|
|||
{
|
||||
backlight_hw_off();
|
||||
|
||||
axp_hw = open("/dev/axp173", O_RDWR);
|
||||
axp_hw = open("/dev/axp173", O_RDWR | O_CLOEXEC);
|
||||
if(axp_hw < 0)
|
||||
panicf("Cannot open '/dev/axp173'");
|
||||
|
||||
|
|
|
@ -234,6 +234,7 @@ int app_open(const char *path, int oflag, ...)
|
|||
if (!fpath)
|
||||
FILE_ERROR_RETURN(ENAMETOOLONG, -1);
|
||||
|
||||
oflag |= O_CLOEXEC;
|
||||
return os_open(fpath, oflag __OPEN_MODE_ARG);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ int os_relate(const char *ospath1, const char *ospath2)
|
|||
}
|
||||
|
||||
/* First file must stay open for duration so that its stats don't change */
|
||||
int fd1 = os_open(ospath1, O_RDONLY);
|
||||
int fd1 = os_open(ospath1, O_RDONLY | O_CLOEXEC);
|
||||
if (fd1 < 0)
|
||||
return -2;
|
||||
|
||||
|
@ -144,7 +144,7 @@ int os_relate(const char *ospath1, const char *ospath2)
|
|||
|
||||
bool os_file_exists(const char *ospath)
|
||||
{
|
||||
int sim_fd = os_open(ospath, O_RDONLY, 0);
|
||||
int sim_fd = os_open(ospath, O_RDONLY | O_CLOEXEC, 0);
|
||||
if (sim_fd < 0)
|
||||
return false;
|
||||
|
||||
|
@ -157,7 +157,7 @@ bool os_file_exists(const char *ospath)
|
|||
|
||||
int os_opendirfd(const char *osdirname)
|
||||
{
|
||||
return os_open(osdirname, O_RDONLY);
|
||||
return os_open(osdirname, O_RDONLY | O_CLOEXEC);
|
||||
}
|
||||
|
||||
int os_opendir_and_fd(const char *osdirname, DIR **osdirpp, int *osfdp)
|
||||
|
|
|
@ -122,7 +122,7 @@ static const char* SYSFS_PATHS[] =
|
|||
|
||||
static FILE* open_read(const char* file_name)
|
||||
{
|
||||
FILE *f = fopen(file_name, "r");
|
||||
FILE *f = fopen(file_name, "re");
|
||||
if(f == NULL)
|
||||
{
|
||||
DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name);
|
||||
|
@ -134,7 +134,7 @@ static FILE* open_read(const char* file_name)
|
|||
|
||||
static FILE* open_write(const char* file_name)
|
||||
{
|
||||
FILE *f = fopen(file_name, "w");
|
||||
FILE *f = fopen(file_name, "we");
|
||||
if(f == NULL)
|
||||
{
|
||||
DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name);
|
||||
|
|
|
@ -47,17 +47,12 @@ static void redraw(void)
|
|||
void lcd_init_device(void)
|
||||
{
|
||||
const char * const fb_dev = "/dev/fb0";
|
||||
fd = open(fb_dev, O_RDWR /* | O_SYNC */);
|
||||
fd = open(fb_dev, O_RDWR | O_CLOEXEC);
|
||||
if(fd < 0)
|
||||
{
|
||||
panicf("Cannot open framebuffer: %s\n", fb_dev);
|
||||
}
|
||||
|
||||
if (fcntl( fd, F_SETFD, FD_CLOEXEC ) < 0)
|
||||
{
|
||||
panicf("Can't set CLOEXEC");
|
||||
}
|
||||
|
||||
/* get fixed and variable information */
|
||||
if(ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0)
|
||||
{
|
||||
|
|
|
@ -62,7 +62,7 @@ int rtc_write_datetime(const struct tm *tm)
|
|||
tm_time = gmtime(&now);
|
||||
|
||||
/* Try to write the HW RTC, if present. */
|
||||
int rtc = open("/dev/rtc0", O_WRONLY);
|
||||
int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
|
||||
if (rtc > 0) {
|
||||
ioctl(rtc, RTC_SET_TIME, (struct rtc_time *)tm_time);
|
||||
close(rtc);
|
||||
|
@ -79,7 +79,7 @@ void rtc_set_alarm(int h, int m)
|
|||
struct rtc_time tm;
|
||||
long sec;
|
||||
|
||||
int rtc = open("/dev/rtc0", O_WRONLY);
|
||||
int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
|
||||
if (rtc < 0)
|
||||
return;
|
||||
|
||||
|
@ -124,7 +124,7 @@ void rtc_get_alarm(int *h, int *m)
|
|||
struct rtc_time tm;
|
||||
long sec;
|
||||
|
||||
int rtc = open("/dev/rtc0", O_WRONLY);
|
||||
int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
|
||||
if (rtc < 0)
|
||||
return;
|
||||
|
||||
|
@ -157,7 +157,7 @@ void rtc_get_alarm(int *h, int *m)
|
|||
|
||||
void rtc_enable_alarm(bool enable)
|
||||
{
|
||||
int rtc = open("/dev/rtc0", O_WRONLY);
|
||||
int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
|
||||
if (rtc < 0)
|
||||
return;
|
||||
|
||||
|
@ -171,7 +171,7 @@ void rtc_enable_alarm(bool enable)
|
|||
/* Returns true if alarm was the reason we started up */
|
||||
bool rtc_check_alarm_started(bool release_alarm)
|
||||
{
|
||||
int rtc = open("/dev/rtc0", O_WRONLY);
|
||||
int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
|
||||
if (rtc < 0)
|
||||
return false;
|
||||
|
||||
|
@ -191,7 +191,7 @@ bool rtc_check_alarm_flag(void)
|
|||
{
|
||||
struct rtc_wkalrm alrm;
|
||||
|
||||
int rtc = open("/dev/rtc0", O_WRONLY);
|
||||
int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
|
||||
if (rtc < 0)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ static void write_to_soundcard(struct pcm_udata *udata)
|
|||
{
|
||||
#ifdef DEBUG
|
||||
if (debug_audio && (udata->debug == NULL)) {
|
||||
udata->debug = fopen("audiodebug.raw", "ab");
|
||||
udata->debug = fopen("audiodebug.raw", "abe");
|
||||
DEBUGF("Audio debug file open\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -364,7 +364,7 @@ void pcm_play_dma_init(void)
|
|||
#ifdef DEBUG
|
||||
udata.debug = NULL;
|
||||
if (debug_audio) {
|
||||
udata.debug = fopen("audiodebug.raw", "wb");
|
||||
udata.debug = fopen("audiodebug.raw", "wbe");
|
||||
DEBUGF("Audio debug file open\n");
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -49,7 +49,7 @@ static void compute_kern_mod_list(void)
|
|||
kern_mod_list = malloc(sizeof(const char **));
|
||||
kern_mod_list[0] = NULL;
|
||||
/* read from proc file system */
|
||||
FILE *f = fopen("/proc/modules", "r");
|
||||
FILE *f = fopen("/proc/modules", "re");
|
||||
if(f == NULL)
|
||||
{
|
||||
printf("Cannot open /proc/modules");
|
||||
|
@ -94,7 +94,7 @@ static void dump_proc_map(void)
|
|||
{
|
||||
const char *file = "/proc/self/maps";
|
||||
printf("Dumping %s...\n", file);
|
||||
FILE *f = fopen(file, "r");
|
||||
FILE *f = fopen(file, "re");
|
||||
if(f == NULL)
|
||||
{
|
||||
perror("Cannot open file");
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
static FILE* open_read(const char *file_name)
|
||||
{
|
||||
FILE *f = fopen(file_name, "r");
|
||||
FILE *f = fopen(file_name, "re");
|
||||
if(f == NULL)
|
||||
{
|
||||
DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name);
|
||||
|
@ -44,7 +44,7 @@ static FILE* open_read(const char *file_name)
|
|||
|
||||
static FILE* open_write(const char* file_name)
|
||||
{
|
||||
FILE *f = fopen(file_name, "w");
|
||||
FILE *f = fopen(file_name, "we");
|
||||
if(f == NULL)
|
||||
{
|
||||
DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name);
|
||||
|
|
|
@ -84,7 +84,7 @@ void button_init_device(void)
|
|||
|
||||
for(int i = 0; i < NR_POLL_DESC; i++)
|
||||
{
|
||||
int fd = open(input_devs[i], O_RDWR);
|
||||
int fd = open(input_devs[i], O_RDWR | O_CLOEXEC);
|
||||
|
||||
if(fd < 0)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue