From 5db48201cebfe499f9efb6a84602415bce4fccf0 Mon Sep 17 00:00:00 2001 From: Sebastian Dransfeld Date: Tue, 23 Nov 2010 16:49:46 +0000 Subject: [PATCH] trap sigint SVN revision: 54891 --- .../src/bin/efreet_desktop_cache_create.c | 75 +++++++++++++------ .../efreet/src/bin/efreet_icon_cache_create.c | 55 ++++++++++---- 2 files changed, 94 insertions(+), 36 deletions(-) diff --git a/legacy/efreet/src/bin/efreet_desktop_cache_create.c b/legacy/efreet/src/bin/efreet_desktop_cache_create.c index 72b471f41e..fe512eb7a0 100644 --- a/legacy/efreet/src/bin/efreet_desktop_cache_create.c +++ b/legacy/efreet/src/bin/efreet_desktop_cache_create.c @@ -27,6 +27,18 @@ static Eina_Hash *paths = NULL; static int verbose = 0; +static char file[PATH_MAX] = { '\0' }; +static char util_file[PATH_MAX] = { '\0' }; + +static void +int_handler (int sig, siginfo_t * info, void *data) +{ + if (util_file[0]) unlink(util_file); + if (file[0]) unlink(file); + if (verbose) printf("EXIT\n"); + exit(1); +} + static int strcmplen(const void *data1, const void *data2) { @@ -158,28 +170,28 @@ cache_scan(const char *path, const char *base_id, int priority, int recurse, int char id[PATH_MAX]; char buf[PATH_MAX]; DIR *files; - struct dirent *file; + struct dirent *ent; if (!ecore_file_is_dir(path)) return 1; files = opendir(path); if (!files) return 1; id[0] = '\0'; - while ((file = readdir(files))) + while ((ent = readdir(files))) { - if (!file) break; - if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue; + if (!ent) break; + if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) continue; if (base_id) { if (*base_id) - snprintf(id, sizeof(id), "%s-%s", base_id, file->d_name); + snprintf(id, sizeof(id), "%s-%s", base_id, ent->d_name); else - strcpy(id, file->d_name); + strcpy(id, ent->d_name); file_id = id; } - snprintf(buf, sizeof(buf), "%s/%s", path, file->d_name); + snprintf(buf, sizeof(buf), "%s/%s", path, ent->d_name); if (ecore_file_is_dir(buf)) { if (recurse) @@ -206,8 +218,6 @@ main(int argc, char **argv) * during whilst this program runs. * - Maybe linger for a while to reduce number of cache re-creates. */ - char file[PATH_MAX]; - char util_file[PATH_MAX]; Eina_List *dirs = NULL, *user_dirs = NULL; int priority = 0; char *dir = NULL; @@ -217,6 +227,7 @@ main(int argc, char **argv) int changed = 0; int i; struct flock fl; + struct sigaction act; for (i = 1; i < argc; i++) { @@ -234,7 +245,18 @@ main(int argc, char **argv) /* init external subsystems */ if (!eina_init()) goto eina_error; if (!eet_init()) goto eet_error; - if (!ecore_init()) goto eet_error; + if (!ecore_init()) goto ecore_error; + + // Trap SIGINT for clean shutdown + act.sa_sigaction = int_handler; + act.sa_flags = SA_RESTART | SA_SIGINFO; + sigemptyset(&act.sa_mask); + + if (sigaction(SIGINT, &act, NULL) < 0) + { + perror("sigaction"); + goto efreet_error; + } efreet_cache_update = 0; @@ -378,6 +400,12 @@ main(int argc, char **argv) eet_close(util_ef); eet_close(ef); + /* Remove signal handler, no need to exit now */ + act.sa_sigaction = SIG_DFL; + act.sa_flags = SA_RESTART | SA_SIGINFO; + sigemptyset(&act.sa_mask); + sigaction(SIGINT, &act, NULL); + /* unlink old cache files */ if (changed) { @@ -392,19 +420,6 @@ main(int argc, char **argv) /* rename tmp files to real files */ if (rename(util_file, efreet_desktop_util_cache_file()) < 0) goto error; if (rename(file, efreet_desktop_cache_file()) < 0) goto error; - - /* touch update file */ - snprintf(file, sizeof(file), "%s/.efreet/desktop_data.update", efreet_home_dir_get()); - tmpfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); - if (tmpfd >= 0) - { - struct timeval tv[2]; - - gettimeofday(&tv[0], NULL); - tv[1] = tv[0]; - futimes(tmpfd, tv); - close(tmpfd); - } } else { @@ -412,6 +427,18 @@ main(int argc, char **argv) unlink(file); } + /* touch update file */ + snprintf(file, sizeof(file), "%s/.efreet/desktop_data.update", efreet_home_dir_get()); + tmpfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); + if (tmpfd >= 0) + { + struct timeval tv[2]; + + gettimeofday(&tv[0], NULL); + tv[1] = tv[0]; + futimes(tmpfd, tv); + close(tmpfd); + } efreet_shutdown(); ecore_shutdown(); eet_shutdown(); @@ -424,6 +451,8 @@ error: edd_error: efreet_shutdown(); efreet_error: + ecore_shutdown(); +ecore_error: eet_shutdown(); eet_error: eina_shutdown(); diff --git a/legacy/efreet/src/bin/efreet_icon_cache_create.c b/legacy/efreet/src/bin/efreet_icon_cache_create.c index 0e6fb3da3e..0cd37b85ba 100644 --- a/legacy/efreet/src/bin/efreet_icon_cache_create.c +++ b/legacy/efreet/src/bin/efreet_icon_cache_create.c @@ -25,25 +25,35 @@ static Eina_List *extensions; static int verbose = 0; +static char file[PATH_MAX] = { '\0' }; + +static void +int_handler (int sig, siginfo_t * info, void *data) +{ + if (file[0]) unlink(file); + if (verbose) printf("EXIT\n"); + exit(1); +} + static int cache_fallback_scan_dir(Eet_File *ef, Eina_Hash *dirs, const char *dir, int *changed) { Eina_Iterator *it; char buf[PATH_MAX]; - const char *ext, *file; + const char *ext, *ent; if (eina_hash_find(dirs, dir)) return 1; eina_hash_add(dirs, dir, (void *)-1); it = eina_file_ls(dir); if (!it) return 1; - EINA_ITERATOR_FOREACH(it, file) + EINA_ITERATOR_FOREACH(it, ent) { Eina_List *l; Efreet_Cache_Icon *icon; char *name, *tmp; - ext = strrchr(file, '.'); + ext = strrchr(ent, '.'); if (!ext) continue; ext = eina_stringshare_add(ext); if (!eina_list_data_find(extensions, ext)) @@ -52,7 +62,7 @@ cache_fallback_scan_dir(Eet_File *ef, Eina_Hash *dirs, const char *dir, int *cha continue; } /* icon with known extension */ - name = strdup(ecore_file_file_get(file)); + name = strdup(ecore_file_file_get(ent)); tmp = strrchr(name, '.'); if (tmp) *tmp = '\0'; icon = eet_data_read(ef, fallback_edd, name); @@ -70,7 +80,7 @@ cache_fallback_scan_dir(Eet_File *ef, Eina_Hash *dirs, const char *dir, int *cha #endif } - icon->icons = eina_list_append(icon->icons, eina_stringshare_ref(file)); + icon->icons = eina_list_append(icon->icons, eina_stringshare_ref(ent)); if (!eet_data_write(ef, fallback_edd, name, icon, 1)) { free(name); @@ -120,19 +130,19 @@ cache_scan_path_dir(Efreet_Icon_Theme *theme, const char *path, Efreet_Icon_Them { Eina_Iterator *it; char buf[PATH_MAX]; - const char *ext, *file; + const char *ext, *ent; snprintf(buf, sizeof(buf), "%s/%s", path, dir->name); it = eina_file_ls(buf); if (!it) return 1; - EINA_ITERATOR_FOREACH(it, file) + EINA_ITERATOR_FOREACH(it, ent) { Eina_List *l; Efreet_Cache_Icon *icon; Efreet_Cache_Icon_Element *elem = NULL, *oelem = NULL; char *name, *tmp; - ext = strrchr(file, '.'); + ext = strrchr(ent, '.'); if (!ext) continue; ext = eina_stringshare_add(ext); if (!eina_list_data_find(extensions, ext)) @@ -141,7 +151,7 @@ cache_scan_path_dir(Efreet_Icon_Theme *theme, const char *path, Efreet_Icon_Them continue; } /* icon with known extension */ - name = strdup(ecore_file_file_get(file)); + name = strdup(ecore_file_file_get(ent)); tmp = strrchr(name, '.'); if (tmp) *tmp = '\0'; icon = eet_data_read(ef, edd, name); @@ -178,12 +188,12 @@ cache_scan_path_dir(Efreet_Icon_Theme *theme, const char *path, Efreet_Icon_Them } if (elem) { - elem->paths = eina_list_append(elem->paths, eina_stringshare_ref(file)); + elem->paths = eina_list_append(elem->paths, eina_stringshare_ref(ent)); } else { elem = NEW(Efreet_Cache_Icon_Element, 1); - elem->paths = eina_list_append(elem->paths, eina_stringshare_ref(file)); + elem->paths = eina_list_append(elem->paths, eina_stringshare_ref(ent)); elem->type = dir->type; elem->size.normal = dir->size.normal; elem->size.min = dir->size.min; @@ -257,7 +267,6 @@ main(int argc, char **argv) * - make sure programs with different extra dirs all work together */ Eet_File *ef; - char file[PATH_MAX]; Eina_List *l = NULL; Efreet_Icon_Theme *theme; char *dir = NULL; @@ -266,6 +275,7 @@ main(int argc, char **argv) int i; struct flock fl; const char *exts[] = { ".png", ".xpm", ".svg", NULL }; + struct sigaction act; for (i = 1; i < argc; i++) { @@ -283,7 +293,18 @@ main(int argc, char **argv) /* init external subsystems */ if (!eina_init()) goto eina_error; if (!eet_init()) goto eet_error; - if (!ecore_init()) goto eet_error; + if (!ecore_init()) goto ecore_error; + + // Trap SIGINT for clean shutdown + act.sa_sigaction = int_handler; + act.sa_flags = SA_RESTART | SA_SIGINFO; + sigemptyset(&act.sa_mask); + + if (sigaction(SIGINT, &act, NULL) < 0) + { + perror("sigaction"); + goto efreet_error; + } for (i = 0; exts[i]; i++) extensions = eina_list_append(extensions, eina_stringshare_add(exts[i])); @@ -438,6 +459,12 @@ main(int argc, char **argv) unlink(file); } + /* Remove signal handler, no need to exit now */ + act.sa_sigaction = SIG_DFL; + act.sa_flags = SA_RESTART | SA_SIGINFO; + sigemptyset(&act.sa_mask); + sigaction(SIGINT, &act, NULL); + eina_list_free(extensions); /* touch update file */ @@ -464,6 +491,8 @@ error: edd_error: efreet_shutdown(); efreet_error: + ecore_shutdown(); +ecore_error: eet_shutdown(); eet_error: eina_shutdown();