try to handle exec-gp2xmenu exit
[ginge.git] / loader / host.c
CommitLineData
8424752c 1/*
2 * GINGE - GINGE Is Not Gp2x Emulator
3 * (C) notaz, 2010-2011,2015
4 *
5 * This work is licensed under the MAME license, see COPYING file for details.
6 */
15a2d3ea 7#define _GNU_SOURCE 1 // for plat.c
ad439e71 8#include <stdio.h>
9#include <stdarg.h>
8424752c 10#include <linux/input.h>
11
12#include "../common/libpicofe/input.h"
13#include "../common/libpicofe/linux/in_evdev.h"
ad439e71 14
15#include "header.h"
16#include "realfuncs.h"
17
f7767d0f 18// must be affected by realfuncs.h
19#include "../common/libpicofe/input.c"
20#include "../common/libpicofe/linux/plat.c"
21#include "../common/libpicofe/linux/in_evdev.c"
22
ad439e71 23#ifdef PND
24#include "host_pnd.c"
25#elif defined(WIZ)
26#include "host_wiz.c"
27#endif
28
ad439e71 29int host_init(void)
30{
31 in_init();
8424752c 32 host_init_input();
ad439e71 33 in_probe();
34
35 return 0;
36}
37
38int host_read_btns(void)
39{
40 int actions[IN_BINDTYPE_COUNT] = { 0, };
41
42 in_update(actions);
43 host_actions(actions);
44
45 return actions[IN_BINDTYPE_PLAYER12];
46}
47
78684356 48void host_forced_exit(int status)
ad439e71 49{
50 // exit() might not be enough because loader and app data is out of sync,
51 // and other threads (which are really processes on this old glibc used)
52 // might not exit properly.
7d4e5f81 53 char cmd[64];
54
55 printf("forced exit...\n");
56
57 snprintf(cmd, sizeof(cmd), "killall %s", g_argv[0]);
58 system(cmd);
ad439e71 59 usleep(300000);
7d4e5f81 60 snprintf(cmd, sizeof(cmd), "killall -9 %s", g_argv[0]);
61 system(cmd);
78684356 62 exit(status);
ad439e71 63}
8424752c 64
65// vim:shiftwidth=2:expandtab