Revision 8d963e6a

b/os-posix.c
26 26
#include <unistd.h>
27 27
#include <fcntl.h>
28 28
#include <signal.h>
29
#include <sys/types.h>
30
#include <sys/wait.h>
29 31

  
30 32
/* Needed early for CONFIG_BSD etc. */
31 33
#include "config-host.h"
......
39 41
    act.sa_handler = SIG_IGN;
40 42
    sigaction(SIGPIPE, &act, NULL);
41 43
}
44

  
45
static void termsig_handler(int signal)
46
{
47
    qemu_system_shutdown_request();
48
}
49

  
50
static void sigchld_handler(int signal)
51
{
52
    waitpid(-1, NULL, WNOHANG);
53
}
54

  
55
void os_setup_signal_handling(void)
56
{
57
    struct sigaction act;
58

  
59
    memset(&act, 0, sizeof(act));
60
    act.sa_handler = termsig_handler;
61
    sigaction(SIGINT,  &act, NULL);
62
    sigaction(SIGHUP,  &act, NULL);
63
    sigaction(SIGTERM, &act, NULL);
64

  
65
    act.sa_handler = sigchld_handler;
66
    act.sa_flags = SA_NOCLDSTOP;
67
    sigaction(SIGCHLD, &act, NULL);
68
}
b/qemu-os-posix.h
30 30
{
31 31
}
32 32

  
33
void os_setup_signal_handling(void);
34

  
33 35
#endif
b/qemu-os-win32.h
41 41
void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
42 42

  
43 43
void os_host_main_loop_wait(int *timeout);
44

  
45
static inline void os_setup_signal_handling(void) {}
46

  
44 47
#endif
b/vl.c
1986 1986
    return -1;
1987 1987
}
1988 1988

  
1989
#ifndef _WIN32
1990

  
1991
static void termsig_handler(int signal)
1992
{
1993
    qemu_system_shutdown_request();
1994
}
1995

  
1996
static void sigchld_handler(int signal)
1997
{
1998
    waitpid(-1, NULL, WNOHANG);
1999
}
2000

  
2001
static void sighandler_setup(void)
2002
{
2003
    struct sigaction act;
2004

  
2005
    memset(&act, 0, sizeof(act));
2006
    act.sa_handler = termsig_handler;
2007
    sigaction(SIGINT,  &act, NULL);
2008
    sigaction(SIGHUP,  &act, NULL);
2009
    sigaction(SIGTERM, &act, NULL);
2010

  
2011
    act.sa_handler = sigchld_handler;
2012
    act.sa_flags = SA_NOCLDSTOP;
2013
    sigaction(SIGCHLD, &act, NULL);
2014
}
2015

  
2016
#endif
2017

  
2018 1989
#ifdef _WIN32
2019 1990
/* Look for support files in the same directory as the executable.  */
2020 1991
static char *find_datadir(const char *argv0)
......
3556 3527

  
3557 3528
    cpu_synchronize_all_post_init();
3558 3529

  
3559
#ifndef _WIN32
3560 3530
    /* must be after terminal init, SDL library changes signal handlers */
3561
    sighandler_setup();
3562
#endif
3531
    os_setup_signal_handling();
3563 3532

  
3564 3533
    set_numa_modes();
3565 3534

  

Also available in: Unified diff