summaryrefslogtreecommitdiff
path: root/firmware/target/hosted
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted')
-rw-r--r--firmware/target/hosted/agptek/button-agptek.c2
-rw-r--r--firmware/target/hosted/cpufreq-linux.c4
-rw-r--r--firmware/target/hosted/cpuinfo-linux.c4
-rw-r--r--firmware/target/hosted/fiio/button-fiio.c2
-rw-r--r--firmware/target/hosted/fiio/system-fiio.c2
-rw-r--r--firmware/target/hosted/filesystem-app.c1
-rw-r--r--firmware/target/hosted/filesystem-unix.c6
-rw-r--r--firmware/target/hosted/ibasso/sysfs-ibasso.c4
-rw-r--r--firmware/target/hosted/lcd-linuxfb.c7
-rw-r--r--firmware/target/hosted/rtc.c12
-rw-r--r--firmware/target/hosted/sdl/pcm-sdl.c4
-rw-r--r--firmware/target/hosted/sonynwz/system-nwz.c4
-rw-r--r--firmware/target/hosted/sysfs.c4
-rw-r--r--firmware/target/hosted/xduoo/button-xduoo.c2
14 files changed, 27 insertions, 31 deletions
diff --git a/firmware/target/hosted/agptek/button-agptek.c b/firmware/target/hosted/agptek/button-agptek.c
index 2d2deda6f6..83953e0dab 100644
--- a/firmware/target/hosted/agptek/button-agptek.c
+++ b/firmware/target/hosted/agptek/button-agptek.c
@@ -77,7 +77,7 @@ void button_init_device(void)
77 77
78 for(int i = 0; i < NR_POLL_DESC; i++) 78 for(int i = 0; i < NR_POLL_DESC; i++)
79 { 79 {
80 int fd = open(input_devs[i], O_RDWR); 80 int fd = open(input_devs[i], O_RDWR | O_CLOEXEC);
81 81
82 if(fd < 0) 82 if(fd < 0)
83 { 83 {
diff --git a/firmware/target/hosted/cpufreq-linux.c b/firmware/target/hosted/cpufreq-linux.c
index d622cf1d74..2083f00f26 100644
--- a/firmware/target/hosted/cpufreq-linux.c
+++ b/firmware/target/hosted/cpufreq-linux.c
@@ -31,7 +31,7 @@
31 31
32static FILE* open_read(const char* file_name) 32static FILE* open_read(const char* file_name)
33{ 33{
34 FILE *f = fopen(file_name, "r"); 34 FILE *f = fopen(file_name, "re");
35 if(f == NULL) 35 if(f == NULL)
36 { 36 {
37 DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name); 37 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)
83 83
84static FILE* open_write(const char* file_name) 84static FILE* open_write(const char* file_name)
85{ 85{
86 FILE *f = fopen(file_name, "w"); 86 FILE *f = fopen(file_name, "we");
87 if(f == NULL) 87 if(f == NULL)
88 { 88 {
89 DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name); 89 DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name);
diff --git a/firmware/target/hosted/cpuinfo-linux.c b/firmware/target/hosted/cpuinfo-linux.c
index c3669a9f5c..8165a0961b 100644
--- a/firmware/target/hosted/cpuinfo-linux.c
+++ b/firmware/target/hosted/cpuinfo-linux.c
@@ -176,7 +176,7 @@ bool current_scaling_governor(int cpu, char* governor, int governor_size)
176 sizeof(path), 176 sizeof(path),
177 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", 177 "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor",
178 cpu); 178 cpu);
179 FILE *f = fopen(path, "r"); 179 FILE *f = fopen(path, "re");
180 if(f == NULL) 180 if(f == NULL)
181 { 181 {
182 DEBUGF("ERROR %s: Can not open %s for reading.", __func__, path); 182 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)
252 } 252 }
253 } 253 }
254 254
255 FILE *f = fopen(path, "r"); 255 FILE *f = fopen(path, "re");
256 if(f == NULL) 256 if(f == NULL)
257 { 257 {
258 DEBUGF("ERROR %s: Can not open %s for reading.", __func__, path); 258 DEBUGF("ERROR %s: Can not open %s for reading.", __func__, path);
diff --git a/firmware/target/hosted/fiio/button-fiio.c b/firmware/target/hosted/fiio/button-fiio.c
index fcc7480e11..79ed702668 100644
--- a/firmware/target/hosted/fiio/button-fiio.c
+++ b/firmware/target/hosted/fiio/button-fiio.c
@@ -226,7 +226,7 @@ void button_init_device(void)
226 226
227 for(int i = 0; i < NR_POLL_DESC; i++) 227 for(int i = 0; i < NR_POLL_DESC; i++)
228 { 228 {
229 int fd = open(input_devs[i], O_RDWR); 229 int fd = open(input_devs[i], O_RDWR | O_CLOEXEC);
230 230
231 if(fd < 0) 231 if(fd < 0)
232 { 232 {
diff --git a/firmware/target/hosted/fiio/system-fiio.c b/firmware/target/hosted/fiio/system-fiio.c
index 5e638989a1..f011ceea75 100644
--- a/firmware/target/hosted/fiio/system-fiio.c
+++ b/firmware/target/hosted/fiio/system-fiio.c
@@ -94,7 +94,7 @@ void power_off(void)
94{ 94{
95 backlight_hw_off(); 95 backlight_hw_off();
96 96
97 axp_hw = open("/dev/axp173", O_RDWR); 97 axp_hw = open("/dev/axp173", O_RDWR | O_CLOEXEC);
98 if(axp_hw < 0) 98 if(axp_hw < 0)
99 panicf("Cannot open '/dev/axp173'"); 99 panicf("Cannot open '/dev/axp173'");
100 100
diff --git a/firmware/target/hosted/filesystem-app.c b/firmware/target/hosted/filesystem-app.c
index f291ece06d..4e2fa8db7b 100644
--- a/firmware/target/hosted/filesystem-app.c
+++ b/firmware/target/hosted/filesystem-app.c
@@ -234,6 +234,7 @@ int app_open(const char *path, int oflag, ...)
234 if (!fpath) 234 if (!fpath)
235 FILE_ERROR_RETURN(ENAMETOOLONG, -1); 235 FILE_ERROR_RETURN(ENAMETOOLONG, -1);
236 236
237 oflag |= O_CLOEXEC;
237 return os_open(fpath, oflag __OPEN_MODE_ARG); 238 return os_open(fpath, oflag __OPEN_MODE_ARG);
238} 239}
239 240
diff --git a/firmware/target/hosted/filesystem-unix.c b/firmware/target/hosted/filesystem-unix.c
index 907d6ab14e..177cb574e0 100644
--- a/firmware/target/hosted/filesystem-unix.c
+++ b/firmware/target/hosted/filesystem-unix.c
@@ -69,7 +69,7 @@ int os_relate(const char *ospath1, const char *ospath2)
69 } 69 }
70 70
71 /* First file must stay open for duration so that its stats don't change */ 71 /* First file must stay open for duration so that its stats don't change */
72 int fd1 = os_open(ospath1, O_RDONLY); 72 int fd1 = os_open(ospath1, O_RDONLY | O_CLOEXEC);
73 if (fd1 < 0) 73 if (fd1 < 0)
74 return -2; 74 return -2;
75 75
@@ -144,7 +144,7 @@ int os_relate(const char *ospath1, const char *ospath2)
144 144
145bool os_file_exists(const char *ospath) 145bool os_file_exists(const char *ospath)
146{ 146{
147 int sim_fd = os_open(ospath, O_RDONLY, 0); 147 int sim_fd = os_open(ospath, O_RDONLY | O_CLOEXEC, 0);
148 if (sim_fd < 0) 148 if (sim_fd < 0)
149 return false; 149 return false;
150 150
@@ -157,7 +157,7 @@ bool os_file_exists(const char *ospath)
157 157
158int os_opendirfd(const char *osdirname) 158int os_opendirfd(const char *osdirname)
159{ 159{
160 return os_open(osdirname, O_RDONLY); 160 return os_open(osdirname, O_RDONLY | O_CLOEXEC);
161} 161}
162 162
163int os_opendir_and_fd(const char *osdirname, DIR **osdirpp, int *osfdp) 163int os_opendir_and_fd(const char *osdirname, DIR **osdirpp, int *osfdp)
diff --git a/firmware/target/hosted/ibasso/sysfs-ibasso.c b/firmware/target/hosted/ibasso/sysfs-ibasso.c
index 5269c16704..8f62e3fec2 100644
--- a/firmware/target/hosted/ibasso/sysfs-ibasso.c
+++ b/firmware/target/hosted/ibasso/sysfs-ibasso.c
@@ -122,7 +122,7 @@ static const char* SYSFS_PATHS[] =
122 122
123static FILE* open_read(const char* file_name) 123static FILE* open_read(const char* file_name)
124{ 124{
125 FILE *f = fopen(file_name, "r"); 125 FILE *f = fopen(file_name, "re");
126 if(f == NULL) 126 if(f == NULL)
127 { 127 {
128 DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name); 128 DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name);
@@ -134,7 +134,7 @@ static FILE* open_read(const char* file_name)
134 134
135static FILE* open_write(const char* file_name) 135static FILE* open_write(const char* file_name)
136{ 136{
137 FILE *f = fopen(file_name, "w"); 137 FILE *f = fopen(file_name, "we");
138 if(f == NULL) 138 if(f == NULL)
139 { 139 {
140 DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name); 140 DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name);
diff --git a/firmware/target/hosted/lcd-linuxfb.c b/firmware/target/hosted/lcd-linuxfb.c
index e85b920fef..14c8c30f89 100644
--- a/firmware/target/hosted/lcd-linuxfb.c
+++ b/firmware/target/hosted/lcd-linuxfb.c
@@ -47,17 +47,12 @@ static void redraw(void)
47void lcd_init_device(void) 47void lcd_init_device(void)
48{ 48{
49 const char * const fb_dev = "/dev/fb0"; 49 const char * const fb_dev = "/dev/fb0";
50 fd = open(fb_dev, O_RDWR /* | O_SYNC */); 50 fd = open(fb_dev, O_RDWR | O_CLOEXEC);
51 if(fd < 0) 51 if(fd < 0)
52 { 52 {
53 panicf("Cannot open framebuffer: %s\n", fb_dev); 53 panicf("Cannot open framebuffer: %s\n", fb_dev);
54 } 54 }
55 55
56 if (fcntl( fd, F_SETFD, FD_CLOEXEC ) < 0)
57 {
58 panicf("Can't set CLOEXEC");
59 }
60
61 /* get fixed and variable information */ 56 /* get fixed and variable information */
62 if(ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) 57 if(ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0)
63 { 58 {
diff --git a/firmware/target/hosted/rtc.c b/firmware/target/hosted/rtc.c
index ced298a5c8..e747aece38 100644
--- a/firmware/target/hosted/rtc.c
+++ b/firmware/target/hosted/rtc.c
@@ -62,7 +62,7 @@ int rtc_write_datetime(const struct tm *tm)
62 tm_time = gmtime(&now); 62 tm_time = gmtime(&now);
63 63
64 /* Try to write the HW RTC, if present. */ 64 /* Try to write the HW RTC, if present. */
65 int rtc = open("/dev/rtc0", O_WRONLY); 65 int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
66 if (rtc > 0) { 66 if (rtc > 0) {
67 ioctl(rtc, RTC_SET_TIME, (struct rtc_time *)tm_time); 67 ioctl(rtc, RTC_SET_TIME, (struct rtc_time *)tm_time);
68 close(rtc); 68 close(rtc);
@@ -79,7 +79,7 @@ void rtc_set_alarm(int h, int m)
79 struct rtc_time tm; 79 struct rtc_time tm;
80 long sec; 80 long sec;
81 81
82 int rtc = open("/dev/rtc0", O_WRONLY); 82 int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
83 if (rtc < 0) 83 if (rtc < 0)
84 return; 84 return;
85 85
@@ -124,7 +124,7 @@ void rtc_get_alarm(int *h, int *m)
124 struct rtc_time tm; 124 struct rtc_time tm;
125 long sec; 125 long sec;
126 126
127 int rtc = open("/dev/rtc0", O_WRONLY); 127 int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
128 if (rtc < 0) 128 if (rtc < 0)
129 return; 129 return;
130 130
@@ -157,7 +157,7 @@ void rtc_get_alarm(int *h, int *m)
157 157
158void rtc_enable_alarm(bool enable) 158void rtc_enable_alarm(bool enable)
159{ 159{
160 int rtc = open("/dev/rtc0", O_WRONLY); 160 int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
161 if (rtc < 0) 161 if (rtc < 0)
162 return; 162 return;
163 163
@@ -171,7 +171,7 @@ void rtc_enable_alarm(bool enable)
171/* Returns true if alarm was the reason we started up */ 171/* Returns true if alarm was the reason we started up */
172bool rtc_check_alarm_started(bool release_alarm) 172bool rtc_check_alarm_started(bool release_alarm)
173{ 173{
174 int rtc = open("/dev/rtc0", O_WRONLY); 174 int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
175 if (rtc < 0) 175 if (rtc < 0)
176 return false; 176 return false;
177 177
@@ -191,7 +191,7 @@ bool rtc_check_alarm_flag(void)
191{ 191{
192 struct rtc_wkalrm alrm; 192 struct rtc_wkalrm alrm;
193 193
194 int rtc = open("/dev/rtc0", O_WRONLY); 194 int rtc = open("/dev/rtc0", O_WRONLY | O_CLOEXEC);
195 if (rtc < 0) 195 if (rtc < 0)
196 return false; 196 return false;
197 197
diff --git a/firmware/target/hosted/sdl/pcm-sdl.c b/firmware/target/hosted/sdl/pcm-sdl.c
index 9cb35beb48..877ca5a482 100644
--- a/firmware/target/hosted/sdl/pcm-sdl.c
+++ b/firmware/target/hosted/sdl/pcm-sdl.c
@@ -141,7 +141,7 @@ static void write_to_soundcard(struct pcm_udata *udata)
141{ 141{
142#ifdef DEBUG 142#ifdef DEBUG
143 if (debug_audio && (udata->debug == NULL)) { 143 if (debug_audio && (udata->debug == NULL)) {
144 udata->debug = fopen("audiodebug.raw", "ab"); 144 udata->debug = fopen("audiodebug.raw", "abe");
145 DEBUGF("Audio debug file open\n"); 145 DEBUGF("Audio debug file open\n");
146 } 146 }
147#endif 147#endif
@@ -364,7 +364,7 @@ void pcm_play_dma_init(void)
364#ifdef DEBUG 364#ifdef DEBUG
365 udata.debug = NULL; 365 udata.debug = NULL;
366 if (debug_audio) { 366 if (debug_audio) {
367 udata.debug = fopen("audiodebug.raw", "wb"); 367 udata.debug = fopen("audiodebug.raw", "wbe");
368 DEBUGF("Audio debug file open\n"); 368 DEBUGF("Audio debug file open\n");
369 } 369 }
370#endif 370#endif
diff --git a/firmware/target/hosted/sonynwz/system-nwz.c b/firmware/target/hosted/sonynwz/system-nwz.c
index b20ee71774..c10c26250b 100644
--- a/firmware/target/hosted/sonynwz/system-nwz.c
+++ b/firmware/target/hosted/sonynwz/system-nwz.c
@@ -49,7 +49,7 @@ static void compute_kern_mod_list(void)
49 kern_mod_list = malloc(sizeof(const char **)); 49 kern_mod_list = malloc(sizeof(const char **));
50 kern_mod_list[0] = NULL; 50 kern_mod_list[0] = NULL;
51 /* read from proc file system */ 51 /* read from proc file system */
52 FILE *f = fopen("/proc/modules", "r"); 52 FILE *f = fopen("/proc/modules", "re");
53 if(f == NULL) 53 if(f == NULL)
54 { 54 {
55 printf("Cannot open /proc/modules"); 55 printf("Cannot open /proc/modules");
@@ -94,7 +94,7 @@ static void dump_proc_map(void)
94{ 94{
95 const char *file = "/proc/self/maps"; 95 const char *file = "/proc/self/maps";
96 printf("Dumping %s...\n", file); 96 printf("Dumping %s...\n", file);
97 FILE *f = fopen(file, "r"); 97 FILE *f = fopen(file, "re");
98 if(f == NULL) 98 if(f == NULL)
99 { 99 {
100 perror("Cannot open file"); 100 perror("Cannot open file");
diff --git a/firmware/target/hosted/sysfs.c b/firmware/target/hosted/sysfs.c
index 177f338911..1c3fe8c396 100644
--- a/firmware/target/hosted/sysfs.c
+++ b/firmware/target/hosted/sysfs.c
@@ -32,7 +32,7 @@
32 32
33static FILE* open_read(const char *file_name) 33static FILE* open_read(const char *file_name)
34{ 34{
35 FILE *f = fopen(file_name, "r"); 35 FILE *f = fopen(file_name, "re");
36 if(f == NULL) 36 if(f == NULL)
37 { 37 {
38 DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name); 38 DEBUGF("ERROR %s: Can not open %s for reading.", __func__, file_name);
@@ -44,7 +44,7 @@ static FILE* open_read(const char *file_name)
44 44
45static FILE* open_write(const char* file_name) 45static FILE* open_write(const char* file_name)
46{ 46{
47 FILE *f = fopen(file_name, "w"); 47 FILE *f = fopen(file_name, "we");
48 if(f == NULL) 48 if(f == NULL)
49 { 49 {
50 DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name); 50 DEBUGF("ERROR %s: Can not open %s for writing.", __func__, file_name);
diff --git a/firmware/target/hosted/xduoo/button-xduoo.c b/firmware/target/hosted/xduoo/button-xduoo.c
index 503e49e001..3dc1bdc13a 100644
--- a/firmware/target/hosted/xduoo/button-xduoo.c
+++ b/firmware/target/hosted/xduoo/button-xduoo.c
@@ -84,7 +84,7 @@ void button_init_device(void)
84 84
85 for(int i = 0; i < NR_POLL_DESC; i++) 85 for(int i = 0; i < NR_POLL_DESC; i++)
86 { 86 {
87 int fd = open(input_devs[i], O_RDWR); 87 int fd = open(input_devs[i], O_RDWR | O_CLOEXEC);
88 88
89 if(fd < 0) 89 if(fd < 0)
90 { 90 {