Archived
1
0
Fork 0

notify: preparation for the new Notify API and inotify implementation

This commit is contained in:
Henrik Hautakoski 2010-09-25 18:08:55 +02:00
parent ed428f20c9
commit b137dd64f5
2 changed files with 18 additions and 57 deletions

View file

@ -70,56 +70,24 @@ void arch_loop() {
for(;;) { for(;;) {
if (indexer_pending() && !notify_is_ready()) { event = notify_read();
#ifdef __DEBUG__
printf("sched: running indexer\n");
#endif
indexer_run(15);
continue;
}
#ifdef __DEBUG__
printf("sched: notify block\n");
#endif
event = notify_read(-1);
if (event == NULL) if (event == NULL)
continue; continue;
#ifdef __DEBUG__
printf("-- EVENT --\n"
" TYPE: %s\n"
" DIR: %i\n"
" PATH: %s%s\n"
"---------------\n", notify_event_typetostr(event), event->dir, event->path, event->filename);
#endif
switch(event->type) {
case NOTIFY_MOVE_TO :
if (event->dir)
indexer_register(event->path, event->filename);
case NOTIFY_CREATE :
break;
case NOTIFY_MOVE_FROM :
case NOTIFY_DELETE :
break;
}
status = output_process(event); status = output_process(event);
if (0 != status) { if (status)
fprintf(stderr,"%s",output_error(status)); fprintf(stderr,"%s",output_error(status));
}
#ifdef __DEBUG__ notify_event_del(event);
notify_stat();
#endif
} }
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
// Validate arguments int status;
/* Validate arguments */
if (argc != 2) { if (argc != 2) {
printf("Usage: %s <Root Directory>\n" printf("Usage: %s <Root Directory>\n"
@ -128,17 +96,14 @@ int main(int argc, char **argv) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Load configuration */
// Load configuration
config = iniparser_load("config.ini"); config = iniparser_load("config.ini");
if (NULL == config) { if (NULL == config) {
fprintf(stderr,"Could not load configuration"); fprintf(stderr,"Could not load configuration");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Setup signal handlers */
// Setup signal handlers
signal(SIGTERM, sighandl); signal(SIGTERM, sighandl);
signal(SIGKILL, sighandl); signal(SIGKILL, sighandl);
signal(SIGQUIT, sighandl); signal(SIGQUIT, sighandl);
@ -147,23 +112,22 @@ int main(int argc, char **argv) {
signal(SIGUSR1, sighandl); signal(SIGUSR1, sighandl);
signal(SIGUSR2, sighandl); signal(SIGUSR2, sighandl);
// Connect to database status = output_init(config);
int status = output_init(config); if (status) {
if (0 != status) { fprintf(stderr, "%s", output_error(status));
fprintf(stderr,"%s",output_error(status));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
status = notify_init();
if (status == -1)
return EXIT_FAILURE;
notify_init(); status = notify_add_watch(argv[1]);
if (status == -1) {
if(notify_add_watch(argv[1]) == -1) {
fprintf(stderr, "Invalid path: %s\n", argv[1]); fprintf(stderr, "Invalid path: %s\n", argv[1]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
indexer_register(argv[1], NULL);
arch_loop(); arch_loop();
return EXIT_SUCCESS; return EXIT_SUCCESS;

View file

@ -29,7 +29,4 @@ notify_event* notify_read();
void notify_stat(); void notify_stat();
/* TODO: context-switch/threading should be implementation specific. */
int notify_is_ready();
#endif /* __NOTIFY_NOTIFY_H */ #endif /* __NOTIFY_NOTIFY_H */