Skip to content

Commit

Permalink
Moves finalise logic out of signal handler (#268)
Browse files Browse the repository at this point in the history
Signal handler now only sets a flag that is checked in main
  • Loading branch information
italo-sampaio authored Jan 21, 2025
1 parent 353c4cf commit 5e63f11
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions firmware/src/sgx/src/untrusted/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct arguments {
char *enclave_path;
};

// Global flag to indicate that the application should stop
static sig_atomic_t G_stop_requested = 0;

// Argp individual option parsing function
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
struct arguments *arguments = state->input;
Expand Down Expand Up @@ -106,7 +109,9 @@ static void finalise_with(int exit_code) {
static void finalise(int signum) {
(void)signum; // Suppress unused parameter warning

finalise_with(0);
// Note: Do not add any finalise logic directly here, just set the flag
// and let the main loop handle it
G_stop_requested = 1;
}

static void set_signal_handlers() {
Expand Down Expand Up @@ -157,16 +162,22 @@ int main(int argc, char **argv) {
unsigned int tx = 0;

while (true) {
if (G_stop_requested) {
break;
}

rx = io_exchange(tx);

if (rx) {
tx = eprx_system_process_apdu(rx);
}
}

LOG("Exited main loop unexpectedly\n");
finalise_with(0);
return 0;

main_error:
LOG("Exited main loop unexpectedly\n");
finalise_with(1);
return 1;
}

0 comments on commit 5e63f11

Please sign in to comment.