Move code to linux_common.c

This commit is contained in:
twinaphex 2015-11-14 22:03:37 +01:00
parent 499c989df0
commit bfec58154e
3 changed files with 48 additions and 39 deletions

View File

@ -13,9 +13,14 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <signal.h>
#include <linux/input.h>
#include <linux/kd.h>
#include <termios.h>
#include <unistd.h>
#include "linux_common.h"
@ -80,3 +85,38 @@ bool linux_terminal_grab_stdin(void *data)
{
return linux_stdin_claimed;
}
static void linux_terminal_restore_signal(int sig)
{
linux_terminal_restore_input();
kill(getpid(), sig);
}
void linux_terminal_disable_input(void)
{
struct sigaction sa = {{0}};
/* Avoid accidentally typing stuff. */
if (!isatty(0))
return;
if (!linux_terminal_init())
{
linux_terminal_flush();
return;
}
sa.sa_handler = linux_terminal_restore_signal;
sa.sa_flags = SA_RESTART | SA_RESETHAND;
sigemptyset(&sa.sa_mask);
/* Trap some fatal signals. */
sigaction(SIGABRT, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
sigaction(SIGFPE, &sa, NULL);
sigaction(SIGILL, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGSEGV, &sa, NULL);
atexit(linux_terminal_restore_input);
}

View File

@ -28,4 +28,6 @@ void linux_terminal_claim_stdin(void);
bool linux_terminal_grab_stdin(void *data);
void linux_terminal_disable_input(void);
#endif

View File

@ -16,19 +16,21 @@
#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/poll.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <libudev.h>
#include <linux/types.h>
#include <linux/input.h>
#include <linux/kd.h>
#include <signal.h>
#include <unistd.h>
#include <file/file_path.h>
@ -697,41 +699,6 @@ static bool open_devices(udev_input_t *udev, const char *type, device_handle_cb
return true;
}
static void restore_terminal_signal(int sig)
{
linux_terminal_restore_input();
kill(getpid(), sig);
}
static void disable_terminal_input(void)
{
struct sigaction sa = {{0}};
/* Avoid accidentally typing stuff. */
if (!isatty(0))
return;
if (!linux_terminal_init())
{
linux_terminal_flush();
return;
}
sa.sa_handler = restore_terminal_signal;
sa.sa_flags = SA_RESTART | SA_RESETHAND;
sigemptyset(&sa.sa_mask);
/* Trap some fatal signals. */
sigaction(SIGABRT, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
sigaction(SIGFPE, &sa, NULL);
sigaction(SIGILL, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGSEGV, &sa, NULL);
atexit(linux_terminal_restore_input);
}
static void *udev_input_init(void)
{
settings_t *settings = config_get_ptr();
@ -847,7 +814,7 @@ static void *udev_input_init(void)
udev->joypad = input_joypad_init_driver(settings->input.joypad_driver, udev);
input_keymaps_init_keyboard_lut(rarch_key_map_linux);
disable_terminal_input();
linux_terminal_disable_input();
return udev;
error: