aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-05-26 21:19:49 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-05-26 21:19:49 +0000
commitac80f396880402ab93e38c54cc1c92a91c3c1a75 (patch)
tree6b8e8c7345155893b316f35e8c71b14c95b425c5
parent51a19a149f0ea28efed4087f1a037c9cc67178b4 (diff)
Merged revisions 266146 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r266146 | tilghman | 2010-05-26 16:17:46 -0500 (Wed, 26 May 2010) | 21 lines Merged revisions 266142 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r266142 | tilghman | 2010-05-26 16:11:44 -0500 (Wed, 26 May 2010) | 14 lines Use sigaction for signals which should persist past the initial trigger, not signal. If you call signal() in a Solaris signal handler, instead of just resetting the signal handler, it causes the signal to refire, because the signal is not marked as handled prior to the signal handler being called. This effectively causes Solaris to immediately exceed the threadstack in recursive signal handlers and crash. (closes issue #17000) Reported by: rmcgilvr Patches: 20100526__issue17000.diff.txt uploaded by tilghman (license 14) Tested by: rmcgilvr ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.2@266154 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--main/asterisk.c55
-rw-r--r--main/logger.c9
-rw-r--r--utils/extconf.c20
3 files changed, 55 insertions, 29 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 187b59416..147b3042b 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -962,16 +962,24 @@ static int fdprint(int fd, const char *s)
}
/*! \brief NULL handler so we can collect the child exit status */
-static void null_sig_handler(int sig)
+static void _null_sig_handler(int sig)
{
}
+static struct sigaction null_sig_handler = {
+ .sa_handler = _null_sig_handler,
+};
+
+static struct sigaction ignore_sig_handler = {
+ .sa_handler = SIG_IGN,
+};
+
AST_MUTEX_DEFINE_STATIC(safe_system_lock);
/*! \brief Keep track of how many threads are currently trying to wait*() on
* a child process */
static unsigned int safe_system_level = 0;
-static void *safe_system_prev_handler;
+static struct sigaction safe_system_prev_handler;
void ast_replace_sigchld(void)
{
@@ -981,8 +989,9 @@ void ast_replace_sigchld(void)
level = safe_system_level++;
/* only replace the handler if it has not already been done */
- if (level == 0)
- safe_system_prev_handler = signal(SIGCHLD, null_sig_handler);
+ if (level == 0) {
+ sigaction(SIGCHLD, &null_sig_handler, &safe_system_prev_handler);
+ }
ast_mutex_unlock(&safe_system_lock);
}
@@ -995,8 +1004,9 @@ void ast_unreplace_sigchld(void)
level = --safe_system_level;
/* only restore the handler if we are the last one */
- if (level == 0)
- signal(SIGCHLD, safe_system_prev_handler);
+ if (level == 0) {
+ sigaction(SIGCHLD, &safe_system_prev_handler, NULL);
+ }
ast_mutex_unlock(&safe_system_lock);
}
@@ -1429,13 +1439,16 @@ static int ast_tryconnect(void)
system call. We don't actually need to do anything though.
Remember: Cannot EVER ast_log from within a signal handler
*/
-static void urg_handler(int num)
+static void _urg_handler(int num)
{
- signal(num, urg_handler);
return;
}
-static void hup_handler(int num)
+static struct sigaction urg_handler = {
+ .sa_handler = _urg_handler,
+};
+
+static void _hup_handler(int num)
{
int a = 0;
if (option_verbose > 1)
@@ -1448,10 +1461,13 @@ static void hup_handler(int num)
fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno));
}
}
- signal(num, hup_handler);
}
-static void child_handler(int sig)
+static struct sigaction hup_handler = {
+ .sa_handler = _hup_handler,
+};
+
+static void _child_handler(int sig)
{
/* Must not ever ast_log or ast_verbose within signal handler */
int n, status;
@@ -1463,9 +1479,12 @@ static void child_handler(int sig)
;
if (n == 0 && option_debug)
printf("Huh? Child handler, but nobody there?\n");
- signal(sig, child_handler);
}
+static struct sigaction child_handler = {
+ .sa_handler = _child_handler,
+};
+
/*! \brief Set maximum open files */
static void set_ulimit(int value)
{
@@ -1664,7 +1683,7 @@ static void __quit_handler(int num)
sig_flags.need_quit = 1;
if (sig_alert_pipe[1] != -1) {
if (write(sig_alert_pipe[1], &a, sizeof(a)) < 0) {
- fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno));
+ fprintf(stderr, "quit_handler: write() failed: %s\n", strerror(errno));
}
}
/* There is no need to restore the signal handler here, since the app
@@ -3304,7 +3323,7 @@ int main(int argc, char *argv[])
/* Must install this signal handler up here to ensure that if the canary
* fails to execute that it doesn't kill the Asterisk process.
*/
- signal(SIGCHLD, child_handler);
+ sigaction(SIGCHLD, &child_handler, NULL);
/* It's common on some platforms to clear /var/run at boot. Create the
* socket file directory before we drop privileges. */
@@ -3503,7 +3522,7 @@ int main(int argc, char *argv[])
snprintf(canary_filename, sizeof(canary_filename), "%s/alt.asterisk.canary.tweet.tweet.tweet", ast_config_AST_RUN_DIR);
/* Don't let the canary child kill Asterisk, if it dies immediately */
- signal(SIGPIPE, SIG_IGN);
+ sigaction(SIGPIPE, &ignore_sig_handler, NULL);
canary_pid = fork();
if (canary_pid == 0) {
@@ -3550,11 +3569,11 @@ int main(int argc, char *argv[])
sigaddset(&sigs, SIGPIPE);
sigaddset(&sigs, SIGWINCH);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
- signal(SIGURG, urg_handler);
+ sigaction(SIGURG, &urg_handler, NULL);
signal(SIGINT, __quit_handler);
signal(SIGTERM, __quit_handler);
- signal(SIGHUP, hup_handler);
- signal(SIGPIPE, SIG_IGN);
+ sigaction(SIGHUP, &hup_handler, NULL);
+ sigaction(SIGPIPE, &ignore_sig_handler, NULL);
/* ensure that the random number generators are seeded with a different value every time
Asterisk is started
diff --git a/main/logger.c b/main/logger.c
index c764a52d4..2d81b1604 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -827,13 +827,16 @@ static struct ast_cli_entry cli_logger[] = {
AST_CLI_DEFINE(handle_logger_set_level, "Enables/Disables a specific logging level for this console")
};
-static int handle_SIGXFSZ(int sig)
+static void _handle_SIGXFSZ(int sig)
{
/* Indicate need to reload */
filesize_reload_needed = 1;
- return 0;
}
+static struct sigaction handle_SIGXFSZ = {
+ .sa_handler = _handle_SIGXFSZ,
+};
+
static void ast_log_vsyslog(int level, const char *file, int line, const char *function, char *str, long pid)
{
char buf[BUFSIZ];
@@ -1007,7 +1010,7 @@ int init_logger(void)
int res = 0;
/* auto rotate if sig SIGXFSZ comes a-knockin */
- (void) signal(SIGXFSZ, (void *) handle_SIGXFSZ);
+ sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
/* start logger thread */
ast_cond_init(&logcond, NULL);
diff --git a/utils/extconf.c b/utils/extconf.c
index 6d51143f5..fc6e2388d 100644
--- a/utils/extconf.c
+++ b/utils/extconf.c
@@ -1258,14 +1258,18 @@ static void CB_RESET(void )
/*! \brief Keep track of how many threads are currently trying to wait*() on
* a child process */
static unsigned int safe_system_level = 0;
-static void *safe_system_prev_handler;
+static struct sigaction safe_system_prev_handler;
/*! \brief NULL handler so we can collect the child exit status */
-static void null_sig_handler(int sig)
+static void _null_sig_handler(int sig)
{
}
+static struct sigaction null_sig_handler = {
+ .sa_handler = _null_sig_handler,
+};
+
void ast_replace_sigchld(void);
void ast_replace_sigchld(void)
@@ -1275,9 +1279,9 @@ void ast_replace_sigchld(void)
level = safe_system_level++;
/* only replace the handler if it has not already been done */
- if (level == 0)
- safe_system_prev_handler = signal(SIGCHLD, null_sig_handler);
-
+ if (level == 0) {
+ sigaction(SIGCHLD, &null_sig_handler, &safe_system_prev_handler);
+ }
}
void ast_unreplace_sigchld(void);
@@ -1289,9 +1293,9 @@ void ast_unreplace_sigchld(void)
level = --safe_system_level;
/* only restore the handler if we are the last one */
- if (level == 0)
- signal(SIGCHLD, safe_system_prev_handler);
-
+ if (level == 0) {
+ sigaction(SIGCHLD, &safe_system_prev_handler, NULL);
+ }
}
int ast_safe_system(const char *s);