Skip to content

Commit ab4b5c7

Browse files
committed
magnet test records its PID in /var/run/funkey.pid and USR1 signal handling exits correctly
1 parent f8e5bc9 commit ab4b5c7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

prodScreen_magnetTest.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
#include "funkey_prod_screens.h"
22
#include <signal.h>
33

4+
#define SHELL_CMD_RECORD_PID "record_pid"
5+
#define SHELL_CMD_CANCEL_SCHED_POWERDOWN "cancel_sched_powerdown"
6+
47
/* Static variable */
58
static int stop_menu_loop = 0;
9+
static int res = EXIT_FAILURE;
610

711
/* Handler for SIGUSR1, caused by closing the console */
812
void handle_sigusr1(int sig)
913
{
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+
1025
//printf("Caught signal USR1 %d\n", sig);
1126
stop_menu_loop = 1;
27+
res = 0;
1228
}
1329

1430
/// -------------- FUNCTIONS IMPLEMENTATION --------------
1531
static int wait_event_loop(){
1632

1733
SDL_Event event;
18-
int res = EXIT_FAILURE;
1934

2035
/// -------- Main loop ---------
2136
while (!stop_menu_loop)
@@ -61,6 +76,11 @@ int launch_prod_screen_magnet(int argc, char *argv[]){
6176
SDL_Surface *text_surface = NULL;
6277
SDL_Rect text_pos;
6378

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+
6484
/* Init Signals */
6585
signal(SIGUSR1, handle_sigusr1);
6686

0 commit comments

Comments
 (0)