Esempio n. 1
0
static void
frontend_dlg_run (WDialog * h)
{
    Widget *wh = WIDGET (h);
    Gpm_Event event;

    event.x = -1;

    /* close opened editors, viewers, etc */
    if (!widget_get_state (wh, WST_MODAL) && mc_global.midnight_shutdown)
    {
        send_message (h, NULL, MSG_VALIDATE, 0, NULL);
        return;
    }

    while (widget_get_state (wh, WST_ACTIVE))
    {
        int d_key;

        if (mc_global.tty.winch_flag != 0)
            dialog_change_screen_size ();

        if (is_idle ())
        {
            if (idle_hook)
                execute_hooks (idle_hook);

            while (widget_get_state (wh, WST_IDLE) && is_idle ())
                send_message (wh, NULL, MSG_IDLE, 0, NULL);

            /* Allow terminating the dialog from the idle handler */
            if (!widget_get_state (wh, WST_ACTIVE))
                break;
        }

        update_cursor (h);

        /* Clear interrupt flag */
        tty_got_interrupt ();
        d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE);

        dlg_process_event (h, d_key, &event);

        if (widget_get_state (wh, WST_CLOSED))
            send_message (h, NULL, MSG_VALIDATE, 0, NULL);
    }
}
Esempio n. 2
0
File: dialog.c Progetto: ryanlee/mc
static void
frontend_run_dlg (Dlg_head * h)
{
    int d_key;
    Gpm_Event event;

    event.x = -1;

    /* close opened editors, viewers, etc */
    if (!h->modal && mc_global.midnight_shutdown)
    {
        h->callback (h, NULL, DLG_VALIDATE, 0, NULL);
        return;
    }

    while (h->state == DLG_ACTIVE)
    {
        if (mc_global.tty.winch_flag)
            dialog_change_screen_size ();

        if (is_idle ())
        {
            if (idle_hook)
                execute_hooks (idle_hook);

            while ((h->flags & DLG_WANT_IDLE) && is_idle ())
                h->callback (h, NULL, DLG_IDLE, 0, NULL);

            /* Allow terminating the dialog from the idle handler */
            if (h->state != DLG_ACTIVE)
                break;
        }

        update_cursor (h);

        /* Clear interrupt flag */
        tty_got_interrupt ();
        d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE);

        dlg_process_event (h, d_key, &event);

        if (h->state == DLG_CLOSED)
            h->callback (h, NULL, DLG_VALIDATE, 0, NULL);
    }
}
Esempio n. 3
0
int start(char* command) {
  int pid = fork();
  if (pid == -1) {
    fprintf(stderr, "Error: %s\n", strerror(errno));
    exit(2);
  }
  if (pid > 0) {
    program_pid = pid;
    DEBUG("pid: %d\n", pid);
    write_to_log("Started '%s' with pid %d", command, pid);
    while (1) { /* We'll break out of this loops once we seem dead. */
      if (check_pid(pid))
        break;
      if (check_tcp_ports()) {
        write_to_log("One of our tcp ports is dead, time to kill our child.");
        DEBUG("One of our tcp ports is dead.. Let's send it a SIGKILL.\n");
        kill(pid, SIGKILL);
        break;
      }
      sleep(interval);
    }
    fprintf(stderr, "Our child seems dead :( let's restart it.\n");
    reset_tcp_ports();
    execute_hooks();
    write_to_log("Our child '%s' died", command);
//    start(command);
    return 0;
  } else if (pid == 0) {
    putenv("MALLOC_CHECK_=3");
    const char *argv[] = { "sh", "-c", command, NULL };
    execvp("sh", (char * const *) argv);
    fprintf(stderr, "execvp failed\n");
    exit(2);
  } else {
    write_to_log("fork() returned %d, this is bad.", pid);
    DEBUG("fork() returned %d, this is bad.\n", pid);
    exit(3);
  }
}