summaryrefslogtreecommitdiff
path: root/src/bin/efreet
diff options
context:
space:
mode:
authorSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-10-16 04:48:20 +0200
committerSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-10-16 04:48:20 +0200
commitbd5a5e7fce3931476bbc68a156be28e58f5d7ef8 (patch)
treea945a5be5185ed83b71bd871eeccf56e0f211472 /src/bin/efreet
parent7576ff00f3e014db84ae1a044ae60a78c2222c31 (diff)
efreet: Use eina_file_mkstemp
Diffstat (limited to 'src/bin/efreet')
-rw-r--r--src/bin/efreet/efreet_desktop_cache_create.c30
-rw-r--r--src/bin/efreet/efreetd.c28
2 files changed, 24 insertions, 34 deletions
diff --git a/src/bin/efreet/efreet_desktop_cache_create.c b/src/bin/efreet/efreet_desktop_cache_create.c
index 2fc6e917d7..fe67da1fb4 100644
--- a/src/bin/efreet/efreet_desktop_cache_create.c
+++ b/src/bin/efreet/efreet_desktop_cache_create.c
@@ -223,9 +223,9 @@ main(int argc, char **argv)
223 int lockfd = -1, tmpfd; 223 int lockfd = -1, tmpfd;
224 int changed = 0; 224 int changed = 0;
225 int i; 225 int i;
226 char file[PATH_MAX] = { '\0' }; 226 char path_name[PATH_MAX] = { '\0' };
227 char util_file[PATH_MAX] = { '\0' }; 227 Eina_Tmpstr *file = NULL;
228 mode_t um; 228 Eina_Tmpstr *util_file = NULL;
229 229
230 if (!eina_init()) goto eina_error; 230 if (!eina_init()) goto eina_error;
231 _efreet_desktop_cache_log_dom = 231 _efreet_desktop_cache_log_dom =
@@ -273,11 +273,11 @@ main(int argc, char **argv)
273 if (!efreet_init()) goto efreet_error; 273 if (!efreet_init()) goto efreet_error;
274 274
275 /* create homedir */ 275 /* create homedir */
276 snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get()); 276 snprintf(path_name, sizeof(path_name), "%s/efreet", efreet_cache_home_get());
277 if (!ecore_file_exists(file)) 277 if (!ecore_file_exists(path_name))
278 { 278 {
279 if (!ecore_file_mkpath(file)) goto efreet_error; 279 if (!ecore_file_mkpath(path_name)) goto efreet_error;
280 efreet_setowner(file); 280 efreet_setowner(path_name);
281 } 281 }
282 282
283 /* lock process, so that we only run one copy of this program */ 283 /* lock process, so that we only run one copy of this program */
@@ -296,21 +296,13 @@ main(int argc, char **argv)
296 } 296 }
297 297
298 /* create cache */ 298 /* create cache */
299 snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file()); 299 tmpfd = eina_file_mkstemp("efreet_desktop_cache_XXXXXX", &file);
300 /* set secure umask for temporary files */
301 um = umask(0077);
302 tmpfd = mkstemp(file);
303 umask(um);
304 if (tmpfd < 0) goto error; 300 if (tmpfd < 0) goto error;
305 close(tmpfd); 301 close(tmpfd);
306 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 302 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
307 if (!ef) goto error; 303 if (!ef) goto error;
308 304
309 snprintf(util_file, sizeof(util_file), "%s.XXXXXX", efreet_desktop_util_cache_file()); 305 tmpfd = eina_file_mkstemp("efreet_desktop_util_cache_XXXXXX", &util_file);
310 /* set secure umask for temporary files */
311 um = umask(0077);
312 tmpfd = mkstemp(util_file);
313 umask(um);
314 if (tmpfd < 0) goto error; 306 if (tmpfd < 0) goto error;
315 close(tmpfd); 307 close(tmpfd);
316 util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE); 308 util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE);
@@ -450,6 +442,8 @@ main(int argc, char **argv)
450 printf("%c\n", c); 442 printf("%c\n", c);
451 } 443 }
452 444
445 eina_tmpstr_del(file);
446 eina_tmpstr_del(util_file);
453 EINA_LIST_FREE(systemdirs, dir) 447 EINA_LIST_FREE(systemdirs, dir)
454 eina_stringshare_del(dir); 448 eina_stringshare_del(dir);
455 eina_list_free(extra_dirs); 449 eina_list_free(extra_dirs);
@@ -461,6 +455,8 @@ main(int argc, char **argv)
461 close(lockfd); 455 close(lockfd);
462 return 0; 456 return 0;
463error: 457error:
458 eina_tmpstr_del(file);
459 eina_tmpstr_del(util_file);
464 IF_FREE(dir); 460 IF_FREE(dir);
465edd_error: 461edd_error:
466 if (old_file_ids) 462 if (old_file_ids)
diff --git a/src/bin/efreet/efreetd.c b/src/bin/efreet/efreetd.c
index 18fc500db1..414bb2cbf4 100644
--- a/src/bin/efreet/efreetd.c
+++ b/src/bin/efreet/efreetd.c
@@ -26,29 +26,22 @@ quit(void)
26int 26int
27main(int argc, char *argv[]) 27main(int argc, char *argv[])
28{ 28{
29 char path[PATH_MAX];
30 FILE *log; 29 FILE *log;
31 mode_t um; 30 int fd;
32 31
33 strcpy(path, "/tmp/efreetd_XXXXXX"); 32 if (!eina_init()) return 1;
34 um = umask(0077); 33
35 if (mkstemp(path) < 0) 34 fd = eina_file_mkstemp("efreetd_XXXXXX", NULL);
36 { 35 if (fd < 0)
37 perror("mkstemp");
38 umask(um);
39 return 1;
40 }
41 umask(um);
42 if (chmod(path, 0700) < 0)
43 { 36 {
44 perror("chmod"); 37 EINA_LOG_ERR("mkstemp");
45 return 1; 38 goto eina_error;
46 } 39 }
47 40
48 log = fopen(path, "wb"); 41 log = fdopen(fd, "wb");
49 if (!log) return 1; 42 if (!log)
43 goto eina_error;
50 44
51 if (!eina_init()) return 1;
52 eina_log_print_cb_set(eina_log_print_cb_file, log); 45 eina_log_print_cb_set(eina_log_print_cb_file, log);
53 46
54 efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR); 47 efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR);
@@ -91,6 +84,7 @@ ecore_error:
91 if (efreetd_log_dom >= 0) 84 if (efreetd_log_dom >= 0)
92 eina_log_domain_unregister(efreetd_log_dom); 85 eina_log_domain_unregister(efreetd_log_dom);
93 efreetd_log_dom = -1; 86 efreetd_log_dom = -1;
87eina_error:
94 eina_shutdown(); 88 eina_shutdown();
95 return 1; 89 return 1;
96} 90}