mirror of
https://github.com/FunKey-Project/FunKey-ProdScreens.git
synced 2026-06-02 09:06:49 +02:00
magnet test records its PID in /var/run/funkey.pid and USR1 signal handling exits correctly
This commit is contained in:
@@ -1,21 +1,36 @@
|
|||||||
#include "funkey_prod_screens.h"
|
#include "funkey_prod_screens.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#define SHELL_CMD_RECORD_PID "record_pid"
|
||||||
|
#define SHELL_CMD_CANCEL_SCHED_POWERDOWN "cancel_sched_powerdown"
|
||||||
|
|
||||||
/* Static variable */
|
/* Static variable */
|
||||||
static int stop_menu_loop = 0;
|
static int stop_menu_loop = 0;
|
||||||
|
static int res = EXIT_FAILURE;
|
||||||
|
|
||||||
/* Handler for SIGUSR1, caused by closing the console */
|
/* Handler for SIGUSR1, caused by closing the console */
|
||||||
void handle_sigusr1(int sig)
|
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);
|
//printf("Caught signal USR1 %d\n", sig);
|
||||||
stop_menu_loop = 1;
|
stop_menu_loop = 1;
|
||||||
|
res = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// -------------- FUNCTIONS IMPLEMENTATION --------------
|
/// -------------- FUNCTIONS IMPLEMENTATION --------------
|
||||||
static int wait_event_loop(){
|
static int wait_event_loop(){
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int res = EXIT_FAILURE;
|
|
||||||
|
|
||||||
/// -------- Main loop ---------
|
/// -------- Main loop ---------
|
||||||
while (!stop_menu_loop)
|
while (!stop_menu_loop)
|
||||||
@@ -61,6 +76,11 @@ int launch_prod_screen_magnet(int argc, char *argv[]){
|
|||||||
SDL_Surface *text_surface = NULL;
|
SDL_Surface *text_surface = NULL;
|
||||||
SDL_Rect text_pos;
|
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 */
|
/* Init Signals */
|
||||||
signal(SIGUSR1, handle_sigusr1);
|
signal(SIGUSR1, handle_sigusr1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user