if (already_dead) {
_exit(1);
}
- if (sig == SIGCHLD) { /* Ignore sigchld */
+ Dmsg1(200, "sig=%d\n", sig);
+ /* Ignore certain signals */
+ if (sig == SIGCHLD || sig == SIGUSR2) {
return;
}
already_dead = sig;
static char pid_buf[20];
static char btpath[400];
pid_t pid;
+ int exelen = strlen(exepath);
fprintf(stderr, "Kaboom! %s, %s got signal %d. Attempting traceback.\n",
exename, my_name, sig);
- if (strlen(exepath) + 12 > (int)sizeof(btpath)) {
+ if (exelen + 12 > (int)sizeof(btpath)) {
strcpy(btpath, "btraceback");
} else {
strcpy(btpath, exepath);
- strcat(btpath, "/btraceback");
+ if (btpath[exelen-1] != '/') {
+ strcat(btpath, "/btraceback");
+ } else {
+ strcat(btpath, "btraceback");
+ }
+ }
+ if (btpath[exelen-1] != '/') {
+ strcat(exepath, "/");
}
- strcat(exepath, "/");
strcat(exepath, exename);
if (chdir(working_directory) !=0) { /* dump in working directory */
Pmsg2(000, "chdir to %s failed. ERR=%s\n", working_directory, strerror(errno));
argv[1] = exepath; /* path to exe */
argv[2] = pid_buf;
argv[3] = (char *)NULL;
+ fprintf(stderr, "Calling: %s %s %s\n", btpath, exepath, pid_buf);
if (execv(btpath, argv) != 0) {
printf("execv: %s failed: ERR=%s\n", btpath, strerror(errno));
}
default: /* parent */
break;
}
+ /* Parent continue here, waiting for child */
sigdefault.sa_flags = 0;
sigdefault.sa_handler = SIG_DFL;
sigfillset(&sigdefault.sa_mask);
waitpid(pid, NULL, 0); /* wait for child to produce dump */
fprintf(stderr, "Traceback complete, attempting cleanup ...\n");
Dmsg0(500, "Done waitpid\n");
- exit_handler(1); /* clean up if possible */
+ exit_handler(sig); /* clean up if possible */
Dmsg0(500, "Done exit_handler\n");
} else {
Dmsg0(500, "Doing sleep\n");
- sleep(30);
+ bmicrosleep(30, 0);
}
fprintf(stderr, "It looks like the traceback worked ...\n");
}
#endif
- exit_handler(1);
+ exit_handler(sig);
}
/*