2012-10-20 21:53:23 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2013-06-21 01:32:18 -07:00
|
|
|
#include <stdlib.h>
|
2016-04-07 20:12:21 -07:00
|
|
|
#include <unistd.h>
|
2013-07-11 02:22:38 -07:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
2013-06-20 04:53:54 -07:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
2013-07-09 01:04:58 -07:00
|
|
|
#endif
|
2016-08-18 19:48:29 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2013-06-20 04:53:54 -07:00
|
|
|
|
2012-10-20 21:53:23 -07:00
|
|
|
#include <Ecore.h>
|
2012-11-01 18:46:31 -07:00
|
|
|
#include <Ecore_File.h>
|
2012-10-20 21:53:23 -07:00
|
|
|
|
|
|
|
#include "efreetd.h"
|
|
|
|
#include "efreetd_cache.h"
|
2015-06-24 03:24:21 -07:00
|
|
|
#include "efreetd_ipc.h"
|
2012-10-20 21:53:23 -07:00
|
|
|
|
|
|
|
int efreetd_log_dom = -1;
|
|
|
|
|
2012-11-02 13:12:41 -07:00
|
|
|
void
|
|
|
|
quit(void)
|
|
|
|
{
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
}
|
|
|
|
|
2012-10-20 21:53:23 -07:00
|
|
|
int
|
2013-01-04 09:42:23 -08:00
|
|
|
main(int argc, char *argv[])
|
2012-10-20 21:53:23 -07:00
|
|
|
{
|
2016-04-07 20:12:21 -07:00
|
|
|
char path[PATH_MAX], buf[PATH_MAX];
|
2013-06-21 01:32:18 -07:00
|
|
|
FILE *log;
|
2013-10-22 03:54:22 -07:00
|
|
|
int fd;
|
2016-04-07 20:12:21 -07:00
|
|
|
const char *log_file_dir = NULL;
|
|
|
|
const char *hostname_str = NULL;
|
2013-06-21 01:32:18 -07:00
|
|
|
|
2013-12-27 17:22:23 -08:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
setpriority(PRIO_PROCESS, 0, 19);
|
|
|
|
#elif _WIN32
|
|
|
|
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
|
|
|
|
#endif
|
|
|
|
|
2015-07-21 20:44:50 -07:00
|
|
|
if (!eina_init()) return 1;
|
|
|
|
|
2017-05-10 12:26:04 -07:00
|
|
|
efreetd_mp_stat = eina_mempool_add("chained_mempool",
|
|
|
|
"struct stat", NULL,
|
|
|
|
sizeof(struct stat), 10);
|
|
|
|
if (!efreetd_mp_stat) return 1;
|
|
|
|
|
2016-04-07 20:12:21 -07:00
|
|
|
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;
|
|
|
|
|
2017-02-08 22:48:11 -08:00
|
|
|
log_file_dir = eina_environment_tmp_get();
|
2016-04-07 20:52:36 -07:00
|
|
|
if (gethostname(buf, sizeof(buf)) < 0)
|
2016-04-07 20:12:21 -07:00
|
|
|
hostname_str = "";
|
|
|
|
else
|
|
|
|
hostname_str = buf;
|
2017-02-08 22:48:11 -08:00
|
|
|
snprintf(path, sizeof(path), "%s/efreetd_%s_XXXXXX.log",
|
|
|
|
log_file_dir, hostname_str);
|
|
|
|
fd = eina_file_mkstemp(path, NULL);
|
|
|
|
if (fd < 0)
|
2013-10-15 21:38:40 -07:00
|
|
|
{
|
2017-05-10 12:26:04 -07:00
|
|
|
ERR("Can't create log file '%s'\b", path);
|
2017-02-08 22:48:11 -08:00
|
|
|
goto tmp_error;
|
2013-08-07 01:02:05 -07:00
|
|
|
}
|
2013-10-22 03:54:22 -07:00
|
|
|
log = fdopen(fd, "wb");
|
2016-04-07 20:12:21 -07:00
|
|
|
if (!log) goto tmp_error;
|
2013-06-21 01:32:18 -07:00
|
|
|
eina_log_print_cb_set(eina_log_print_cb_file, log);
|
2012-10-20 21:53:23 -07:00
|
|
|
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.");
|
2016-04-07 20:12:21 -07:00
|
|
|
goto tmp_error;
|
2012-10-20 21:53:23 -07:00
|
|
|
}
|
2013-12-27 17:22:23 -08:00
|
|
|
|
2012-10-20 21:53:23 -07:00
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2017-05-10 12:26:04 -07:00
|
|
|
eina_mempool_del(efreetd_mp_stat);
|
|
|
|
|
2012-10-20 21:53:23 -07:00
|
|
|
cache_shutdown();
|
2015-06-24 03:24:21 -07:00
|
|
|
ipc_shutdown();
|
2012-11-01 18:46:31 -07:00
|
|
|
ecore_file_shutdown();
|
2012-10-20 21:53:23 -07:00
|
|
|
ecore_shutdown();
|
|
|
|
eina_log_domain_unregister(efreetd_log_dom);
|
|
|
|
efreetd_log_dom = -1;
|
|
|
|
eina_shutdown();
|
|
|
|
return 0;
|
|
|
|
|
2016-04-07 20:12:21 -07:00
|
|
|
tmp_error:
|
|
|
|
cache_shutdown();
|
2012-10-20 21:53:23 -07:00
|
|
|
cache_error:
|
2015-06-24 03:24:21 -07:00
|
|
|
ipc_shutdown();
|
|
|
|
ipc_error:
|
2012-11-01 18:46:31 -07:00
|
|
|
ecore_file_shutdown();
|
|
|
|
ecore_file_error:
|
2012-10-20 21:53:23 -07:00
|
|
|
ecore_shutdown();
|
|
|
|
ecore_error:
|
2013-12-27 17:22:23 -08:00
|
|
|
if (efreetd_log_dom >= 0) eina_log_domain_unregister(efreetd_log_dom);
|
2012-10-20 21:53:23 -07:00
|
|
|
efreetd_log_dom = -1;
|
|
|
|
eina_shutdown();
|
|
|
|
return 1;
|
|
|
|
}
|