Răsfoiți Sursa

cleanups from pedantic complier warnings

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@666 f882894a-f735-0410-b71e-b25c423dba1c
Karl DeBisschop 22 ani în urmă
părinte
comite
930650812a
3 a modificat fișierele cu 47 adăugiri și 36 ștergeri
  1. 13 2
      plugins/check_disk.c
  2. 17 17
      plugins/netutils.c
  3. 17 17
      plugins/netutils.h

+ 13 - 2
plugins/check_disk.c

@@ -233,9 +233,10 @@ process_arguments (int argc, char **argv)
 	struct name_list **fstail = &fs_exclude_list;
 	struct name_list **fstail = &fs_exclude_list;
 	struct name_list **dptail = &dp_exclude_list;
 	struct name_list **dptail = &dp_exclude_list;
 	struct name_list *temp_list;
 	struct name_list *temp_list;
-	unsigned long l;
 	int result = OK;
 	int result = OK;
 
 
+	unsigned long l;
+
 	int option_index = 0;
 	int option_index = 0;
 	static struct option long_options[] = {
 	static struct option long_options[] = {
 		{"timeout", required_argument, 0, 't'},
 		{"timeout", required_argument, 0, 't'},
@@ -322,6 +323,8 @@ process_arguments (int argc, char **argv)
 				usage (_("Critical threshold must be integer or percentage!\n"));
 				usage (_("Critical threshold must be integer or percentage!\n"));
 			}
 			}
 		case 'u':
 		case 'u':
+			if (units)
+				free(units);
 			if (! strcmp (optarg, "bytes")) {
 			if (! strcmp (optarg, "bytes")) {
 				mult = (uintmax_t)1;
 				mult = (uintmax_t)1;
 				units = strdup ("B");
 				units = strdup ("B");
@@ -340,13 +343,19 @@ process_arguments (int argc, char **argv)
 			} else {
 			} else {
 				die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
 				die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
 			}
 			}
+			if (units == NULL)
+				die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units");
 			break;
 			break;
 		case 'k': /* display mountpoint */
 		case 'k': /* display mountpoint */
 			mult = 1024;
 			mult = 1024;
+			if (units)
+				free(units);
 			units = strdup ("kB");
 			units = strdup ("kB");
 			break;
 			break;
 		case 'm': /* display mountpoint */
 		case 'm': /* display mountpoint */
 			mult = 1024 * 1024;
 			mult = 1024 * 1024;
+			if (units)
+				free(units);
 			units = strdup ("kB");
 			units = strdup ("kB");
 			break;
 			break;
 		case 'l':
 		case 'l':
@@ -475,8 +484,10 @@ INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greate
 		return ERROR;
 		return ERROR;
 	}
 	}
 	
 	
-	if (units == NULL)
+	if (units == NULL) {
 		units = strdup ("MB");
 		units = strdup ("MB");
+		mult = (uintmax_t)1024 * 1024;
+	}
 	return OK;
 	return OK;
 }
 }
 
 

+ 17 - 17
plugins/netutils.c

@@ -53,8 +53,8 @@ socket_timeout_alarm_handler (int sig)
 /* connects to a host on a specified TCP port, sends a string,
 /* connects to a host on a specified TCP port, sends a string,
    and gets a response */
    and gets a response */
 int
 int
-process_tcp_request (char *server_address, int server_port,
-	char *send_buffer, char *recv_buffer, int recv_size)
+process_tcp_request (const char *server_address, int server_port,
+	const char *send_buffer, char *recv_buffer, int recv_size)
 {
 {
 	int result;
 	int result;
 
 
@@ -68,8 +68,8 @@ process_tcp_request (char *server_address, int server_port,
 /* connects to a host on a specified UDP port, sends a string, and gets a
 /* connects to a host on a specified UDP port, sends a string, and gets a
     response */
     response */
 int
 int
-process_udp_request (char *server_address, int server_port,
-	char *send_buffer, char *recv_buffer, int recv_size)
+process_udp_request (const char *server_address, int server_port,
+	const char *send_buffer, char *recv_buffer, int recv_size)
 {
 {
 	int result;
 	int result;
 
 
@@ -85,8 +85,8 @@ process_udp_request (char *server_address, int server_port,
 	 response. loops on select-recv until timeout or eof to get all of a 
 	 response. loops on select-recv until timeout or eof to get all of a 
 	 multi-packet answer */
 	 multi-packet answer */
 int
 int
-process_tcp_request2 (char *server_address, int server_port,
-	char *send_buffer, char *recv_buffer, int recv_size)
+process_tcp_request2 (const char *server_address, int server_port,
+	const char *send_buffer, char *recv_buffer, int recv_size)
 {
 {
 
 
 	int result;
 	int result;
@@ -163,8 +163,8 @@ process_tcp_request2 (char *server_address, int server_port,
 /* connects to a host on a specified port, sends a string, and gets a 
 /* connects to a host on a specified port, sends a string, and gets a 
    response */
    response */
 int
 int
-process_request (char *server_address, int server_port, int proto,
-	char *send_buffer, char *recv_buffer, int recv_size)
+process_request (const char *server_address, int server_port, int proto,
+	const char *send_buffer, char *recv_buffer, int recv_size)
 {
 {
 	int result;
 	int result;
 	int send_result;
 	int send_result;
@@ -223,7 +223,7 @@ process_request (char *server_address, int server_port, int proto,
 
 
 /* opens a connection to a remote host/tcp port */
 /* opens a connection to a remote host/tcp port */
 int
 int
-my_tcp_connect (char *host_name, int port, int *sd)
+my_tcp_connect (const char *host_name, int port, int *sd)
 {
 {
 	int result;
 	int result;
 
 
@@ -235,7 +235,7 @@ my_tcp_connect (char *host_name, int port, int *sd)
 
 
 /* opens a connection to a remote host/udp port */
 /* opens a connection to a remote host/udp port */
 int
 int
-my_udp_connect (char *host_name, int port, int *sd)
+my_udp_connect (const char *host_name, int port, int *sd)
 {
 {
 	int result;
 	int result;
 
 
@@ -247,7 +247,7 @@ my_udp_connect (char *host_name, int port, int *sd)
 
 
 /* opens a tcp or udp connection to a remote host */
 /* opens a tcp or udp connection to a remote host */
 int
 int
-my_connect (char *host_name, int port, int *sd, int proto)
+my_connect (const char *host_name, int port, int *sd, int proto)
 {
 {
 	struct addrinfo hints;
 	struct addrinfo hints;
 	struct addrinfo *res;
 	struct addrinfo *res;
@@ -315,7 +315,7 @@ my_connect (char *host_name, int port, int *sd, int proto)
 }
 }
 
 
 int
 int
-is_host (char *address)
+is_host (const char *address)
 {
 {
 	if (is_addr (address) || is_hostname (address))
 	if (is_addr (address) || is_hostname (address))
 		return (TRUE);
 		return (TRUE);
@@ -324,7 +324,7 @@ is_host (char *address)
 }
 }
 
 
 int
 int
-is_addr (char *address)
+is_addr (const char *address)
 {
 {
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 	if (is_inet_addr (address) && address_family != AF_INET6)
 	if (is_inet_addr (address) && address_family != AF_INET6)
@@ -342,7 +342,7 @@ is_addr (char *address)
 }
 }
 
 
 int
 int
-resolve_host_or_addr (char *address, int family)
+resolve_host_or_addr (const char *address, int family)
 {
 {
 	struct addrinfo hints;
 	struct addrinfo hints;
 	struct addrinfo *res;
 	struct addrinfo *res;
@@ -361,21 +361,21 @@ resolve_host_or_addr (char *address, int family)
 }
 }
 
 
 int
 int
-is_inet_addr (char *address)
+is_inet_addr (const char *address)
 {
 {
 	return resolve_host_or_addr (address, AF_INET);
 	return resolve_host_or_addr (address, AF_INET);
 }
 }
 
 
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 int
 int
-is_inet6_addr (char *address)
+is_inet6_addr (const char *address)
 {
 {
 	return resolve_host_or_addr (address, AF_INET6);
 	return resolve_host_or_addr (address, AF_INET6);
 }
 }
 #endif
 #endif
 
 
 int
 int
-is_hostname (char *s1)
+is_hostname (const char *s1)
 {
 {
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 	return resolve_host_or_addr (s1, address_family);
 	return resolve_host_or_addr (s1, address_family);

+ 17 - 17
plugins/netutils.h

@@ -36,27 +36,27 @@
 
 
 RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
 RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
 
 
-int process_tcp_request2 (char *address, int port, char *sbuffer,
-	char *rbuffer, int rsize);
-int process_tcp_request (char *address, int port, char *sbuffer,
-	char *rbuffer, int rsize);
-int process_udp_request (char *address, int port, char *sbuffer,
-	char *rbuffer, int rsize);
-int process_request (char *address, int port, int proto, char *sbuffer,
-	char *rbuffer, int rsize);
+int process_tcp_request2 (const char *address, int port,
+  const char *sbuffer, char *rbuffer, int rsize);
+int process_tcp_request (const char *address, int port,
+  const char *sbuffer, char *rbuffer, int rsize);
+int process_udp_request (const char *address, int port,
+  const char *sbuffer, char *rbuffer, int rsize);
+int process_request (const char *address, int port, int proto,
+  const char *sbuffer, char *rbuffer, int rsize);
 
 
-int my_tcp_connect (char *address, int port, int *sd);
-int my_udp_connect (char *address, int port, int *sd);
-int my_connect (char *address, int port, int *sd, int proto);
+int my_tcp_connect (const char *address, int port, int *sd);
+int my_udp_connect (const char *address, int port, int *sd);
+int my_connect (const char *address, int port, int *sd, int proto);
 
 
-int is_host (char *);
-int is_addr (char *);
-int resolve_host_or_addr (char *, int);
-int is_inet_addr (char *);
+int is_host (const char *);
+int is_addr (const char *);
+int resolve_host_or_addr (const char *, int);
+int is_inet_addr (const char *);
 #ifdef USE_IPV6
 #ifdef USE_IPV6
-int is_inet6_addr (char *);
+int is_inet6_addr (const char *);
 #endif
 #endif
-int is_hostname (char *);
+int is_hostname (const char *);
 
 
 extern unsigned int socket_timeout;
 extern unsigned int socket_timeout;
 extern int econn_refuse_state;
 extern int econn_refuse_state;