summaryrefslogtreecommitdiff
path: root/main/tcptls.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2017-06-18 20:24:04 -0400
committerCorey Farrell <git@cfware.com>2017-07-21 14:04:33 -0500
commiteea9da2f42c23fae72bb5b67c51dd38ab3a92a8d (patch)
treee0e69955214e682e2e4550cb8c6298c5adc147b3 /main/tcptls.c
parent7fcb730997a54fd58a2edf47489f464c34c6e156 (diff)
Core: Add support for systemd socket activation.
This change adds support for socket activation of certain SOCK_STREAM listeners in Asterisk: * AMI / AMI over TLS * CLI * HTTP / HTTPS Example systemd units are provided. This support extends to any socket which is initialized using ast_tcptls_server_start, so any unknown modules using this function will support socket activation. Asterisk continues to function as normal if socket activation is not enabled or if systemd development headers are not available during build. ASTERISK-27063 #close Change-Id: Id814ee6a892f4b80d018365c8ad8d89063474f4d
Diffstat (limited to 'main/tcptls.c')
-rw-r--r--main/tcptls.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/main/tcptls.c b/main/tcptls.c
index a3c7dfa72..85859a343 100644
--- a/main/tcptls.c
+++ b/main/tcptls.c
@@ -40,6 +40,7 @@
#include "asterisk/compat.h"
#include "asterisk/tcptls.h"
+#include "asterisk/io.h"
#include "asterisk/http.h"
#include "asterisk/utils.h"
#include "asterisk/strings.h"
@@ -618,6 +619,7 @@ void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
int flags;
int x = 1;
int tls_changed = 0;
+ int sd_socket;
if (desc->tls_cfg) {
char hash[41];
@@ -689,6 +691,19 @@ void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
pthread_join(desc->master, NULL);
}
+ sd_socket = ast_sd_get_fd(SOCK_STREAM, &desc->local_address);
+
+ if (sd_socket != -1) {
+ if (desc->accept_fd != sd_socket) {
+ if (desc->accept_fd != -1) {
+ close(desc->accept_fd);
+ }
+ desc->accept_fd = sd_socket;
+ }
+
+ goto systemd_socket_activation;
+ }
+
if (desc->accept_fd != -1) {
close(desc->accept_fd);
}
@@ -718,6 +733,8 @@ void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
ast_log(LOG_ERROR, "Unable to listen for %s!\n", desc->name);
goto error;
}
+
+systemd_socket_activation:
flags = fcntl(desc->accept_fd, F_GETFL);
fcntl(desc->accept_fd, F_SETFL, flags | O_NONBLOCK);
if (ast_pthread_create_background(&desc->master, NULL, desc->accept_fn, desc)) {