… | |
… | |
33 | #include <signal.h> |
33 | #include <signal.h> |
34 | |
34 | |
35 | #include <global.h> |
35 | #include <global.h> |
36 | #include <material.h> |
36 | #include <material.h> |
37 | |
37 | |
|
|
38 | #include <sys/time.h> |
|
|
39 | #include <sys/resource.h> |
|
|
40 | |
38 | #include <glib.h> |
41 | #include <glib.h> |
39 | |
42 | |
40 | refcnt_base::refcnt_t refcnt_dummy; |
43 | refcnt_base::refcnt_t refcnt_dummy; |
41 | ssize_t slice_alloc; |
44 | ssize_t slice_alloc; |
42 | rand_gen rndm, rmg_rndm; |
45 | rand_gen rndm, rmg_rndm; |
… | |
… | |
446 | void |
449 | void |
447 | fork_abort (const char *msg) |
450 | fork_abort (const char *msg) |
448 | { |
451 | { |
449 | if (!fork ()) |
452 | if (!fork ()) |
450 | { |
453 | { |
|
|
454 | fprintf (stderr, "background fork_abort in progress, remove me when debugged.\n");//D |
|
|
455 | |
|
|
456 | signal (SIGINT , SIG_IGN); |
|
|
457 | signal (SIGTERM, SIG_IGN); |
451 | signal (SIGABRT, SIG_DFL); |
458 | signal (SIGABRT, SIG_IGN); |
|
|
459 | |
|
|
460 | signal (SIGSEGV, SIG_DFL); |
|
|
461 | signal (SIGBUS , SIG_DFL); |
|
|
462 | signal (SIGILL , SIG_DFL); |
|
|
463 | signal (SIGTRAP, SIG_DFL); |
|
|
464 | |
452 | // try to put corefiles into a subdirectory, if existing, to allow |
465 | // try to put corefiles into a subdirectory, if existing, to allow |
453 | // an administrator to reduce the I/O load. |
466 | // an administrator to reduce the I/O load. |
454 | chdir ("cores"); |
467 | chdir ("cores"); |
|
|
468 | |
|
|
469 | // try to detach us from as many external dependencies as possible |
|
|
470 | // as coredumping can take time by closing all fd's. |
|
|
471 | { |
|
|
472 | struct rlimit lim; |
|
|
473 | |
|
|
474 | if (getrlimit (RLIMIT_NOFILE, &lim)) |
|
|
475 | lim.rlim_cur = 1024; |
|
|
476 | |
|
|
477 | for (int i = 0; i < lim.rlim_cur; ++i) |
|
|
478 | close (i); |
|
|
479 | } |
|
|
480 | |
|
|
481 | { |
|
|
482 | sigset_t empty; |
|
|
483 | sigemptyset (&empty); |
|
|
484 | sigprocmask (SIG_SETMASK, &empty, 0); |
|
|
485 | } |
|
|
486 | |
|
|
487 | // try to coredump with SIGTRAP |
|
|
488 | kill (getpid (), SIGTRAP); |
455 | abort (); |
489 | abort (); |
456 | } |
490 | } |
457 | |
491 | |
458 | LOG (llevError, "fork abort: %s\n", msg); |
492 | LOG (llevError, "fork abort: %s\n", msg); |
459 | } |
493 | } |