2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "mem_config.h"
24 #include "ms_memslap.h"
25 #include "ms_setting.h"
28 int ms_setup_sigsegv(void);
29 int ms_setup_sigpipe(void);
30 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
) {
34 UNUSED_ARGUMENT(signum
);
35 UNUSED_ARGUMENT(info
);
38 pthread_mutex_lock(&ms_global
.quit_mutex
);
39 fprintf(stderr
, "Segmentation fault occurred.\nStack trace:\n");
41 pandora_print_callstack(stderr
);
43 fprintf(stderr
, "End of stack trace\n");
44 pthread_mutex_unlock(&ms_global
.quit_mutex
);
48 /* signal int reaches, this function will run */
49 static void ms_signal_int(int signum
, siginfo_t
*info
, void *ptr
) {
50 UNUSED_ARGUMENT(signum
);
51 UNUSED_ARGUMENT(info
);
54 pthread_mutex_lock(&ms_global
.quit_mutex
);
55 fprintf(stderr
, "SIGINT handled.\n");
56 pthread_mutex_unlock(&ms_global
.quit_mutex
);
63 * @return if success, return EXIT_SUCCESS, else return -1
65 int ms_setup_sigsegv(void) {
66 struct sigaction action
;
68 memset(&action
, 0, sizeof(action
));
69 action
.sa_sigaction
= ms_signal_segv
;
70 action
.sa_flags
= SA_SIGINFO
;
71 if (sigaction(SIGSEGV
, &action
, NULL
) < 0) {
77 } /* ms_setup_sigsegv */
80 * redirect signal pipe
82 * @return if success, return EXIT_SUCCESS, else return -1
84 int ms_setup_sigpipe(void) {
85 /* ignore the SIGPIPE signal */
86 signal(SIGPIPE
, SIG_IGN
);
89 } /* ms_setup_sigpipe */
94 * @return if success, return EXIT_SUCCESS, else return -1
96 int ms_setup_sigint(void) {
97 struct sigaction action_3
;
99 memset(&action_3
, 0, sizeof(action_3
));
100 action_3
.sa_sigaction
= ms_signal_int
;
101 action_3
.sa_flags
= SA_SIGINFO
;
102 if (sigaction(SIGINT
, &action_3
, NULL
) < 0) {
108 } /* ms_setup_sigint */
110 #ifndef SIGSEGV_NO_AUTO_INIT
111 static void __attribute((constructor
)) ms_init(void) {