From d68e3158cfbc8133fdcbabe654017a5d91393854 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Mon, 6 Apr 2009 12:59:58 +0000 Subject: [PATCH] minor speedups. the e_main.c change might prove useful as it will minimize path resolution a lot, something that is not that cheap, even more durin e startup where disc is still spinning due other tasks starting. HOWEVER, it might bring problems to those using pre GLibC-2.4 (we're at 2.9 these days) and maybe people using Solaris or BSD, let's see if they have any trouble. SVN revision: 39880 --- src/bin/e_config.c | 41 ++++++++++----- src/bin/e_main.c | 126 +++++++++++++++++++++++++++++++++------------ 2 files changed, 122 insertions(+), 45 deletions(-) diff --git a/src/bin/e_config.c b/src/bin/e_config.c index c53c2944f..9d9c79097 100644 --- a/src/bin/e_config.c +++ b/src/bin/e_config.c @@ -1100,22 +1100,32 @@ EAPI Eina_List * e_config_profile_list(void) { Eina_List *files; - char buf[PATH_MAX]; + char buf[PATH_MAX], *p; const char *homedir; const char *dir; Eina_List *flist = NULL; - + int len; + homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/", homedir); + len = snprintf(buf, sizeof(buf), "%s/.e/e/config/", homedir); + if (len >= (int)sizeof(buf)) + return NULL; + + p = buf + len; + len = sizeof(buf) - len; files = ecore_file_ls(buf); if (files) { char *file; - + files = eina_list_sort(files, 0, (Eina_Compare_Cb)_cb_sort_files); EINA_LIST_FREE(files, file) { - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, file); + if (ecore_strlcpy(p, file, len) >= len) + { + free(file); + continue; + } if (ecore_file_is_dir(buf)) flist = eina_list_append(flist, file); else @@ -1123,24 +1133,31 @@ e_config_profile_list(void) } } dir = e_prefix_data_get(); - snprintf(buf, sizeof(buf), "%s/data/config", dir); + len = snprintf(buf, sizeof(buf), "%s/data/config", dir); + if (len >= (int)sizeof(buf)) + return NULL; + + p = buf + len; + len = sizeof(buf) - len; files = ecore_file_ls(buf); if (files) { char *file; - files = eina_list_sort(files, 0, (Eina_Compare_Cb)_cb_sort_files); EINA_LIST_FREE(files, file) { - const char *tmp; - Eina_List *l; - - snprintf(buf, sizeof(buf), "%s/data/config/%s", dir, file); + if (ecore_strlcpy(p, file, len) >= len) + { + free(file); + continue; + } if (ecore_file_is_dir(buf)) { + const Eina_List *l; + const char *tmp; EINA_LIST_FOREACH(flist, l, tmp) if (!strcmp(file, tmp)) break; - + if (!l) flist = eina_list_append(flist, file); else free(file); } diff --git a/src/bin/e_main.c b/src/bin/e_main.c index 8f09712eb..c3c2119de 100644 --- a/src/bin/e_main.c +++ b/src/bin/e_main.c @@ -1,12 +1,17 @@ /* * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 */ +#define _GNU_SOURCE #include "e.h" #ifdef HAVE_ECORE_IMF #include #endif +#include +#include +#include + /* * i need to make more use of these when i'm baffled as to when something is * up. other hooks: @@ -1151,53 +1156,108 @@ _e_main_x_shutdown(void) return 1; } +static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + static int _e_main_dirs_init(void) { const char *homedir; char buf[PATH_MAX]; - const char *dirs[] = - { - "%s/.e", - "%s/.e/e/", - "%s/.e/e/images", - "%s/.e/e/fonts", - "%s/.e/e/themes", - "%s/.e/e/icons", - "%s/.e/e/backgrounds", - "%s/.e/e/applications", - "%s/.e/e/applications/menu", - "%s/.e/e/applications/menu/favorite", - "%s/.e/e/applications/menu/all", - "%s/.e/e/applications/bar", - "%s/.e/e/applications/bar/default", - "%s/.e/e/applications/startup", - "%s/.e/e/applications/restart", - "%s/.e/e/applications/trash", - "%s/.e/e/modules", - "%s/.e/e/config", - "%s/.e/e/locale", - "%s/.e/e/input_methods" - }; - int i; - + const char *dirs[] = { + "images", + "fonts", + "themes", + "icons", + "backgrounds", + "applications", + "applications/menu", + "applications/menu/favorite", + "applications/menu/all", + "applications/bar", + "applications/bar/default", + "applications/startup", + "applications/restart", + "applications/trash", + "modules", + "config", + "locale", + "input_methods" + }; + int i, fd, baselen, retval; + DIR *dir; + homedir = e_user_homedir_get(); + baselen = snprintf(buf, sizeof(buf), "%s/.e/e", homedir); + if (baselen >= (int)sizeof(buf)) + { + e_error_message_show("Error could not join:\n'%s'\nand\n'/.e/e", + homedir); + return 0; + } + if ((!ecore_file_is_dir(buf)) && (!ecore_file_mkpath(buf))) + { + e_error_message_show("Error creating directory:\n%s", buf); + return 0; + } + + dir = opendir(buf); + if (!dir) + { + e_error_message_show("Could not open:\n%s\nError: %s", + buf, strerror(errno)); + return 0; + } + fd = dirfd(dir); + + buf[baselen] = '/'; + baselen++; + buf[baselen] = '\0'; + retval = 1; for (i = 0; i < (int)(sizeof(dirs) / sizeof(char *)); i++) { - snprintf(buf, sizeof(buf), dirs[i], homedir); - if (!ecore_file_mkdir(buf)) + /* TODO: probably need to handle cases without ATSOURCE files? + * let's wait people to report and if any I'll fix it. + */ + struct stat st; + if (fstatat(fd, dirs[i], &st, 0) == 0) { - if (!ecore_file_is_dir(buf)) + if (S_ISDIR(st.st_mode)) + continue; + else { - e_error_message_show("Error creating directory:\n" - "%s", - buf); - return 0; + e_error_message_show("Not a directory:\n%s%s", buf, dirs[i]); + retval = 0; + goto end; + } + } + else + { + if (errno == ENOENT) + { + if (mkdirat(fd, dirs[i], default_mode) == 0) + continue; + else + { + e_error_message_show + ("could not create dir:\n%s%s\nError: %s", + buf, dirs[i], strerror(errno)); + retval = 0; + goto end; + } + } + else + { + e_error_message_show("could not fstat:\n%s%s\nError: %s", + buf, dirs[i], strerror(errno)); + retval = 0; + goto end; } } } - return 1; + end: + closedir(dir); + return retval; } static int