forked from enlightenment/efl
efreet: fix tmp file/dir/log handling to not leave a mess and work
so efreets tmp file/cache/log file handling was broken, using filenames in tmp and renaming them to a caceh dir that can be on different filesystems. also log file should have been in a tmp dir ... and subsidrs cache didnt get renamed properly at all and thus not updated. @fix
This commit is contained in:
parent
81c1b8b530
commit
5028a88077
|
@ -3,6 +3,8 @@
|
|||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_SYS_RESOURCE_H
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
@ -26,9 +28,12 @@ quit(void)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
char path[PATH_MAX], buf[PATH_MAX];
|
||||
FILE *log;
|
||||
int fd;
|
||||
const char *s;
|
||||
const char *log_file_dir = NULL;
|
||||
const char *hostname_str = NULL;
|
||||
|
||||
#ifdef HAVE_SYS_RESOURCE_H
|
||||
setpriority(PRIO_PROCESS, 0, 19);
|
||||
|
@ -38,31 +43,37 @@ main(int argc, char *argv[])
|
|||
|
||||
if (!eina_init()) return 1;
|
||||
|
||||
snprintf(path, sizeof(path), "efreetd_XXXXXX.cache");
|
||||
fd = eina_file_mkstemp(path, NULL);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("mkstemp");
|
||||
goto ecore_error;
|
||||
}
|
||||
log = fdopen(fd, "wb");
|
||||
if (!log)
|
||||
goto ecore_error;
|
||||
|
||||
eina_log_print_cb_set(eina_log_print_cb_file, log);
|
||||
efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR);
|
||||
if (efreetd_log_dom < 0)
|
||||
{
|
||||
EINA_LOG_ERR("Efreet: Could not create a log domain for efreetd.");
|
||||
goto ecore_error;
|
||||
}
|
||||
|
||||
if (!ecore_init()) goto ecore_error;
|
||||
ecore_app_args_set(argc, (const char **)argv);
|
||||
if (!ecore_file_init()) goto ecore_file_error;
|
||||
if (!ipc_init()) goto ipc_error;
|
||||
if (!cache_init()) goto cache_error;
|
||||
|
||||
s = getenv("XDG_RUNTIME_DIR");
|
||||
if (s) log_file_dir = s;
|
||||
else log_file_dir = "/tmp";
|
||||
if (gethostname(buf, sizeof(buf)) < 0)
|
||||
hostname_str = "";
|
||||
else
|
||||
hostname_str = buf;
|
||||
snprintf(path, sizeof(path), "%s/efreetd_%s_XXXXXX.log",
|
||||
log_file_dir, hostname_str);
|
||||
fd = eina_file_mkstemp(path, NULL);
|
||||
if (fd < 0)
|
||||
{
|
||||
ERR("Can't create log file '%s'\b", path);;
|
||||
goto tmp_error;
|
||||
}
|
||||
log = fdopen(fd, "wb");
|
||||
if (!log) goto tmp_error;
|
||||
eina_log_print_cb_set(eina_log_print_cb_file, log);
|
||||
efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR);
|
||||
if (efreetd_log_dom < 0)
|
||||
{
|
||||
EINA_LOG_ERR("Efreet: Could not create a log domain for efreetd.");
|
||||
goto tmp_error;
|
||||
}
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
cache_shutdown();
|
||||
|
@ -74,6 +85,8 @@ main(int argc, char *argv[])
|
|||
eina_shutdown();
|
||||
return 0;
|
||||
|
||||
tmp_error:
|
||||
cache_shutdown();
|
||||
cache_error:
|
||||
ipc_shutdown();
|
||||
ipc_error:
|
||||
|
|
|
@ -122,7 +122,8 @@ subdir_cache_init(void)
|
|||
EET_DATA_DESCRIPTOR_ADD_HASH(subdir_edd, Subdir_Cache, "dirs", dirs, subdir_dir_edd);
|
||||
|
||||
// load subdirs from the cache file
|
||||
snprintf(buf, sizeof(buf), "%s/efreet/subdirs_%s.eet", efreet_cache_home_get(), efreet_hostname_get());
|
||||
snprintf(buf, sizeof(buf), "%s/efreet/subdirs_%s.eet",
|
||||
efreet_cache_home_get(), efreet_hostname_get());
|
||||
ef = eet_open(buf, EET_FILE_MODE_READ);
|
||||
if (ef)
|
||||
{
|
||||
|
@ -172,15 +173,15 @@ subdir_cache_save(void)
|
|||
if (!subdir_cache->dirs) return;
|
||||
|
||||
// save to tmp file first
|
||||
snprintf(buf2, sizeof(buf2), "%s/efreet/subdirs_%s.eet.XXXXXX.cache", efreet_cache_home_get(), efreet_hostname_get());
|
||||
snprintf(buf2, sizeof(buf2), "%s/efreet/subdirs_%s.eet.XXXXXX.cache",
|
||||
efreet_cache_home_get(), efreet_hostname_get());
|
||||
tmpfd = eina_file_mkstemp(buf2, &tmpstr);
|
||||
if (tmpfd < 0) return;
|
||||
|
||||
// write out eet file to tmp file
|
||||
ef = eet_open(buf2, EET_FILE_MODE_WRITE);
|
||||
ef = eet_open(tmpstr, EET_FILE_MODE_WRITE);
|
||||
eet_data_write(ef, subdir_edd, "subdirs", subdir_cache, EET_COMPRESSION_SUPERFAST);
|
||||
eet_close(ef);
|
||||
eina_tmpstr_del(tmpstr);
|
||||
|
||||
/*
|
||||
* On Windows, buf2 has one remaining ref, hence it can not be renamed below.
|
||||
|
@ -192,10 +193,16 @@ subdir_cache_save(void)
|
|||
#endif
|
||||
|
||||
// atomically rename subdirs file on top from tmp file
|
||||
snprintf(buf, sizeof(buf), "%s/efreet/subdirs_%s.eet", efreet_cache_home_get(), efreet_hostname_get());
|
||||
if (rename(buf2, buf) < 0) ERR("Can't save subdir cache %s", buf);
|
||||
snprintf(buf, sizeof(buf), "%s/efreet/subdirs_%s.eet",
|
||||
efreet_cache_home_get(), efreet_hostname_get());
|
||||
if (rename(tmpstr, buf) < 0)
|
||||
{
|
||||
unlink(tmpstr);
|
||||
ERR("Can't save subdir cache %s", buf);
|
||||
}
|
||||
// we dont need saving anymore - we just did
|
||||
subdir_need_save = EINA_FALSE;
|
||||
eina_tmpstr_del(tmpstr);
|
||||
}
|
||||
|
||||
static const Subdir_Cache_Dir *
|
||||
|
|
Loading…
Reference in New Issue