summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2017-07-13 16:44:37 +0300
committerDmitry Kozlov <xeb@mail.ru>2017-07-13 16:44:37 +0300
commit7bfde7ac526337e18673c57d85f83faaf4beeb12 (patch)
treed491778a72a4588531d80c7533971d5c93c392d8
parente8dda21218a0bcb5363490a35e2cfed798421f2c (diff)
downloadaccel-ppp-xebd-7bfde7ac526337e18673c57d85f83faaf4beeb12.tar.gz
accel-ppp-xebd-7bfde7ac526337e18673c57d85f83faaf4beeb12.zip
improved SIGSEGV handler
-rw-r--r--accel-pppd/main.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/accel-pppd/main.c b/accel-pppd/main.c
index 02ada1d..0f85c77 100644
--- a/accel-pppd/main.c
+++ b/accel-pppd/main.c
@@ -169,53 +169,55 @@ void core_restart(int soft)
static void sigsegv(int num)
{
- char cmd[PATH_MAX];
- char fname[128];
+ char cmd[128];
+ char dump[128];
char exec_file[PATH_MAX];
- struct rlimit lim;
pid_t pid;
- int status;
+ FILE *f;
+ int fd;
+ char pid_str[16];
+ unsigned int t;
pthread_sigmask(SIG_SETMASK, &orig_set, NULL);
if (conf_dump) {
- FILE *f;
- unsigned int t = time(NULL);
-
+ t = time(NULL);
+ sprintf(pid_str, "%u", getpid());
+ sprintf(cmd, "cmd-%u", t);
chdir(conf_dump);
- sprintf(fname, "cmd-%u", t);
- f = fopen(fname, "w");
+ pid = fork();
+ if (pid == 0) {
+ printf("starting gdb...\n");
+ sprintf(dump, "dump-%u", t);
+ fd = open(dump, O_CREAT|O_TRUNC|O_WRONLY,0600);
+ if (fd == -1)
+ _exit(0);
+
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ close(fd);
+
+ f = fopen(cmd, "w");
if (!f)
- goto out;
- fprintf(f, "thread apply all bt full\ndetach\nquit\n");
+ _exit(0);
+ fprintf(f, "info shared\nthread apply all bt full\ngenerate-core-file core-%u\ndetach\nquit\n", t);
fclose(f);
- sprintf(exec_file, "/proc/%u/exe", getpid());
+ sprintf(exec_file, "/proc/%s/exe", pid_str);
readlink(exec_file, exec_file, PATH_MAX);
- sprintf(cmd, "gdb -x %s %s %d > dump-%u", fname, exec_file, getpid(), t);
-
- system(cmd);
-
- unlink(fname);
- }
-
-out:
- pid = fork();
- if (pid) {
- waitpid(pid, &status, 0);
- __core_restart(1);
- }
+ execlp("gdb", "gdb", "-x", cmd, exec_file, pid_str, NULL);
+ perror("exec");
+ _exit(0);
+ }
- if (conf_dump) {
- lim.rlim_cur = RLIM_INFINITY;
- lim.rlim_max = RLIM_INFINITY;
+ printf("waitpid: %i\n", waitpid(pid, NULL, 0));
- setrlimit(RLIMIT_CORE, &lim);
+ unlink(cmd);
}
- abort();
+ __core_restart(1);
}
static void shutdown_cb()