3 * Author: Mingqiang Zhuang
5 * Created on March 15, 2009
7 * (c) Copyright 2009, Schooner Information Technology, Inc.
8 * http://www.schoonerinfotech.com/
10 * Rewrite of stack dump:
11 * Copyright (C) 2009 Sun Microsystems
15 #include "mem_config.h"
23 #include "ms_memslap.h"
24 #include "ms_setting.h"
27 int ms_setup_sigsegv(void);
28 int ms_setup_sigpipe(void);
29 int ms_setup_sigint(void);
32 /* signal seg reaches, this function will run */
33 static void ms_signal_segv(int signum
, siginfo_t
*info
, void *ptr
)
35 UNUSED_ARGUMENT(signum
);
36 UNUSED_ARGUMENT(info
);
39 pthread_mutex_lock(&ms_global
.quit_mutex
);
40 fprintf(stderr
, "Segmentation fault occurred.\nStack trace:\n");
42 pandora_print_callstack(stderr
);
44 fprintf(stderr
, "End of stack trace\n");
45 pthread_mutex_unlock(&ms_global
.quit_mutex
);
49 /* signal int reaches, this function will run */
50 static void ms_signal_int(int signum
, siginfo_t
*info
, void *ptr
)
52 UNUSED_ARGUMENT(signum
);
53 UNUSED_ARGUMENT(info
);
56 pthread_mutex_lock(&ms_global
.quit_mutex
);
57 fprintf(stderr
, "SIGINT handled.\n");
58 pthread_mutex_unlock(&ms_global
.quit_mutex
);
66 * @return if success, return EXIT_SUCCESS, else return -1
68 int ms_setup_sigsegv(void)
70 struct sigaction action
;
72 memset(&action
, 0, sizeof(action
));
73 action
.sa_sigaction
= ms_signal_segv
;
74 action
.sa_flags
= SA_SIGINFO
;
75 if (sigaction(SIGSEGV
, &action
, NULL
) < 0)
82 } /* ms_setup_sigsegv */
86 * redirect signal pipe
88 * @return if success, return EXIT_SUCCESS, else return -1
90 int ms_setup_sigpipe(void)
92 /* ignore the SIGPIPE signal */
93 signal(SIGPIPE
, SIG_IGN
);
96 } /* ms_setup_sigpipe */
100 * redirect signal int
102 * @return if success, return EXIT_SUCCESS, else return -1
104 int ms_setup_sigint(void)
106 struct sigaction action_3
;
108 memset(&action_3
, 0, sizeof(action_3
));
109 action_3
.sa_sigaction
= ms_signal_int
;
110 action_3
.sa_flags
= SA_SIGINFO
;
111 if (sigaction(SIGINT
, &action_3
, NULL
) < 0)
118 } /* ms_setup_sigint */
121 #ifndef SIGSEGV_NO_AUTO_INIT
122 static void __attribute((constructor
)) ms_init(void)