static Eet_File * _open_temp_eet(Eina_Tmpstr **path, const char *rel) { Eet_File *ef; int tmpfd; char buffer[PATH_MAX]; { char *tmp; tmp = strdup(rel); snprintf(buffer, sizeof(buffer), "%s/efreet/%s.XXXXXX.cache", efreet_cache_home_get(), basename(tmp)); free(tmp); } tmpfd = eina_file_mkstemp(buffer, path); if (tmpfd < 0) return NULL; close(tmpfd); ef = eet_open(*path, EET_FILE_MODE_READ_WRITE); if (!ef) goto on_error; return ef; on_error: eina_tmpstr_del(*path); *path = NULL; return NULL; }
// "owner" creates/frees the bufs, clients just open existing ones Extnbuf * _extnbuf_new(const char *base, int id, Eina_Bool sys, int num, int w, int h, Eina_Bool owner) { Extnbuf *b; char file[PATH_MAX]; mode_t mode = S_IRUSR; int prot = PROT_READ; int page_size; Eina_Tmpstr *tmp = NULL; page_size = eina_cpu_page_size(); b = calloc(1, sizeof(Extnbuf)); b->fd = -1; b->lockfd = -1; b->addr = MAP_FAILED; b->w = w; b->h = h; b->stride = w * 4; b->size = page_size * (((b->stride * b->h) + (page_size - 1)) / page_size); b->am_owner = owner; snprintf(file, sizeof(file), "/%s-%i.%i", base, id, num); b->file = eina_stringshare_add(file); if (!b->file) goto err; if (sys) mode |= S_IRGRP | S_IROTH; if (owner) { mode |= S_IWUSR; prot |= PROT_WRITE; } if (b->am_owner) { b->lockfd = eina_file_mkstemp("ee-lock-XXXXXX", &tmp); if (b->lockfd < 0) goto err; b->lock = eina_stringshare_add(file); if (!b->lock) goto err; b->fd = shm_open(b->file, O_RDWR | O_CREAT | O_EXCL, mode); if (b->fd < 0) goto err; if (ftruncate(b->fd, b->size) < 0) goto err; } else { b->fd = shm_open(b->file, O_RDONLY, mode); if (b->fd < 0) goto err; } b->addr = mmap(NULL, b->size, prot, MAP_SHARED, b->fd, 0); if (b->addr == MAP_FAILED) goto err; return b; err: if (tmp) eina_tmpstr_del(tmp); _extnbuf_free(b); return NULL; }
static Eina_Bool _url_compl_cb(void *data, int type EINA_UNUSED, void *event_info) { url_test *info = data; Ecore_Con_Event_Url_Complete *ev = event_info; printf("Total downloaded bytes = %d\n", ecore_con_url_received_bytes_get(ev->url_con)); if (info->_tmpfd) { _free_url_test(info); ecore_con_url_free(ev->url_con); } else { fail_unless(ecore_con_url_url_set(ev->url_con, "ftp://ftp.kernel.org/pub/linux/kernel/README")); ecore_con_url_verbose_set (ev->url_con, EINA_FALSE); info->_tmpfd = eina_file_mkstemp("ecore_con_test_XXXXXX.html", &(info->_test_file)); if (info->_tmpfd < 0) { free(info); ecore_con_url_free(ev->url_con); fail(); } ecore_con_url_fd_set(ev->url_con, info->_tmpfd); if (!ecore_con_url_get(ev->url_con)) { _free_url_test(info); ecore_con_url_free(ev->url_con); fail(); } } return EINA_FALSE; }
int main(int argc, char *argv[]) { char path[PATH_MAX + 128], buf[PATH_MAX]; FILE *log; int fd; const char *log_file_dir = NULL; const char *hostname_str = NULL; #ifdef HAVE_SYS_RESOURCE_H setpriority(PRIO_PROCESS, 0, 19); #elif _WIN32 SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); #endif if (!eina_init()) return 1; efreetd_mp_stat = eina_mempool_add("chained_mempool", "struct stat", NULL, sizeof(struct stat), 10); if (!efreetd_mp_stat) return 1; 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; log_file_dir = eina_environment_tmp_get(); 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(); eina_mempool_del(efreetd_mp_stat); cache_shutdown(); ipc_shutdown(); ecore_file_shutdown(); ecore_shutdown(); eina_log_domain_unregister(efreetd_log_dom); efreetd_log_dom = -1; eina_shutdown(); return 0; tmp_error: cache_shutdown(); cache_error: ipc_shutdown(); ipc_error: ecore_file_shutdown(); ecore_file_error: ecore_shutdown(); ecore_error: if (efreetd_log_dom >= 0) eina_log_domain_unregister(efreetd_log_dom); efreetd_log_dom = -1; eina_shutdown(); return 1; }
static int _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared) { char bin_dir_path[PATH_MAX]; char bin_file_path[PATH_MAX]; char tmp_file_name[PATH_MAX]; int tmpfd = -1, copy; Eina_Tmpstr *tmp_file_path = NULL; Eet_File *ef = NULL; Evas_GL_Program *p; Eina_Iterator *it; char pname[32]; /* use eet */ if (!eet_init()) return 0; if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path))) { if (!evas_gl_common_file_cache_mkpath(bin_dir_path)) return 0; /* we can't make directory */ } copy = evas_gl_common_file_cache_file_check(bin_dir_path, SHADER_EET_CACHENAME, bin_file_path, sizeof(bin_dir_path)); /* use mkstemp for writing */ snprintf(tmp_file_name, sizeof(tmp_file_name), "%s.XXXXXX.cache", bin_file_path); tmpfd = eina_file_mkstemp(tmp_file_name, &tmp_file_path); if (tmpfd < 0) goto error; /* copy old file */ if (copy) { ef = eet_open(tmp_file_path, EET_FILE_MODE_READ); if (!ef) goto save; if (!_evas_gl_common_shader_binary_checksum_check(shared, ef)) copy = EINA_FALSE; eet_close(ef); if (copy) eina_file_copy(bin_file_path, tmp_file_path, EINA_FILE_COPY_DATA, NULL, NULL); } save: ef = eet_open(tmp_file_path, copy ? EET_FILE_MODE_READ_WRITE : EET_FILE_MODE_WRITE); if (!ef) goto error; if (!_evas_gl_common_shader_binary_checksum_write(shared, ef)) goto error; it = eina_hash_iterator_data_new(shared->shaders_hash); EINA_ITERATOR_FOREACH(it, p) { if (!p->bin_saved) { int len = 0; sprintf(pname, SHADER_PROG_NAME_FMT, p->flags); eet_read_direct(ef, pname, &len); if (len > 0) p->bin_saved = 1; // assume bin data is correct else _evas_gl_common_shader_program_binary_save(p, ef); } } eina_iterator_free(it); if (shared->shaders_cache) { eet_close(shared->shaders_cache); shared->shaders_cache = NULL; eet_shutdown(); } if (eet_close(ef) != EET_ERROR_NONE) goto destroyed; if (rename(tmp_file_path, bin_file_path) < 0) goto destroyed; eina_tmpstr_del(tmp_file_path); close(tmpfd); eet_shutdown(); shared->needs_shaders_flush = 0; return 1; destroyed: ef = NULL; error: if (tmpfd >= 0) close(tmpfd); if (ef) eet_close(ef); if (evas_gl_common_file_cache_file_exists(tmp_file_path)) unlink(tmp_file_path); eina_tmpstr_del(tmp_file_path); eet_shutdown(); return 0; }