Exemplo n.º 1
0
static void
catch_sig_watchdog(int sig)
{
    switch (sig)
    {
    case SIGALRM:
        watchdog_on_timer();
        break;
    case SIGHUP:
        watchdog_on_sighup();
        break;
    case SIGUSR1:
        watchdog_on_sigusr1();
        break;
    case SIGUSR2:
        watchdog_on_sigusr2();
        break;
    case SIGTERM:
        remove(WD_PID_FILE);
#if defined (BOARD_GPIO_BTN_WPS)
        cpu_gpio_irq_set(BOARD_GPIO_BTN_WPS, 0, 0, 0);
#endif
#if defined (BOARD_GPIO_BTN_WLTOG)
        cpu_gpio_irq_set(BOARD_GPIO_BTN_WLTOG, 0, 0, 0);
#endif
#if defined (BOARD_GPIO_BTN_RESET)
        cpu_gpio_irq_set(BOARD_GPIO_BTN_RESET, 0, 0, 0);
#endif
        wd_alarmtimer(0, 0);
        exit(0);
        break;
    }
}
Exemplo n.º 2
0
static void
notify_shutdown(void)
{
#if defined (BOARD_GPIO_BTN_PWR_CUT) && defined (BOARD_GPIO_BTN_PWR_INT)
	unsigned int i_button_value = BTN_PRESSED;

	if (cpu_gpio_get_pin(BOARD_GPIO_BTN_PWR_INT, &i_button_value) < 0)
		return;

	if (i_button_value == BTN_PRESSED)
		return;

	/* POWER button is released, shutdown now */
	cpu_gpio_irq_set(BOARD_GPIO_BTN_PWR_INT, 0, 0, 0);

	reset_signals();

	printf("Button POWER is released, shutdown system...\n");

	shutdown_router(2);

	printf("\nShutdown!\n\n");

	usleep(10000);

	sync();

	/* Power OFF */
	cpu_gpio_set_pin(BOARD_GPIO_BTN_PWR_CUT, 0);
#endif
}
Exemplo n.º 3
0
int
watchdog_main(int argc, char *argv[])
{
    FILE *fp;
    pid_t pid;
    struct sigaction sa;

    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = catch_sig_watchdog;
    sigemptyset(&sa.sa_mask);
    sigaddset(&sa.sa_mask, SIGALRM);
    sigaddset(&sa.sa_mask, SIGHUP);
    sigaddset(&sa.sa_mask, SIGUSR1);
    sigaddset(&sa.sa_mask, SIGUSR2);
    sigaction(SIGHUP, &sa, NULL);
    sigaction(SIGUSR1, &sa, NULL);
    sigaction(SIGUSR2, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGALRM, &sa, NULL);

    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = SIG_IGN;
    sigemptyset(&sa.sa_mask);
    sigaction(SIGPIPE, &sa, NULL);

    if (daemon(0, 0) < 0) {
        perror("daemon");
        exit(errno);
    }

    pid = getpid();

    /* never invoke oom killer */
    oom_score_adjust(pid, OOM_SCORE_ADJ_MIN);

    /* write pid */
    if ((fp = fopen(WD_PID_FILE, "w")) != NULL) {
        fprintf(fp, "%d", pid);
        fclose(fp);
    }

    nvram_set_int_temp("wd_notify_id", 0);

#if defined (BOARD_GPIO_BTN_WPS)
    cpu_gpio_irq_set(BOARD_GPIO_BTN_WPS, 0, 1, pid);
#endif
#if defined (BOARD_GPIO_BTN_WLTOG)
    cpu_gpio_irq_set(BOARD_GPIO_BTN_WLTOG, 0, 1, pid);
#endif
#if defined (BOARD_GPIO_BTN_RESET)
    cpu_gpio_irq_set(BOARD_GPIO_BTN_RESET, 0, 1, pid);
#endif

    /* set timer */
    wd_alarmtimer(WD_NORMAL_PERIOD, 0);

    /* most of time it goes to sleep */
    while (1) {
        pause();
    }

    return 0;
}