Пример #1
0
void
setup_sighandlers(void)
{
  struct sigaction saction;

  sigemptyset(&saction.sa_mask);
  saction.sa_flags = 0;

  if (success_when_zero) {
    saction.sa_handler = zero_handler;
  }
  else {
    saction.sa_handler = timebomb_handler;

    if (sigaction(SIGALRM, &saction, NULL)) {
      perror("sigaction");
      _exit(EXIT_FAILURE);
    }
  }

  if (sigaction(SIGINT, &saction, NULL)) {
    perror("sigaction");
    _exit(EXIT_FAILURE);
  }

  if (success_when_timebomb) {
    setup_sigchld();
  }
}
Пример #2
0
BOOL fork_exec_and_wait(char *browser_fmt, char *url)
{
    pid_t child;
    char buffer[MAX_PATH];
    char *cur, *next, *ins, *ptr;
    char *args[MAX_ARGS+1];
    int status, argc, len;

    argc = 0;
    ins = strstr(browser_fmt, "%s");
    cur = browser_fmt;
    ptr = buffer;
    while (argc < MAX_ARGS) {
        next = strchr(cur, ' ');
        if (!next) next = cur + strlen(cur);

        if (ins >= cur && ins < next) {
            /* it's the %s argument, I'm going to assume it's always its own parameter */
            args[argc++] = url;
        } else {
            /* anything else */
            args[argc++] = ptr;
            len = next - cur;
            if ((ptr + len - buffer) >= MAX_PATH)
                len = buffer + MAX_PATH - ptr - 1;
            memcpy(ptr, cur, len);
            ptr += len;
            *ptr++ = 0;
            if ((ptr - buffer) == MAX_PATH)
                break;
        }

        if (!*next) break;
        cur = next+1;
    }
    args[argc] = NULL;

    setup_sigchld();
    child = fork();
    if (child == -1)
    {
        return FALSE;
    }
    if (child == 0)
    { /* child */
        fprintf(stderr, "using browser %s\n", args[0]);
        unsetenv("TEMP"); /* mozilla doesn't like wines TEMP (or TMP) env variable */
        unsetenv("TMP");
        execvp(args[0], args);
        _exit(1);
    }
    /* parent */

    waitpid(child, &status, 0);

    return TRUE;
}