|
1 | 1 | #include "funkey_prod_screens.h" |
2 | 2 | #include <signal.h> |
3 | 3 |
|
| 4 | +#define SHELL_CMD_RECORD_PID "record_pid" |
| 5 | +#define SHELL_CMD_CANCEL_SCHED_POWERDOWN "cancel_sched_powerdown" |
| 6 | + |
4 | 7 | /* Static variable */ |
5 | 8 | static int stop_menu_loop = 0; |
| 9 | +static int res = EXIT_FAILURE; |
6 | 10 |
|
7 | 11 | /* Handler for SIGUSR1, caused by closing the console */ |
8 | 12 | void handle_sigusr1(int sig) |
9 | 13 | { |
| 14 | + |
| 15 | + /* Send command to cancel any previously scheduled powerdown */ |
| 16 | + if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL) |
| 17 | + { |
| 18 | + /* Countdown is still ticking, so better do nothing |
| 19 | + than start writing and get interrupted! |
| 20 | + */ |
| 21 | + printf("Failed to cancel scheduled shutdown\n"); |
| 22 | + //exit(0); |
| 23 | + } |
| 24 | + |
10 | 25 | //printf("Caught signal USR1 %d\n", sig); |
11 | 26 | stop_menu_loop = 1; |
| 27 | + res = 0; |
12 | 28 | } |
13 | 29 |
|
14 | 30 | /// -------------- FUNCTIONS IMPLEMENTATION -------------- |
15 | 31 | static int wait_event_loop(){ |
16 | 32 |
|
17 | 33 | SDL_Event event; |
18 | | - int res = EXIT_FAILURE; |
19 | 34 |
|
20 | 35 | /// -------- Main loop --------- |
21 | 36 | while (!stop_menu_loop) |
@@ -61,6 +76,11 @@ int launch_prod_screen_magnet(int argc, char *argv[]){ |
61 | 76 | SDL_Surface *text_surface = NULL; |
62 | 77 | SDL_Rect text_pos; |
63 | 78 |
|
| 79 | + /* Record current PID */ |
| 80 | + char shell_cmd[100]; |
| 81 | + sprintf(shell_cmd, "%s %d", SHELL_CMD_RECORD_PID, getpid()); |
| 82 | + system(shell_cmd); |
| 83 | + |
64 | 84 | /* Init Signals */ |
65 | 85 | signal(SIGUSR1, handle_sigusr1); |
66 | 86 |
|
|
0 commit comments