-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
# include <unistd.h>
# include <signal.h>
# include <string.h>
# include <stdlib.h>
static int fds[2];
static void sgsgvhndlr (int signr)
{
write (fds[1], &signr, 1);
_Exit (EXIT_FAILURE);
}
static int err (int exit_code, char *msg)
{
write (STDERR_FILENO, msg, strlen (msg));
write (STDERR_FILENO, "\n", 1);
_Exit (EXIT_FAILURE);
}
int main (void)
{
int rc;
pid_t pid;
rc = pipe (fds);
if (rc != 0) err (EXIT_FAILURE, "pipe");
pid = fork ();
if (pid == -1) err (EXIT_FAILURE, "fork");
if (pid) {
rc = read (fds[0], &pid, 1);
if (rc - 1) err (EXIT_FAILURE, "read");
write (STDOUT_FILENO, "gdb\n", 4);
/* execute gdb */
return EXIT_SUCCESS;
}
else {
struct sigaction sa = {0,};
sa.sa_handler = sgsgvhndlr;
rc = sigaction (SIGSEGV, &sa, NULL);
if (rc) err (EXIT_SUCCESS, "sigaction");
return *(char*)0;
}
}
Metadata
Metadata
Assignees
Labels
No labels