efreet: Use eina_file_mkstemp
This commit is contained in:
parent
7576ff00f3
commit
bd5a5e7fce
|
@ -223,9 +223,9 @@ main(int argc, char **argv)
|
||||||
int lockfd = -1, tmpfd;
|
int lockfd = -1, tmpfd;
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
int i;
|
int i;
|
||||||
char file[PATH_MAX] = { '\0' };
|
char path_name[PATH_MAX] = { '\0' };
|
||||||
char util_file[PATH_MAX] = { '\0' };
|
Eina_Tmpstr *file = NULL;
|
||||||
mode_t um;
|
Eina_Tmpstr *util_file = NULL;
|
||||||
|
|
||||||
if (!eina_init()) goto eina_error;
|
if (!eina_init()) goto eina_error;
|
||||||
_efreet_desktop_cache_log_dom =
|
_efreet_desktop_cache_log_dom =
|
||||||
|
@ -273,11 +273,11 @@ main(int argc, char **argv)
|
||||||
if (!efreet_init()) goto efreet_error;
|
if (!efreet_init()) goto efreet_error;
|
||||||
|
|
||||||
/* create homedir */
|
/* create homedir */
|
||||||
snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
|
snprintf(path_name, sizeof(path_name), "%s/efreet", efreet_cache_home_get());
|
||||||
if (!ecore_file_exists(file))
|
if (!ecore_file_exists(path_name))
|
||||||
{
|
{
|
||||||
if (!ecore_file_mkpath(file)) goto efreet_error;
|
if (!ecore_file_mkpath(path_name)) goto efreet_error;
|
||||||
efreet_setowner(file);
|
efreet_setowner(path_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lock process, so that we only run one copy of this program */
|
/* lock process, so that we only run one copy of this program */
|
||||||
|
@ -296,21 +296,13 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create cache */
|
/* create cache */
|
||||||
snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file());
|
tmpfd = eina_file_mkstemp("efreet_desktop_cache_XXXXXX", &file);
|
||||||
/* set secure umask for temporary files */
|
|
||||||
um = umask(0077);
|
|
||||||
tmpfd = mkstemp(file);
|
|
||||||
umask(um);
|
|
||||||
if (tmpfd < 0) goto error;
|
if (tmpfd < 0) goto error;
|
||||||
close(tmpfd);
|
close(tmpfd);
|
||||||
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
|
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
|
||||||
if (!ef) goto error;
|
if (!ef) goto error;
|
||||||
|
|
||||||
snprintf(util_file, sizeof(util_file), "%s.XXXXXX", efreet_desktop_util_cache_file());
|
tmpfd = eina_file_mkstemp("efreet_desktop_util_cache_XXXXXX", &util_file);
|
||||||
/* set secure umask for temporary files */
|
|
||||||
um = umask(0077);
|
|
||||||
tmpfd = mkstemp(util_file);
|
|
||||||
umask(um);
|
|
||||||
if (tmpfd < 0) goto error;
|
if (tmpfd < 0) goto error;
|
||||||
close(tmpfd);
|
close(tmpfd);
|
||||||
util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE);
|
util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE);
|
||||||
|
@ -450,6 +442,8 @@ main(int argc, char **argv)
|
||||||
printf("%c\n", c);
|
printf("%c\n", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eina_tmpstr_del(file);
|
||||||
|
eina_tmpstr_del(util_file);
|
||||||
EINA_LIST_FREE(systemdirs, dir)
|
EINA_LIST_FREE(systemdirs, dir)
|
||||||
eina_stringshare_del(dir);
|
eina_stringshare_del(dir);
|
||||||
eina_list_free(extra_dirs);
|
eina_list_free(extra_dirs);
|
||||||
|
@ -461,6 +455,8 @@ main(int argc, char **argv)
|
||||||
close(lockfd);
|
close(lockfd);
|
||||||
return 0;
|
return 0;
|
||||||
error:
|
error:
|
||||||
|
eina_tmpstr_del(file);
|
||||||
|
eina_tmpstr_del(util_file);
|
||||||
IF_FREE(dir);
|
IF_FREE(dir);
|
||||||
edd_error:
|
edd_error:
|
||||||
if (old_file_ids)
|
if (old_file_ids)
|
||||||
|
|
|
@ -26,29 +26,22 @@ quit(void)
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
|
||||||
FILE *log;
|
FILE *log;
|
||||||
mode_t um;
|
int fd;
|
||||||
|
|
||||||
strcpy(path, "/tmp/efreetd_XXXXXX");
|
|
||||||
um = umask(0077);
|
|
||||||
if (mkstemp(path) < 0)
|
|
||||||
{
|
|
||||||
perror("mkstemp");
|
|
||||||
umask(um);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
umask(um);
|
|
||||||
if (chmod(path, 0700) < 0)
|
|
||||||
{
|
|
||||||
perror("chmod");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
log = fopen(path, "wb");
|
|
||||||
if (!log) return 1;
|
|
||||||
|
|
||||||
if (!eina_init()) return 1;
|
if (!eina_init()) return 1;
|
||||||
|
|
||||||
|
fd = eina_file_mkstemp("efreetd_XXXXXX", NULL);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
EINA_LOG_ERR("mkstemp");
|
||||||
|
goto eina_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
log = fdopen(fd, "wb");
|
||||||
|
if (!log)
|
||||||
|
goto eina_error;
|
||||||
|
|
||||||
eina_log_print_cb_set(eina_log_print_cb_file, log);
|
eina_log_print_cb_set(eina_log_print_cb_file, log);
|
||||||
|
|
||||||
efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR);
|
efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR);
|
||||||
|
@ -91,6 +84,7 @@ ecore_error:
|
||||||
if (efreetd_log_dom >= 0)
|
if (efreetd_log_dom >= 0)
|
||||||
eina_log_domain_unregister(efreetd_log_dom);
|
eina_log_domain_unregister(efreetd_log_dom);
|
||||||
efreetd_log_dom = -1;
|
efreetd_log_dom = -1;
|
||||||
|
eina_error:
|
||||||
eina_shutdown();
|
eina_shutdown();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue