aboutsummaryrefslogblamecommitdiff
path: root/gcc7.patch
blob: 113140e817ae741a6cd43b25dc2909cf451ae682 (plain) (tree)


















































































































































































































                                                                                                                                                         
From 0390d827eab62ad2d84f0d6db8278d683659c0ba Mon Sep 17 00:00:00 2001
From: Oleg Pereverzev <oleg.pereverzev@gmail.com>
Date: Mon, 12 Jun 2017 23:20:59 +0300
Subject: [PATCH] Support for GCC 7

---
 lib/runcmd.c               |  3 +++
 lib/snprintf.c             |  6 ++++++
 src/naemon/checks.c        | 12 +++++++++++-
 src/naemon/configuration.c | 13 +++++++++++--
 src/naemon/macros.c        | 18 ++++++++++++++++++
 src/naemon/xodtemplate.c   | 11 ++++++++++-
 6 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/lib/runcmd.c b/lib/runcmd.c
index eb6668fe..4e55fbd7 100644
--- a/lib/runcmd.c
+++ b/lib/runcmd.c
@@ -199,6 +199,9 @@ int runcmd_cmd2strv(const char *str, int *out_argc, char **out_argv)
 				set_state(STATE_INSQ | STATE_INARG);
 				continue;
 			}
+#if __GNUC__ >= 7
+			__attribute__((fallthrough));
+#endif
 		case '"':
 			if (have_state(STATE_INSQ))
 				break;
diff --git a/lib/snprintf.c b/lib/snprintf.c
index 49bf8962..80b69dbf 100644
--- a/lib/snprintf.c
+++ b/lib/snprintf.c
@@ -493,6 +493,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
 				break;
 			case 'X':
 				cnk->flags |= DP_F_UP;
+#if __GNUC__ >= 7
+				__attribute__((fallthrough));
+#endif
 			case 'x':
 				cnk->type = CNK_HEX;
 				cnk->flags |= DP_F_UNSIGNED;
@@ -503,6 +506,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
 			case 'G':
 			case 'F':
 				cnk->flags |= DP_F_UP;
+#if __GNUC__ >= 7
+			__attribute__((fallthrough));
+#endif
 			case 'a':
 				/* hex float not supported yet */
 			case 'e':
diff --git a/src/naemon/checks.c b/src/naemon/checks.c
index 97bd9f73..91d83ef1 100644
--- a/src/naemon/checks.c
+++ b/src/naemon/checks.c
@@ -207,6 +207,9 @@ int process_check_result_queue(char *dirname)
 	char *temp_buffer = NULL;
 	int result = OK, check_result_files = 0;
 	time_t start;
+#if __GNUC__ >= 7
+	unsigned int writesize;
+#endif
 
 	/* make sure we have what we need */
 	if (dirname == NULL) {
@@ -240,9 +243,16 @@ int process_check_result_queue(char *dirname)
 		}
 
 		/* create /path/to/file */
+                
+#if __GNUC__ >= 7
+		writesize = snprintf(file, sizeof(file), "%s/%s", dirname, dirfile->d_name);
+		if (writesize < (strlen(dirname) + strlen(dirfile->d_name) + 2)) 
+			nm_log(NSLOG_RUNTIME_WARNING, "Warning: truncated path to file in check result queue directory '%s'", dirfile->d_name);
+#else
 		snprintf(file, sizeof(file), "%s/%s", dirname, dirfile->d_name);
+#endif
 		file[sizeof(file) - 1] = '\x0';
-
+		
 		/* process this if it's a check result file... */
 		x = strlen(dirfile->d_name);
 		if (x == 7 && dirfile->d_name[0] == 'c') {
diff --git a/src/naemon/configuration.c b/src/naemon/configuration.c
index a2a8d3ed..c4dc97dd 100644
--- a/src/naemon/configuration.c
+++ b/src/naemon/configuration.c
@@ -59,6 +59,9 @@ read_config_file(const char *main_config_file, nagios_macros *mac)
 	char *argptr = NULL;
 	mmapfile *thefile = NULL;
 	DIR *tmpdir = NULL;
+#if __GNUC__ >= 7
+	unsigned int writesize;
+#endif
 
 	/* open the config file for reading */
 	if ((thefile = mmap_fopen(main_config_file)) == NULL) {
@@ -1021,10 +1024,16 @@ read_config_file(const char *main_config_file, nagios_macros *mac)
 					if (strcmp(dirfile->d_name + strlen(dirfile->d_name) - 4, ".cfg"))
 						continue;
 
-					/* create /path/to/file */
+					/* create /path/to/file */              
+#if __GNUC__ >= 7
+					writesize = snprintf(file, sizeof(file), "%s/%s", include_dir, dirfile->d_name);
+					if (writesize < (strlen(include_dir) + strlen(dirfile->d_name) + 2)) 
+						nm_log(NSLOG_RUNTIME_WARNING, "Warning: truncated path to sub-configuration file '%s'", dirfile->d_name);
+#else
 					snprintf(file, sizeof(file), "%s/%s", include_dir, dirfile->d_name);
+#endif
 					file[sizeof(file) - 1] = '\x0';
-
+					
 					error |= read_config_file(file, mac);
 				}
 				closedir(dirp);
diff --git a/src/naemon/macros.c b/src/naemon/macros.c
index 700bc821..13d817cf 100644
--- a/src/naemon/macros.c
+++ b/src/naemon/macros.c
@@ -1518,6 +1518,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
 		/***************/
 	case MACRO_HOSTGROUPNAMES:
 		*free_macro = TRUE;
+#if __GNUC__ >= 7
+		__attribute__((fallthrough));
+#endif
 	case MACRO_HOSTNAME:
 	case MACRO_HOSTALIAS:
 	case MACRO_HOSTADDRESS:
@@ -1612,6 +1615,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
 		/********************/
 	case MACRO_HOSTGROUPMEMBERS:
 		*free_macro = TRUE;
+#if __GNUC__ >= 7
+		__attribute__((fallthrough));
+#endif
 	case MACRO_HOSTGROUPNAME:
 	case MACRO_HOSTGROUPALIAS:
 	case MACRO_HOSTGROUPNOTES:
@@ -1640,6 +1646,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
 		/******************/
 	case MACRO_SERVICEGROUPNAMES:
 		*free_macro = TRUE;
+#if __GNUC__ >= 7
+		__attribute__((fallthrough));
+#endif
 	case MACRO_SERVICEDESC:
 	case MACRO_SERVICESTATE:
 	case MACRO_SERVICESTATEID:
@@ -1757,6 +1766,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
 	case MACRO_SERVICEGROUPNOTESURL:
 	case MACRO_SERVICEGROUPACTIONURL:
 		*free_macro = TRUE;
+#if __GNUC__ >= 7
+		__attribute__((fallthrough));
+#endif
 	case MACRO_SERVICEGROUPNAME:
 	case MACRO_SERVICEGROUPALIAS:
 		/* a standard servicegroup macro */
@@ -1781,6 +1793,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
 		/******************/
 	case MACRO_CONTACTGROUPNAMES:
 		*free_macro = TRUE;
+#if __GNUC__ >= 7
+		__attribute__((fallthrough));
+#endif
 	case MACRO_CONTACTNAME:
 	case MACRO_CONTACTALIAS:
 	case MACRO_CONTACTEMAIL:
@@ -1841,6 +1856,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
 		/***********************/
 	case MACRO_CONTACTGROUPMEMBERS:
 		*free_macro = TRUE;
+#if __GNUC__ >= 7
+		__attribute__((fallthrough));
+#endif
 	case MACRO_CONTACTGROUPNAME:
 	case MACRO_CONTACTGROUPALIAS:
 		/* a standard contactgroup macro */
diff --git a/src/naemon/xodtemplate.c b/src/naemon/xodtemplate.c
index d5fd1cda..225fc40a 100644
--- a/src/naemon/xodtemplate.c
+++ b/src/naemon/xodtemplate.c
@@ -8443,7 +8443,10 @@ static int xodtemplate_process_config_dir(char *dir_name)
 	int result = OK;
 	register int x = 0;
 	struct stat stat_buf;
-
+#if __GNUC__ >= 7
+	unsigned int writesize;
+#endif
+        
 	if (verify_config >= 2)
 		printf("Processing object config directory '%s'...\n", dir_name);
 
@@ -8462,7 +8465,13 @@ static int xodtemplate_process_config_dir(char *dir_name)
 			continue;
 
 		/* create /path/to/file */
+#if __GNUC__ >= 7
+		writesize = snprintf(file, sizeof(file), "%s/%s", dir_name, dirfile->d_name);
+		if (writesize < (strlen(dir_name) + strlen(dirfile->d_name) + 2)) 
+			nm_log(NSLOG_RUNTIME_WARNING, "Warning: truncated path to file '%s' in config directory '%s'", dirfile->d_name, dir_name);
+#else
 		snprintf(file, sizeof(file), "%s/%s", dir_name, dirfile->d_name);
+#endif
 		file[sizeof(file) - 1] = '\x0';
 
 		/* process this if it's a non-hidden config file... */