Exemplo n.º 1
0
static void *
watch(void *arg)
{
	int fd, err;
	queue_t q;
	struct inotify_event *event;

	fd = ((struct watch_data_t *)arg)->fd;
	q = ((struct watch_data_t *)arg)->q;
	free(arg);

	while (1) {
		while (!queue_empty(q)) {
			event = queue_front(q);
			queue_dequeue(q);
			err = create_ihandler_thread(event);
			if (err < 0)
				err_msg("warning[watch]: Unable to spawn inotify event handler for event->wd #%d\n", event->wd);
		}

		if (event_check(fd) > 0) {
			int r;
			r = read_events(q, fd);
			if (r < 0)  /* read(2) in read_events() returned an error. */
				break;
		}
	}

	return NULL;
}
Exemplo n.º 2
0
void eventTree_check(EventTree *eventTree) {
	Event *event;
	EventTree_Iterator *eventIterator = eventTree_getIterator(eventTree);
	while((event = eventTree_getNext(eventIterator)) != NULL) {
		event_check(event);
	}
	eventTree_destructIterator(eventIterator);
}
Exemplo n.º 3
0
static int event_event_id(lua_State* L)
{
    EventID eid = EVENT_WILDCARD;
    
    Event *event = event_check(L, 1);
    if (event != NULL)
        eid = event->eventID;
    
    lua_pushinteger(L, (int)eid);
    
    return 1;
}
Exemplo n.º 4
0
int process_inotify_events (queue_t q, int fd) {
  while (keep_running && (watched_items > 0)) {
    if (event_check (fd) > 0) {
      int r;
      r = read_events (q, fd);
      if (r < 0) {
        break;
      } else {
        handle_events (q);
      }
    }
  }
  return 0;
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: ekollof/Angel
void
mainloop(void)
{
        /*
         * This is the main program loop. Here's where we're doing all the
         * spawning and the checking. This is the heart of the program.
         */

        int             exitcode, status, command = CMD_OK, event = EV_AOK;

        while (1) {

                event = event_check();
                command = command_check();
                command_handle(command, pid);

                if (command == CMD_OK && event == EV_AOK)
                        pid = fork();
                else
                        pid = -2;

                switch (pid) {
                case 0: /* we are the child */
                        vbprintf("(child) Executing %s in work directory %s\n"
                                 ,cmd, workdir);
                        chdir(workdir);

                        logging_rotate();
                        logging_init();
                        exitcode = execl(cmd, cmd, args,
                                         (char *)NULL);
                        if (exitcode < 0) {
                                perror("execl");
                        }
                        exit(exitcode);
                        break;
                case -1:        /* error */
                        err(EX_OSERR, "Couldn't fork: ");
                        break;
                case -2:        /* stop */
                        vbprintf("Not reforking. Waiting %d seconds\n", delay);
                        sleep(delay);
                        break;
                default:        /* we are the parent */
                        vbprintf("(parent) Forked process with pid %d\n", pid);
                        while (waitpid(pid, &status, WNOHANG) == 0) {

                                /* Do something while child is running */

                                dbprintf("Waiting for child (%d) to terminate\n",
                                        pid);
                                running = TRUE;
                                command = command_check();
                                command_handle(command, pid);

                                sleep(delay);
                        }
                        /* if we get here, the child process must have died */
                        running = FALSE;
                        command = command_check();
                        command_handle(command, pid);
                        break;
                }
                if (command == CMD_STOP) {

                        struct stat     st;

                        /* check if HALTFILE still exists */
                        chdir(workdir);
                        if (stat(HALTFILE, &st) < 0) {
                                vbprintf("Haltfile gone. Resuming...\n");
                                command = CMD_OK;
                        }
                        if (event == EV_AOK) {
                                vbprintf("Event over. Resuming...\n");
                                command = CMD_OK;
                        }
                }
        }
        return;
}