akaros/tools/jenkins/utils/qemu_launcher.c
<<
>>
Prefs
   1#include <unistd.h>
   2#include <stdio.h>
   3#include <string.h>
   4#include <signal.h>
   5
   6pid_t pid;
   7
   8void signal_handler(int signal) {
   9        int res = kill(pid, SIGKILL);
  10}
  11
  12int main(int argc, char *argv[])
  13{
  14        pid = fork();
  15
  16        if (pid == -1) {
  17                perror("Fork failed when trying to spawn qemu process.\n");
  18                return 1;
  19        } else if (pid == 0) { /* Child process */
  20                char* prog_name = "qemu-system-x86_64";
  21                char* params[argc];
  22                int i;
  23
  24                params[0] = prog_name;
  25                for (i = 1; i < argc; ++i)
  26                {
  27                        params[i] = argv[i];
  28                }
  29                params[argc] = NULL;
  30
  31                execvp(prog_name, params);
  32        } else { /* Parent process */
  33                int status;
  34
  35                if (signal(SIGUSR1, signal_handler) == SIG_ERR) {
  36                        fputs("An error occurred while setting a signal handler.\n", stderr);
  37                        return 2;
  38                }
  39
  40                (void) waitpid(pid, &status, 0);
  41        }
  42
  43        return 0;
  44}
  45