Skip to content

Commit

Permalink
set SIGINT and SIGTSTP to default handlers; re-raise the signal
Browse files Browse the repository at this point in the history
  • Loading branch information
ddermendzhiev authored and Andrew Fasano committed Jul 1, 2024
1 parent dae80f2 commit b989674
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>

// Bind a shell to a serial console and ensure
// the session has support for job control (e.g.,
// ctrl+c, ctrl+z)

// Explicitly re-raise the signal to the default handler

void handle_sigint(int sig) {
signal(sig, SIG_DFL);
raise(sig);
}

void handle_sigtstp(int sig) {
signal(sig, SIG_DFL);
raise(sig);
}

int main(int argc, char **argv) {
int fd;

Expand Down Expand Up @@ -43,5 +56,9 @@ int main(int argc, char **argv) {
putenv("TERM=linux");
putenv("PATH=/sbin:/bin:/usr/sbin:/usr/bin");

// Set up signal handlers for SIGINT and SIGTSTP
signal(SIGINT, handle_sigint);
signal(SIGTSTP, handle_sigtstp);

return execl(SHELL, SHELL, NULL);
}

0 comments on commit b989674

Please sign in to comment.