trap sigint

SVN revision: 54891
This commit is contained in:
Sebastian Dransfeld 2010-11-23 16:49:46 +00:00
parent 6bed064f60
commit 5db48201ce
2 changed files with 94 additions and 36 deletions

View File

@ -27,6 +27,18 @@ static Eina_Hash *paths = NULL;
static int verbose = 0; 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 static int
strcmplen(const void *data1, const void *data2) 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 id[PATH_MAX];
char buf[PATH_MAX]; char buf[PATH_MAX];
DIR *files; DIR *files;
struct dirent *file; struct dirent *ent;
if (!ecore_file_is_dir(path)) return 1; if (!ecore_file_is_dir(path)) return 1;
files = opendir(path); files = opendir(path);
if (!files) return 1; if (!files) return 1;
id[0] = '\0'; id[0] = '\0';
while ((file = readdir(files))) while ((ent = readdir(files)))
{ {
if (!file) break; if (!ent) break;
if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue; if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) continue;
if (base_id) if (base_id)
{ {
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 else
strcpy(id, file->d_name); strcpy(id, ent->d_name);
file_id = id; 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 (ecore_file_is_dir(buf))
{ {
if (recurse) if (recurse)
@ -206,8 +218,6 @@ main(int argc, char **argv)
* during whilst this program runs. * during whilst this program runs.
* - Maybe linger for a while to reduce number of cache re-creates. * - 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; Eina_List *dirs = NULL, *user_dirs = NULL;
int priority = 0; int priority = 0;
char *dir = NULL; char *dir = NULL;
@ -217,6 +227,7 @@ main(int argc, char **argv)
int changed = 0; int changed = 0;
int i; int i;
struct flock fl; struct flock fl;
struct sigaction act;
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
@ -234,7 +245,18 @@ main(int argc, char **argv)
/* init external subsystems */ /* init external subsystems */
if (!eina_init()) goto eina_error; if (!eina_init()) goto eina_error;
if (!eet_init()) goto eet_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; efreet_cache_update = 0;
@ -378,6 +400,12 @@ main(int argc, char **argv)
eet_close(util_ef); eet_close(util_ef);
eet_close(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 */ /* unlink old cache files */
if (changed) if (changed)
{ {
@ -392,19 +420,6 @@ main(int argc, char **argv)
/* rename tmp files to real files */ /* rename tmp files to real files */
if (rename(util_file, efreet_desktop_util_cache_file()) < 0) goto error; if (rename(util_file, efreet_desktop_util_cache_file()) < 0) goto error;
if (rename(file, efreet_desktop_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 else
{ {
@ -412,6 +427,18 @@ main(int argc, char **argv)
unlink(file); 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(); efreet_shutdown();
ecore_shutdown(); ecore_shutdown();
eet_shutdown(); eet_shutdown();
@ -424,6 +451,8 @@ error:
edd_error: edd_error:
efreet_shutdown(); efreet_shutdown();
efreet_error: efreet_error:
ecore_shutdown();
ecore_error:
eet_shutdown(); eet_shutdown();
eet_error: eet_error:
eina_shutdown(); eina_shutdown();

View File

@ -25,25 +25,35 @@ static Eina_List *extensions;
static int verbose = 0; 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 static int
cache_fallback_scan_dir(Eet_File *ef, Eina_Hash *dirs, const char *dir, int *changed) cache_fallback_scan_dir(Eet_File *ef, Eina_Hash *dirs, const char *dir, int *changed)
{ {
Eina_Iterator *it; Eina_Iterator *it;
char buf[PATH_MAX]; char buf[PATH_MAX];
const char *ext, *file; const char *ext, *ent;
if (eina_hash_find(dirs, dir)) return 1; if (eina_hash_find(dirs, dir)) return 1;
eina_hash_add(dirs, dir, (void *)-1); eina_hash_add(dirs, dir, (void *)-1);
it = eina_file_ls(dir); it = eina_file_ls(dir);
if (!it) return 1; if (!it) return 1;
EINA_ITERATOR_FOREACH(it, file) EINA_ITERATOR_FOREACH(it, ent)
{ {
Eina_List *l; Eina_List *l;
Efreet_Cache_Icon *icon; Efreet_Cache_Icon *icon;
char *name, *tmp; char *name, *tmp;
ext = strrchr(file, '.'); ext = strrchr(ent, '.');
if (!ext) continue; if (!ext) continue;
ext = eina_stringshare_add(ext); ext = eina_stringshare_add(ext);
if (!eina_list_data_find(extensions, 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; continue;
} }
/* icon with known extension */ /* icon with known extension */
name = strdup(ecore_file_file_get(file)); name = strdup(ecore_file_file_get(ent));
tmp = strrchr(name, '.'); tmp = strrchr(name, '.');
if (tmp) *tmp = '\0'; if (tmp) *tmp = '\0';
icon = eet_data_read(ef, fallback_edd, name); 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 #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)) if (!eet_data_write(ef, fallback_edd, name, icon, 1))
{ {
free(name); free(name);
@ -120,19 +130,19 @@ cache_scan_path_dir(Efreet_Icon_Theme *theme, const char *path, Efreet_Icon_Them
{ {
Eina_Iterator *it; Eina_Iterator *it;
char buf[PATH_MAX]; char buf[PATH_MAX];
const char *ext, *file; const char *ext, *ent;
snprintf(buf, sizeof(buf), "%s/%s", path, dir->name); snprintf(buf, sizeof(buf), "%s/%s", path, dir->name);
it = eina_file_ls(buf); it = eina_file_ls(buf);
if (!it) return 1; if (!it) return 1;
EINA_ITERATOR_FOREACH(it, file) EINA_ITERATOR_FOREACH(it, ent)
{ {
Eina_List *l; Eina_List *l;
Efreet_Cache_Icon *icon; Efreet_Cache_Icon *icon;
Efreet_Cache_Icon_Element *elem = NULL, *oelem = NULL; Efreet_Cache_Icon_Element *elem = NULL, *oelem = NULL;
char *name, *tmp; char *name, *tmp;
ext = strrchr(file, '.'); ext = strrchr(ent, '.');
if (!ext) continue; if (!ext) continue;
ext = eina_stringshare_add(ext); ext = eina_stringshare_add(ext);
if (!eina_list_data_find(extensions, 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; continue;
} }
/* icon with known extension */ /* icon with known extension */
name = strdup(ecore_file_file_get(file)); name = strdup(ecore_file_file_get(ent));
tmp = strrchr(name, '.'); tmp = strrchr(name, '.');
if (tmp) *tmp = '\0'; if (tmp) *tmp = '\0';
icon = eet_data_read(ef, edd, name); 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) 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 else
{ {
elem = NEW(Efreet_Cache_Icon_Element, 1); 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->type = dir->type;
elem->size.normal = dir->size.normal; elem->size.normal = dir->size.normal;
elem->size.min = dir->size.min; 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 * - make sure programs with different extra dirs all work together
*/ */
Eet_File *ef; Eet_File *ef;
char file[PATH_MAX];
Eina_List *l = NULL; Eina_List *l = NULL;
Efreet_Icon_Theme *theme; Efreet_Icon_Theme *theme;
char *dir = NULL; char *dir = NULL;
@ -266,6 +275,7 @@ main(int argc, char **argv)
int i; int i;
struct flock fl; struct flock fl;
const char *exts[] = { ".png", ".xpm", ".svg", NULL }; const char *exts[] = { ".png", ".xpm", ".svg", NULL };
struct sigaction act;
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
@ -283,7 +293,18 @@ main(int argc, char **argv)
/* init external subsystems */ /* init external subsystems */
if (!eina_init()) goto eina_error; if (!eina_init()) goto eina_error;
if (!eet_init()) goto eet_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++) for (i = 0; exts[i]; i++)
extensions = eina_list_append(extensions, eina_stringshare_add(exts[i])); extensions = eina_list_append(extensions, eina_stringshare_add(exts[i]));
@ -438,6 +459,12 @@ main(int argc, char **argv)
unlink(file); 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); eina_list_free(extensions);
/* touch update file */ /* touch update file */
@ -464,6 +491,8 @@ error:
edd_error: edd_error:
efreet_shutdown(); efreet_shutdown();
efreet_error: efreet_error:
ecore_shutdown();
ecore_error:
eet_shutdown(); eet_shutdown();
eet_error: eet_error:
eina_shutdown(); eina_shutdown();