aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/efreet
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-04-08 12:12:21 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-04-08 12:13:42 +0900
commit5028a8807780892c361ae976b567cd924fa529b1 (patch)
tree2837cc8c5e4c344f2cdc0d810016244c30685390 /src/bin/efreet
parentdoc: Remove widget_preview_nstate.c (diff)
downloadefl-5028a8807780892c361ae976b567cd924fa529b1.tar.gz
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
Diffstat (limited to 'src/bin/efreet')
-rw-r--r--src/bin/efreet/efreetd.c41
-rw-r--r--src/bin/efreet/efreetd_cache.c19
2 files changed, 40 insertions, 20 deletions
diff --git a/src/bin/efreet/efreetd.c b/src/bin/efreet/efreetd.c
index 870dea7658..81d97aa1e6 100644
--- a/src/bin/efreet/efreetd.c
+++ b/src/bin/efreet/efreetd.c
@@ -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");
+ 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)
{
- perror("mkstemp");
- goto ecore_error;
+ ERR("Can't create log file '%s'\b", path);;
+ goto tmp_error;
}
log = fdopen(fd, "wb");
- if (!log)
- goto ecore_error;
-
+ 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 ecore_error;
+ goto tmp_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;
-
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:
diff --git a/src/bin/efreet/efreetd_cache.c b/src/bin/efreet/efreetd_cache.c
index 55e813041d..fefc852dd0 100644
--- a/src/bin/efreet/efreetd_cache.c
+++ b/src/bin/efreet/efreetd_cache.c
@@ -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 *