Skip to content

Commit

Permalink
magnet test records its PID in /var/run/funkey.pid and USR1 signal ha…
Browse files Browse the repository at this point in the history
…ndling exits correctly
  • Loading branch information
Vincent-FK committed Jan 19, 2021
1 parent f8e5bc9 commit ab4b5c7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion prodScreen_magnetTest.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
#include "funkey_prod_screens.h"
#include <signal.h>

#define SHELL_CMD_RECORD_PID "record_pid"
#define SHELL_CMD_CANCEL_SCHED_POWERDOWN "cancel_sched_powerdown"

/* Static variable */
static int stop_menu_loop = 0;
static int res = EXIT_FAILURE;

/* Handler for SIGUSR1, caused by closing the console */
void handle_sigusr1(int sig)
{

/* Send command to cancel any previously scheduled powerdown */
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
{
/* Countdown is still ticking, so better do nothing
than start writing and get interrupted!
*/
printf("Failed to cancel scheduled shutdown\n");
//exit(0);
}

//printf("Caught signal USR1 %d\n", sig);
stop_menu_loop = 1;
res = 0;
}

/// -------------- FUNCTIONS IMPLEMENTATION --------------
static int wait_event_loop(){

SDL_Event event;
int res = EXIT_FAILURE;

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

/* Record current PID */
char shell_cmd[100];
sprintf(shell_cmd, "%s %d", SHELL_CMD_RECORD_PID, getpid());
system(shell_cmd);

/* Init Signals */
signal(SIGUSR1, handle_sigusr1);

Expand Down

0 comments on commit ab4b5c7

Please sign in to comment.