diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c
index c3f17d40a9f8e88ffa6c879f8574345d9432d850..eae092642afa81b83a246fca76e3ff008f115383 100644
--- a/cdr/cdr_pgsql.c
+++ b/cdr/cdr_pgsql.c
@@ -163,7 +163,7 @@ static int pgsql_log(struct ast_cdr *cdr)
 			if (strcmp(cur->name, "start") == 0 || strcmp(cur->name, "calldate") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
 					LENGTHEN_BUF2(13);
-					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", cdr->start.tv_sec);
+					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", (long) cdr->start.tv_sec);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
 					LENGTHEN_BUF2(31);
 					ast_str_append(&sql2, 0, "%s%f", first ? "" : ",", (double)cdr->start.tv_sec + (double)cdr->start.tv_usec / 1000000.0);
@@ -177,7 +177,7 @@ static int pgsql_log(struct ast_cdr *cdr)
 			} else if (strcmp(cur->name, "answer") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
 					LENGTHEN_BUF2(13);
-					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", cdr->answer.tv_sec);
+					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", (long) cdr->answer.tv_sec);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
 					LENGTHEN_BUF2(31);
 					ast_str_append(&sql2, 0, "%s%f", first ? "" : ",", (double)cdr->answer.tv_sec + (double)cdr->answer.tv_usec / 1000000.0);
@@ -191,7 +191,7 @@ static int pgsql_log(struct ast_cdr *cdr)
 			} else if (strcmp(cur->name, "end") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
 					LENGTHEN_BUF2(13);
-					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", cdr->end.tv_sec);
+					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", (long) cdr->end.tv_sec);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
 					LENGTHEN_BUF2(31);
 					ast_str_append(&sql2, 0, "%s%f", first ? "" : ",", (double)cdr->end.tv_sec + (double)cdr->end.tv_usec / 1000000.0);
diff --git a/cel/cel_pgsql.c b/cel/cel_pgsql.c
index cdb1d2a1649278f1f499b01eb5a8d36f68dcb4d5..17654875ce32e2eca900ed778fb99cc0230c437c 100644
--- a/cel/cel_pgsql.c
+++ b/cel/cel_pgsql.c
@@ -166,7 +166,7 @@ static void pgsql_log(const struct ast_event *event, void *userdata)
 			if (strcmp(cur->name, "eventtime") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
 					LENGTHEN_BUF2(13);
-					ast_str_append(&sql2, 0, "%s%ld", SEP, record.event_time.tv_sec);
+					ast_str_append(&sql2, 0, "%s%ld", SEP, (long) record.event_time.tv_sec);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
 					LENGTHEN_BUF2(31);
 					ast_str_append(&sql2, 0, "%s%f",
diff --git a/main/cel.c b/main/cel.c
index 9fe9993a0493c842401d0fc10291f480ceb52a21..0e08e95c65c382c195685f42ea3fc93aa2eeb48c 100644
--- a/main/cel.c
+++ b/main/cel.c
@@ -421,7 +421,7 @@ struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event
 	}
 
 	if (ast_strlen_zero(cel_dateformat)) {
-		snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", record.event_time.tv_sec,
+		snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", (long) record.event_time.tv_sec,
 				(long) record.event_time.tv_usec);
 	} else {
 		struct ast_tm tm;
diff --git a/main/features.c b/main/features.c
index 5a2bb02697a7d85bd55e66da5d0cdd07e9ea2599..44daf377903ebe167ea39a1461e0213fead26d0b 100644
--- a/main/features.c
+++ b/main/features.c
@@ -30,6 +30,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/_private.h"
 
 #include <pthread.h>
+#include <signal.h>
 #include <sys/time.h>
 #include <sys/signal.h>
 #include <netinet/in.h>
diff --git a/main/manager.c b/main/manager.c
index fdcf2bbc85b67ef0d656451f68b09752f6ee848e..f811987f799c491aa3f67ea7bce7ea58d1ece433 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -2159,7 +2159,7 @@ static int action_ping(struct mansession *s, const struct message *m)
 		"Ping: Pong\r\n"
 		"Timestamp: %ld.%06lu\r\n"
 		"\r\n",
-		now.tv_sec, (unsigned long) now.tv_usec);
+		(long) now.tv_sec, (unsigned long) now.tv_usec);
 	return 0;
 }
 
diff --git a/main/stdtime/localtime.c b/main/stdtime/localtime.c
index 4440a55eff15e226e19207e2639842320c065dd8..836ed215536f2d8c10c26cc60bac982b70cb1bd2 100644
--- a/main/stdtime/localtime.c
+++ b/main/stdtime/localtime.c
@@ -48,6 +48,7 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include <signal.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <float.h>
diff --git a/main/tcptls.c b/main/tcptls.c
index 5c419c4af827d8cec3c446e38a010837d2060e87..8c95502e7f4b0caf18e50cc3309032ea4a58e5b4 100644
--- a/main/tcptls.c
+++ b/main/tcptls.c
@@ -33,6 +33,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include <fcntl.h>
 #endif
 
+#include <signal.h>
 #include <sys/signal.h>
 
 #include "asterisk/compat.h"
diff --git a/main/test.c b/main/test.c
index c5223e6a8fe860633232abcdc0800e33197c5ed7..766775c7aa7605280d1c006ea23a1a1b45d6b2c9 100644
--- a/main/test.c
+++ b/main/test.c
@@ -848,7 +848,7 @@ static char *test_cli_generate_results(struct ast_cli_entry *e, int cmd, struct
 			if (!(buf = ast_str_create(256))) {
 				return NULL;
 			}
-			ast_str_set(&buf, 0, "%s/asterisk_test_results-%ld.%s", ast_config_AST_LOG_DIR, time.tv_sec, type);
+			ast_str_set(&buf, 0, "%s/asterisk_test_results-%ld.%s", ast_config_AST_LOG_DIR, (long) time.tv_sec, type);
 
 			file = ast_str_buffer(buf);
 		}