mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
virsh-console: Avoid using signal() in multithreaded application
Man page for signal states: "The effects of signal() in a multithreaded process are unspecified." Switch signal() to sigaction in virsh console code.
This commit is contained in:
parent
02eaf1821c
commit
3e29c77a26
@ -312,32 +312,34 @@ vshRunConsole(vshControl *ctl,
|
|||||||
const char *dev_name,
|
const char *dev_name,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
void (*old_sigquit)(int);
|
|
||||||
void (*old_sigterm)(int);
|
|
||||||
void (*old_sigint)(int);
|
|
||||||
void (*old_sighup)(int);
|
|
||||||
void (*old_sigpipe)(int);
|
|
||||||
virConsolePtr con = NULL;
|
virConsolePtr con = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
/* Put STDIN into raw mode so that stuff typed
|
struct sigaction old_sigquit;
|
||||||
does not echo to the screen (the TTY reads will
|
struct sigaction old_sigterm;
|
||||||
result in it being echoed back already), and
|
struct sigaction old_sigint;
|
||||||
also ensure Ctrl-C, etc is blocked, and misc
|
struct sigaction old_sighup;
|
||||||
other bits */
|
struct sigaction old_sigpipe;
|
||||||
|
struct sigaction sighandler = {.sa_handler = virConsoleHandleSignal,
|
||||||
|
.sa_flags = SA_SIGINFO };
|
||||||
|
|
||||||
|
sigemptyset(&sighandler.sa_mask);
|
||||||
|
|
||||||
|
/* Put STDIN into raw mode so that stuff typed does not echo to the screen
|
||||||
|
* (the TTY reads will result in it being echoed back already), and also
|
||||||
|
* ensure Ctrl-C, etc is blocked, and misc other bits */
|
||||||
if (vshTTYMakeRaw(ctl, true) < 0)
|
if (vshTTYMakeRaw(ctl, true) < 0)
|
||||||
goto resettty;
|
goto resettty;
|
||||||
|
|
||||||
/* Trap all common signals so that we can safely restore
|
/* Trap all common signals so that we can safely restore the original
|
||||||
the original terminal settings on STDIN before the
|
* terminal settings on STDIN before the process exits - people don't like
|
||||||
process exits - people don't like being left with a
|
* being left with a messed up terminal ! */
|
||||||
messed up terminal ! */
|
|
||||||
old_sigquit = signal(SIGQUIT, virConsoleHandleSignal);
|
|
||||||
old_sigterm = signal(SIGTERM, virConsoleHandleSignal);
|
|
||||||
old_sigint = signal(SIGINT, virConsoleHandleSignal);
|
|
||||||
old_sighup = signal(SIGHUP, virConsoleHandleSignal);
|
|
||||||
old_sigpipe = signal(SIGPIPE, virConsoleHandleSignal);
|
|
||||||
got_signal = 0;
|
got_signal = 0;
|
||||||
|
sigaction(SIGQUIT, &sighandler, &old_sigquit);
|
||||||
|
sigaction(SIGTERM, &sighandler, &old_sigterm);
|
||||||
|
sigaction(SIGINT, &sighandler, &old_sigint);
|
||||||
|
sigaction(SIGHUP, &sighandler, &old_sighup);
|
||||||
|
sigaction(SIGPIPE, &sighandler, &old_sigpipe);
|
||||||
|
|
||||||
if (VIR_ALLOC(con) < 0)
|
if (VIR_ALLOC(con) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -384,11 +386,11 @@ cleanup:
|
|||||||
virConsoleFree(con);
|
virConsoleFree(con);
|
||||||
|
|
||||||
/* Restore original signal handlers */
|
/* Restore original signal handlers */
|
||||||
signal(SIGPIPE, old_sigpipe);
|
sigaction(SIGQUIT, &old_sigquit, NULL);
|
||||||
signal(SIGHUP, old_sighup);
|
sigaction(SIGTERM, &old_sigterm, NULL);
|
||||||
signal(SIGINT, old_sigint);
|
sigaction(SIGINT, &old_sigint, NULL);
|
||||||
signal(SIGTERM, old_sigterm);
|
sigaction(SIGHUP, &old_sighup, NULL);
|
||||||
signal(SIGQUIT, old_sigquit);
|
sigaction(SIGPIPE, &old_sigpipe, NULL);
|
||||||
|
|
||||||
resettty:
|
resettty:
|
||||||
/* Put STDIN back into the (sane?) state we found
|
/* Put STDIN back into the (sane?) state we found
|
||||||
|
Loading…
x
Reference in New Issue
Block a user