From 028d50d6f99e647a325a0a68303016382c4bbdc9 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 29 Jun 2012 00:57:48 -0400 Subject: Die when asprintf fails Fixes many instances of warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result] Signed-off-by: Anders Kaseorg diff --git a/contrib/check_http-with-client-certificate.c b/contrib/check_http-with-client-certificate.c index 60e1481..c47cbd4 100644 --- a/contrib/check_http-with-client-certificate.c +++ b/contrib/check_http-with-client-certificate.c @@ -606,7 +606,7 @@ process_arguments( int argc, char **argv ) *if ( !is_hostname( optarg ) ) * usage2( "invalid hostname", optarg ); */ - asprintf( &server_hostname, "%s", optarg ); + xasprintf( &server_hostname, "%s", optarg ); use_server_hostname = TRUE; break; case 'F': /* File (dummy) */ @@ -619,7 +619,7 @@ process_arguments( int argc, char **argv ) *if ( !is_host( optarg ) ) * usage2( "invalid ip address or hostname", optarg ) */ - asprintf( &server_host, "%s", optarg ); + xasprintf( &server_host, "%s", optarg ); break; case 'p': /* Server port */ if ( !is_intnonneg( optarg ) ) @@ -653,7 +653,7 @@ process_arguments( int argc, char **argv ) break; case 'A': /* client certificate */ #ifdef HAVE_SSL - asprintf( &client_certificate_file, "%s", optarg ); + xasprintf( &client_certificate_file, "%s", optarg ); use_client_certificate = TRUE; #else usage( "check_http: invalid option - SSL is not available\n" ); @@ -661,26 +661,26 @@ process_arguments( int argc, char **argv ) break; case 'K': /* client certificate passphrase */ #ifdef HAVE_SSL - asprintf( &client_certificate_passphrase, "%s", optarg ); + xasprintf( &client_certificate_passphrase, "%s", optarg ); use_client_certificate_passphrase = TRUE; #else usage( "check_http: invalid option - SSL is not available\n" ); #endif case 'Z': /* valid CA certificates */ #ifdef HAVE_SSL - asprintf( &ca_certificate_file, "%s", optarg ); + xasprintf( &ca_certificate_file, "%s", optarg ); use_ca_certificate = TRUE; #else usage( "check_http: invalid option - SSL is not available\n" ); #endif break; case 'u': /* URL PATH */ - asprintf( &http_url_path, "%s", optarg ); + xasprintf( &http_url_path, "%s", optarg ); break; case 'P': /* POST DATA */ - asprintf( &http_post_data, "%s", optarg ); + xasprintf( &http_post_data, "%s", optarg ); use_http_post_data = TRUE; - asprintf( &http_method, "%s", "POST" ); + xasprintf( &http_method, "%s", "POST" ); break; case 'e': /* expected string in first line of HTTP response */ strncpy( http_expect , optarg, MAX_INPUT_BUFFER - 1 ); @@ -765,13 +765,13 @@ process_arguments( int argc, char **argv ) * without an option */ if ( ( strcmp( server_host, "" ) ) && (c < argc) ) { - asprintf( &server_host, "%s", argv[c++] ); + xasprintf( &server_host, "%s", argv[c++] ); } /* 2. check if another artument is supplied */ if ( ( strcmp( server_hostname, "" ) == 0 ) && (c < argc) ) { - asprintf( &server_hostname, "%s", argv[c++] ); + xasprintf( &server_hostname, "%s", argv[c++] ); } /* 3. if host is still not defined, just copy hostname, @@ -781,7 +781,7 @@ process_arguments( int argc, char **argv ) if ( strcmp( server_hostname, "" ) == 0 ) { usage ("check_http: you must specify a server address or host name\n"); } else { - asprintf( &server_host, "%s", server_hostname ); + xasprintf( &server_host, "%s", server_hostname ); } } @@ -807,9 +807,9 @@ process_arguments( int argc, char **argv ) /* Finally set some default values if necessary */ if ( strcmp( http_method, "" ) == 0 ) - asprintf( &http_method, "%s", DEFAULT_HTTP_METHOD ); + xasprintf( &http_method, "%s", DEFAULT_HTTP_METHOD ); if ( strcmp( http_url_path, "" ) == 0 ) { - asprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); + xasprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); } return TRUE; @@ -829,25 +829,25 @@ http_request( int sock, struct pageref *page ) size_t size = 0; char *basic_auth_encoded = NULL; - asprintf( &buffer, HTTP_TEMPLATE_REQUEST, buffer, http_method, http_url_path ); + xasprintf( &buffer, HTTP_TEMPLATE_REQUEST, buffer, http_method, http_url_path ); - asprintf( &buffer, HTTP_TEMPLATE_HEADER_USERAGENT, buffer, progname, REVISION, PACKAGE_VERSION ); + xasprintf( &buffer, HTTP_TEMPLATE_HEADER_USERAGENT, buffer, progname, REVISION, PACKAGE_VERSION ); if ( use_server_hostname ) { - asprintf( &buffer, HTTP_TEMPLATE_HEADER_HOST, buffer, server_hostname ); + xasprintf( &buffer, HTTP_TEMPLATE_HEADER_HOST, buffer, server_hostname ); } if ( use_basic_auth ) { basic_auth_encoded = base64( basic_auth, strlen( basic_auth ) ); - asprintf( &buffer, HTTP_TEMPLATE_HEADER_AUTH, buffer, basic_auth_encoded ); + xasprintf( &buffer, HTTP_TEMPLATE_HEADER_AUTH, buffer, basic_auth_encoded ); } /* either send http POST data */ if ( use_http_post_data ) { /* based on code written by Chris Henesy */ - asprintf( &buffer, "Content-Type: application/x-www-form-urlencoded\r\n" ); - asprintf( &buffer, "Content-Length: %i\r\n\r\n", buffer, content_len ); - asprintf( &buffer, "%s%s%s", buffer, http_post_data, "\r\n" ); + xasprintf( &buffer, "Content-Type: application/x-www-form-urlencoded\r\n" ); + xasprintf( &buffer, "Content-Length: %i\r\n\r\n", buffer, content_len ); + xasprintf( &buffer, "%s%s%s", buffer, http_post_data, "\r\n" ); sendsize = send( sock, buffer, strlen( buffer ), 0 ); if ( sendsize < strlen( buffer ) ) { printf( "ERROR: Incomplete write\n" ); @@ -855,7 +855,7 @@ http_request( int sock, struct pageref *page ) } /* or just a newline */ } else { - asprintf( &buffer, "%s%s", buffer, "\r\n" ); + xasprintf( &buffer, "%s%s", buffer, "\r\n" ); sendsize = send( sock, buffer, strlen( buffer ) , 0 ); if ( sendsize < strlen( buffer ) ) { printf( "ERROR: Incomplete write\n" ); @@ -870,12 +870,12 @@ http_request( int sock, struct pageref *page ) recvsize = recv( sock, recvbuff, MAX_INPUT_BUFFER - 1, 0 ); if ( recvsize > (size_t) 0 ) { recvbuff[recvsize] = '\0'; - asprintf( &content, "%s%s", content, recvbuff ); + xasprintf( &content, "%s%s", content, recvbuff ); size += recvsize; } } while ( recvsize > (size_t) 0 ); - asprintf( &page->content, "%s", content ); + xasprintf( &page->content, "%s", content ); page->size = size; /* return a CRITICAL status if we couldn't read any data */ @@ -895,7 +895,7 @@ parse_http_response( struct pageref *page ) size_t len = 0; //temporary used char *pos = ""; //temporary used - asprintf( &content, "%s", page->content ); + xasprintf( &content, "%s", page->content ); /* find status line and null-terminate it */ // copy content to status @@ -962,7 +962,7 @@ check_http_response( struct pageref *page ) /* check response time befor anything else */ if ( use_critical_interval && ( elapsed_time > critical_interval ) ) { - asprintf( &msg, RESULT_TEMPLATE_RESPONSE_TIME, + xasprintf( &msg, RESULT_TEMPLATE_RESPONSE_TIME, protocol_text( use_ssl ), state_text( STATE_CRITICAL ), elapsed_time, @@ -970,7 +970,7 @@ check_http_response( struct pageref *page ) terminate( STATE_CRITICAL, msg ); } if ( use_warning_interval && ( elapsed_time > warning_interval ) ) { - asprintf( &msg, RESULT_TEMPLATE_RESPONSE_TIME, + xasprintf( &msg, RESULT_TEMPLATE_RESPONSE_TIME, protocol_text( use_ssl ), state_text( STATE_WARNING ), elapsed_time, @@ -990,9 +990,9 @@ check_http_response( struct pageref *page ) #else ) #endif - asprintf( &msg, "Expected HTTP response received from host\n" ); + xasprintf( &msg, "Expected HTTP response received from host\n" ); else - asprintf( &msg, "Expected HTTP response received from host on port %d\n", server_port ); + xasprintf( &msg, "Expected HTTP response received from host on port %d\n", server_port ); terminate( STATE_OK, msg ); } } else { @@ -1002,9 +1002,9 @@ check_http_response( struct pageref *page ) #else ) #endif - asprintf( &msg, "Invalid HTTP response received from host\n" ); + xasprintf( &msg, "Invalid HTTP response received from host\n" ); else - asprintf( &msg, "Invalid HTTP response received from host on port %d\n", server_port ); + xasprintf( &msg, "Invalid HTTP response received from host on port %d\n", server_port ); terminate( STATE_CRITICAL, msg ); } @@ -1016,7 +1016,7 @@ check_http_response( struct pageref *page ) strstr( page->status, "503" ) || strstr( page->status, "504" ) || strstr( page->status, "505" )) { - asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, + xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, protocol_text( use_ssl ), state_text( http_client_error_state ), page->status, @@ -1044,7 +1044,7 @@ check_http_response( struct pageref *page ) strstr( page->status, "415" ) || strstr( page->status, "416" ) || strstr( page->status, "417" ) ) { - asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, + xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, protocol_text( use_ssl ), state_text( http_client_error_state ), page->status, @@ -1066,7 +1066,7 @@ check_http_response( struct pageref *page ) /* returning STATE_DEPENDENT means follow redirect */ return STATE_DEPENDENT; } else { - asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, + xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, protocol_text( use_ssl ), state_text( http_redirect_state ), page->status, @@ -1087,7 +1087,7 @@ check_http_content( struct pageref *page ) /* check for string in content */ if ( check_content_string ) { if ( strstr( page->content, content_string ) ) { - asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, + xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, protocol_text( use_ssl ), state_text( STATE_OK ), page->status, @@ -1095,7 +1095,7 @@ check_http_content( struct pageref *page ) elapsed_time ); terminate( STATE_OK, msg ); } else { - asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, + xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, protocol_text( use_ssl ), state_text( STATE_CRITICAL ), page->status, @@ -1110,7 +1110,7 @@ check_http_content( struct pageref *page ) if ( check_content_regex ) { regex_error = regexec( ®ex_preg, page->content, REGEX_REGS, regex_pmatch, 0); if ( regex_error == 0 ) { - asprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, + xasprintf( &msg, RESULT_TEMPLATE_STATUS_RESPONSE_TIME, protocol_text( use_ssl ), state_text( STATE_OK ), page->status, @@ -1119,13 +1119,13 @@ check_http_content( struct pageref *page ) terminate( STATE_OK, msg ); } else { if ( regex_error == REG_NOMATCH ) { - asprintf( &msg, "%s, %s: regex pattern not found\n", + xasprintf( &msg, "%s, %s: regex pattern not found\n", protocol_text( use_ssl) , state_text( STATE_CRITICAL ) ); terminate( STATE_CRITICAL, msg ); } else { regerror( regex_error, ®ex_preg, regex_error_buffer, MAX_INPUT_BUFFER); - asprintf( &msg, "%s %s: Regex execute Error: %s\n", + xasprintf( &msg, "%s %s: Regex execute Error: %s\n", protocol_text( use_ssl) , state_text( STATE_CRITICAL ), regex_error_buffer ); @@ -1152,16 +1152,16 @@ prepare_follow_redirect( struct pageref *page ) char *orig_url_dirname = NULL; size_t len = 0; - asprintf( &header, "%s", page->header ); + xasprintf( &header, "%s", page->header ); /* restore some default values */ use_http_post_data = FALSE; - asprintf( &http_method, "%s", DEFAULT_HTTP_METHOD ); + xasprintf( &http_method, "%s", DEFAULT_HTTP_METHOD ); /* copy url of original request, maybe we need it to compose absolute url from relative Location: header */ - asprintf( &orig_url_path, "%s", http_url_path ); + xasprintf( &orig_url_path, "%s", http_url_path ); while ( strcspn( header, "\r\n" ) > (size_t) 0 ) { url_path = realloc( url_path, (size_t) strcspn( header, "\r\n" ) ); @@ -1172,43 +1172,43 @@ prepare_follow_redirect( struct pageref *page ) /* Try to find a Location header combination of METHOD HOSTNAME PORT and PATH */ /* 1. scan for Location: http[s]://hostname:port/path */ if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_PORT_MATCH HTTP_HEADER_URL_PATH_MATCH, &protocol, &hostname, &port, url_path ) == 4 ) { - asprintf( &server_hostname, "%s", hostname ); - asprintf( &server_host, "%s", hostname ); + xasprintf( &server_hostname, "%s", hostname ); + xasprintf( &server_host, "%s", hostname ); use_ssl = chk_protocol(protocol); server_port = atoi( port ); - asprintf( &http_url_path, "%s", url_path ); + xasprintf( &http_url_path, "%s", url_path ); return STATE_DEPENDENT; } else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_URL_PATH_MATCH, &protocol, &hostname, url_path ) == 3) { - asprintf( &server_hostname, "%s", hostname ); - asprintf( &server_host, "%s", hostname ); + xasprintf( &server_hostname, "%s", hostname ); + xasprintf( &server_host, "%s", hostname ); use_ssl = chk_protocol(protocol); server_port = protocol_std_port(use_ssl); - asprintf( &http_url_path, "%s", url_path ); + xasprintf( &http_url_path, "%s", url_path ); return STATE_DEPENDENT; } else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH HTTP_HEADER_PORT_MATCH, &protocol, &hostname, &port ) == 3) { - asprintf( &server_hostname, "%s", hostname ); - asprintf( &server_host, "%s", hostname ); + xasprintf( &server_hostname, "%s", hostname ); + xasprintf( &server_host, "%s", hostname ); use_ssl = chk_protocol(protocol); server_port = atoi( port ); - asprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); + xasprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); return STATE_DEPENDENT; } else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_PROTOCOL_MATCH HTTP_HEADER_HOSTNAME_MATCH, protocol, hostname ) == 2 ) { - asprintf( &server_hostname, "%s", hostname ); - asprintf( &server_host, "%s", hostname ); + xasprintf( &server_hostname, "%s", hostname ); + xasprintf( &server_host, "%s", hostname ); use_ssl = chk_protocol(protocol); server_port = protocol_std_port(use_ssl); - asprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); + xasprintf( &http_url_path, "%s", DEFAULT_HTTP_URL_PATH ); } else if ( sscanf ( header, HTTP_HEADER_LOCATION_MATCH HTTP_HEADER_URL_PATH_MATCH, url_path ) == 1 ) { /* check for relative url and prepend path if necessary */ if ( ( url_path[0] != '/' ) && ( orig_url_dirname = strrchr( orig_url_path, '/' ) ) ) { *orig_url_dirname = '\0'; - asprintf( &http_url_path, "%s%s", orig_url_path, url_path ); + xasprintf( &http_url_path, "%s%s", orig_url_path, url_path ); } else { - asprintf( &http_url_path, "%s", url_path ); + xasprintf( &http_url_path, "%s", url_path ); } return STATE_DEPENDENT; } @@ -1218,7 +1218,7 @@ prepare_follow_redirect( struct pageref *page ) /* default return value is STATE_DEPENDENT to continue looping in main() */ - asprintf( &msg, "% %: % - Could not find redirect Location", + xasprintf( &msg, "% %: % - Could not find redirect Location", protocol_text( use_ssl ), state_text( STATE_UNKNOWN ), page->status ); @@ -1239,24 +1239,24 @@ https_request( SSL_CTX *ctx, SSL *ssl, struct pageref *page ) size_t size = 0; char *basic_auth_encoded = NULL; - asprintf( &buffer, HTTP_TEMPLATE_REQUEST, buffer, http_method, http_url_path ); + xasprintf( &buffer, HTTP_TEMPLATE_REQUEST, buffer, http_method, http_url_path ); - asprintf( &buffer, HTTP_TEMPLATE_HEADER_USERAGENT, buffer, progname, REVISION, PACKAGE_VERSION ); + xasprintf( &buffer, HTTP_TEMPLATE_HEADER_USERAGENT, buffer, progname, REVISION, PACKAGE_VERSION ); if ( use_server_hostname ) { - asprintf( &buffer, HTTP_TEMPLATE_HEADER_HOST, buffer, server_hostname ); + xasprintf( &buffer, HTTP_TEMPLATE_HEADER_HOST, buffer, server_hostname ); } if ( use_basic_auth ) { basic_auth_encoded = base64( basic_auth, strlen( basic_auth ) ); - asprintf( &buffer, HTTP_TEMPLATE_HEADER_AUTH, buffer, basic_auth_encoded ); + xasprintf( &buffer, HTTP_TEMPLATE_HEADER_AUTH, buffer, basic_auth_encoded ); } /* either send http POST data */ if ( use_http_post_data ) { - asprintf( &buffer, "%sContent-Type: application/x-www-form-urlencoded\r\n", buffer ); - asprintf( &buffer, "%sContent-Length: %i\r\n\r\n", buffer, content_len ); - asprintf( &buffer, "%s%s%s", buffer, http_post_data, "\r\n" ); + xasprintf( &buffer, "%sContent-Type: application/x-www-form-urlencoded\r\n", buffer ); + xasprintf( &buffer, "%sContent-Length: %i\r\n\r\n", buffer, content_len ); + xasprintf( &buffer, "%s%s%s", buffer, http_post_data, "\r\n" ); sendsize = SSL_write( ssl, buffer, strlen( buffer ) ); switch ( SSL_get_error( ssl, sendsize ) ) { case SSL_ERROR_NONE: @@ -1270,7 +1270,7 @@ https_request( SSL_CTX *ctx, SSL *ssl, struct pageref *page ) /* or just a newline */ } else { - asprintf( &buffer, "%s\r\n", buffer ); + xasprintf( &buffer, "%s\r\n", buffer ); sendsize = SSL_write( ssl, buffer, strlen( buffer ) ); switch ( SSL_get_error( ssl, sendsize ) ) { case SSL_ERROR_NONE: @@ -1293,7 +1293,7 @@ https_request( SSL_CTX *ctx, SSL *ssl, struct pageref *page ) case SSL_ERROR_NONE: if ( recvsize > (size_t) 0 ) { recvbuff[recvsize] = '\0'; - asprintf( &content, "%s%s", content, recvbuff ); + xasprintf( &content, "%s%s", content, recvbuff ); size += recvsize; } break; @@ -1317,7 +1317,7 @@ https_request( SSL_CTX *ctx, SSL *ssl, struct pageref *page ) } } while ( recvsize > (size_t) 0 ); - asprintf( &page->content, "%s", content ); + xasprintf( &page->content, "%s", content ); page->size = size; /* return a CRITICAL status if we couldn't read any data */ @@ -1446,7 +1446,7 @@ check_server_certificate_hostname( ) char *msg = NULL; X509_NAME_get_text_by_NID( X509_get_subject_name( server_certificate ), NID_commonName, server_CN, 256 ); if ( strcasecmp( server_CN, server_hostname ) ) { - asprintf( &msg, "SSL ERROR: Server Certificate does not match Hostname %s.\n", server_hostname ); + xasprintf( &msg, "SSL ERROR: Server Certificate does not match Hostname %s.\n", server_hostname ); ssl_terminate( STATE_WARNING, msg ); } @@ -1507,20 +1507,20 @@ check_server_certificate_expires( ) stamp.tm_hour, stamp.tm_min ); if ( ( days_left > 0 ) && ( days_left <= server_certificate_min_days_valid ) ) { - asprintf( &msg, "Certificate expires in %d day(s) (%s).\n", days_left, timestamp ); + xasprintf( &msg, "Certificate expires in %d day(s) (%s).\n", days_left, timestamp ); ssl_terminate( STATE_WARNING, msg ); } if ( days_left < 0 ) { - asprintf( &msg, "Certificate expired on %s.\n", timestamp ); + xasprintf( &msg, "Certificate expired on %s.\n", timestamp ); ssl_terminate( STATE_CRITICAL, msg ); } if (days_left == 0) { - asprintf( &msg, "Certificate expires today (%s).\n", timestamp ); + xasprintf( &msg, "Certificate expires today (%s).\n", timestamp ); ssl_terminate( STATE_WARNING, msg ); } - asprintf( &msg, "Certificate will expire on %s.\n", timestamp ); + xasprintf( &msg, "Certificate will expire on %s.\n", timestamp ); ssl_terminate( STATE_OK, msg ); } #endif diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 8752016..c5f0d52 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c @@ -281,8 +281,8 @@ process_arguments (int argc, char **argv) case 'C': /* Command for remote machine */ commands++; if (commands > 1) - asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); - asprintf (&remotecmd, "%s%s", remotecmd, optarg); + xasprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); + xasprintf (&remotecmd, "%s%s", remotecmd, optarg); break; case 'S': /* skip n (or all) lines on stdout */ if (optarg == NULL) @@ -328,13 +328,13 @@ process_arguments (int argc, char **argv) if (strlen(remotecmd) == 0) { for (; c < argc; c++) if (strlen(remotecmd) > 0) - asprintf (&remotecmd, "%s %s", remotecmd, argv[c]); + xasprintf (&remotecmd, "%s %s", remotecmd, argv[c]); else - asprintf (&remotecmd, "%s", argv[c]); + xasprintf (&remotecmd, "%s", argv[c]); } if (commands > 1 || passive) - asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); + xasprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); if (remotecmd == NULL || strlen (remotecmd) <= 1) usage_va(_("No remotecmd")); diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 06f59c8..893e0a1 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c @@ -87,7 +87,7 @@ main (int argc, char **argv) usage_va(_("Could not parse arguments")); /* get the command to run */ - asprintf (&command_line, "%s @%s -p %d %s -t %s %s", + xasprintf (&command_line, "%s @%s -p %d %s -t %s %s", PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args); alarm (timeout_interval); @@ -306,7 +306,7 @@ print_help (void) { char *myport; - asprintf (&myport, "%d", DEFAULT_PORT); + xasprintf (&myport, "%d", DEFAULT_PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_disk.c b/plugins/check_disk.c index f889764..f8e913e 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -320,7 +320,7 @@ main (int argc, char **argv) } /* Nb: *_high_tide are unset when == UINT_MAX */ - asprintf (&perf, "%s %s", perf, + xasprintf (&perf, "%s %s", perf, perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, path->dused_units, units, (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, @@ -331,20 +331,20 @@ main (int argc, char **argv) if (disk_result==STATE_OK && erronly && !verbose) continue; - asprintf (&output, "%s %s %.0f %s (%.0f%%", + xasprintf (&output, "%s %s %.0f %s (%.0f%%", output, (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, path->dfree_units, units, path->dfree_pct); if (path->dused_inodes_percent < 0) { - asprintf(&output, "%s inode=-);", output); + xasprintf(&output, "%s inode=-);", output); } else { - asprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent ); + xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent ); } /* TODO: Need to do a similar debug line - asprintf (&details, _("%s\n\ + xasprintf (&details, _("%s\n\ %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, me->me_devname, me->me_type, me->me_mountdir, @@ -356,7 +356,7 @@ main (int argc, char **argv) } if (verbose >= 2) - asprintf (&output, "%s%s", output, details); + xasprintf (&output, "%s%s", output, details); printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf); @@ -473,13 +473,13 @@ process_arguments (int argc, char **argv) if (*optarg == '@') { warn_freespace_percent = optarg; } else { - asprintf(&warn_freespace_percent, "@%s", optarg); + xasprintf(&warn_freespace_percent, "@%s", optarg); } } else { if (*optarg == '@') { warn_freespace_units = optarg; } else { - asprintf(&warn_freespace_units, "@%s", optarg); + xasprintf(&warn_freespace_units, "@%s", optarg); } } break; @@ -494,13 +494,13 @@ process_arguments (int argc, char **argv) if (*optarg == '@') { crit_freespace_percent = optarg; } else { - asprintf(&crit_freespace_percent, "@%s", optarg); + xasprintf(&crit_freespace_percent, "@%s", optarg); } } else { if (*optarg == '@') { crit_freespace_units = optarg; } else { - asprintf(&crit_freespace_units, "@%s", optarg); + xasprintf(&crit_freespace_units, "@%s", optarg); } } break; @@ -509,14 +509,14 @@ process_arguments (int argc, char **argv) if (*optarg == '@') { warn_freeinodes_percent = optarg; } else { - asprintf(&warn_freeinodes_percent, "@%s", optarg); + xasprintf(&warn_freeinodes_percent, "@%s", optarg); } break; case 'K': /* critical inode threshold */ if (*optarg == '@') { crit_freeinodes_percent = optarg; } else { - asprintf(&crit_freeinodes_percent, "@%s", optarg); + xasprintf(&crit_freeinodes_percent, "@%s", optarg); } break; case 'u': diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 73b560c..91af730 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -103,7 +103,7 @@ main (int argc, char **argv) } /* get the command to run */ - asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); + xasprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); alarm (timeout_interval); gettimeofday (&tv, NULL); @@ -208,19 +208,19 @@ main (int argc, char **argv) for (i=0; i 0) printf ("%s\n", command_line); diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 51a0099..60e922e 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c @@ -227,7 +227,7 @@ main (int argc, char **argv) /* might not be the problem, but most likely is. */ result = STATE_UNKNOWN ; - asprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address ); + xasprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address ); } diff --git a/plugins/check_http.c b/plugins/check_http.c index 703e317..77a235e 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -147,7 +147,7 @@ main (int argc, char **argv) /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ server_url = strdup(HTTP_URL); server_url_length = strlen(server_url); - asprintf (&user_agent, "User-Agent: check_http/v%s (nagios-plugins %s)", + xasprintf (&user_agent, "User-Agent: check_http/v%s (nagios-plugins %s)", NP_VERSION, VERSION); /* Parse extra opts if any */ @@ -265,7 +265,7 @@ process_arguments (int argc, char **argv) warning_thresholds = optarg; break; case 'A': /* User Agent String */ - asprintf (&user_agent, "User-Agent: %s", optarg); + xasprintf (&user_agent, "User-Agent: %s", optarg); break; case 'k': /* Additional headers */ if (http_opt_headers_count == 0) @@ -273,7 +273,7 @@ process_arguments (int argc, char **argv) else http_opt_headers = realloc (http_opt_headers, sizeof (char *) * (++http_opt_headers_count)); http_opt_headers[http_opt_headers_count - 1] = optarg; - /* asprintf (&http_opt_headers, "%s", optarg); */ + /* xasprintf (&http_opt_headers, "%s", optarg); */ break; case 'L': /* show html link */ display_html = TRUE; @@ -394,7 +394,7 @@ process_arguments (int argc, char **argv) server_expect_yn = 1; break; case 'T': /* Content-type */ - asprintf (&http_content_type, "%s", optarg); + xasprintf (&http_content_type, "%s", optarg); break; case 'l': /* linespan */ cflags &= ~REG_NEWLINE; @@ -690,31 +690,31 @@ check_document_dates (const char *headers, char **msg) /* Done parsing the body. Now check the dates we (hopefully) parsed. */ if (!server_date || !*server_date) { - asprintf (msg, _("%sServer date unknown, "), *msg); + xasprintf (msg, _("%sServer date unknown, "), *msg); date_result = max_state_alt(STATE_UNKNOWN, date_result); } else if (!document_date || !*document_date) { - asprintf (msg, _("%sDocument modification date unknown, "), *msg); + xasprintf (msg, _("%sDocument modification date unknown, "), *msg); date_result = max_state_alt(STATE_CRITICAL, date_result); } else { time_t srv_data = parse_time_string (server_date); time_t doc_data = parse_time_string (document_date); if (srv_data <= 0) { - asprintf (msg, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); + xasprintf (msg, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); date_result = max_state_alt(STATE_CRITICAL, date_result); } else if (doc_data <= 0) { - asprintf (msg, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); + xasprintf (msg, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); date_result = max_state_alt(STATE_CRITICAL, date_result); } else if (doc_data > srv_data + 30) { - asprintf (msg, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data); + xasprintf (msg, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data); date_result = max_state_alt(STATE_CRITICAL, date_result); } else if (doc_data < srv_data - maximum_age) { int n = (srv_data - doc_data); if (n > (60 * 60 * 24 * 2)) { - asprintf (msg, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24)); + xasprintf (msg, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24)); date_result = max_state_alt(STATE_CRITICAL, date_result); } else { - asprintf (msg, _("%sLast modified %d:%02d:%02d ago, "), *msg, n / (60 * 60), (n / 60) % 60, n % 60); + xasprintf (msg, _("%sLast modified %d:%02d:%02d ago, "), *msg, n / (60 * 60), (n / 60) % 60, n % 60); date_result = max_state_alt(STATE_CRITICAL, date_result); } } @@ -831,10 +831,10 @@ check_http (void) } #endif /* HAVE_SSL */ - asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); + xasprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); /* tell HTTP/1.1 servers not to keep the connection alive */ - asprintf (&buf, "%sConnection: close\r\n", buf); + xasprintf (&buf, "%sConnection: close\r\n", buf); /* optionally send the host header info */ if (host_name) { @@ -845,16 +845,16 @@ check_http (void) */ if ((use_ssl == FALSE && server_port == HTTP_PORT) || (use_ssl == TRUE && server_port == HTTPS_PORT)) - asprintf (&buf, "%sHost: %s\r\n", buf, host_name); + xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); else - asprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); + xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); } /* optionally send any other header tag */ if (http_opt_headers_count) { for (i = 0; i < http_opt_headers_count ; i++) { for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) - asprintf (&buf, "%s%s\r\n", buf, pos); + xasprintf (&buf, "%s%s\r\n", buf, pos); } /* This cannot be free'd here because a redirection will then try to access this and segfault */ /* Covered in a testcase in tests/check_http.t */ @@ -864,29 +864,29 @@ check_http (void) /* optionally send the authentication info */ if (strlen(user_auth)) { base64_encode_alloc (user_auth, strlen (user_auth), &auth); - asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); + xasprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); } /* optionally send the proxy authentication info */ if (strlen(proxy_auth)) { base64_encode_alloc (proxy_auth, strlen (proxy_auth), &auth); - asprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); + xasprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); } /* either send http POST data (any data, not only POST)*/ if (http_post_data) { if (http_content_type) { - asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type); + xasprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type); } else { - asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); + xasprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); } - asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); - asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); + xasprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); + xasprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); } else { /* or just a newline so the server knows we're done with the request */ - asprintf (&buf, "%s%s", buf, CRLF); + xasprintf (&buf, "%s%s", buf, CRLF); } if (verbose) printf ("%s\n", buf); @@ -896,7 +896,7 @@ check_http (void) full_page = strdup(""); while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { buffer[i] = '\0'; - asprintf (&full_page_new, "%s%s", full_page, buffer); + xasprintf (&full_page_new, "%s%s", full_page, buffer); free (full_page); full_page = full_page_new; pagesize += i; @@ -981,11 +981,11 @@ check_http (void) /* make sure the status line matches the response we are looking for */ if (!expected_statuscode (status_line, server_expect)) { if (server_port == HTTP_PORT) - asprintf (&msg, + xasprintf (&msg, _("Invalid HTTP response received from host: %s\n"), status_line); else - asprintf (&msg, + xasprintf (&msg, _("Invalid HTTP response received from host on port %d: %s\n"), server_port, status_line); die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); @@ -994,7 +994,7 @@ check_http (void) /* Bypass normal status line check if server_expect was set by user and not default */ /* NOTE: After this if/else block msg *MUST* be an asprintf-allocated string */ if ( server_expect_yn ) { - asprintf (&msg, + xasprintf (&msg, _("Status line output matched \"%s\" - "), server_expect); if (verbose) printf ("%s\n",msg); @@ -1017,12 +1017,12 @@ check_http (void) } /* server errors result in a critical state */ else if (http_status >= 500) { - asprintf (&msg, _("%s - "), status_line); + xasprintf (&msg, _("%s - "), status_line); result = STATE_CRITICAL; } /* client errors result in a warning state */ else if (http_status >= 400) { - asprintf (&msg, _("%s - "), status_line); + xasprintf (&msg, _("%s - "), status_line); result = max_state_alt(STATE_WARNING, result); } /* check redirected page if specified */ @@ -1032,11 +1032,11 @@ check_http (void) redir (header, status_line); else result = max_state_alt(onredirect, result); - asprintf (&msg, _("%s - "), status_line); + xasprintf (&msg, _("%s - "), status_line); } /* end if (http_status >= 300) */ else { /* Print OK status anyway */ - asprintf (&msg, _("%s - "), status_line); + xasprintf (&msg, _("%s - "), status_line); } } /* end else (server_expect_yn) */ @@ -1056,7 +1056,7 @@ check_http (void) if(output_string_search[sizeof(output_string_search)-1]!='\0') { bcopy("...",&output_string_search[sizeof(output_string_search)-4],4); } - asprintf (&msg, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, output_string_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); + xasprintf (&msg, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, output_string_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); result = STATE_CRITICAL; } } @@ -1069,15 +1069,15 @@ check_http (void) } else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { if (invert_regex == 0) - asprintf (&msg, _("%spattern not found, "), msg); + xasprintf (&msg, _("%spattern not found, "), msg); else - asprintf (&msg, _("%spattern found, "), msg); + xasprintf (&msg, _("%spattern found, "), msg); result = STATE_CRITICAL; } else { /* FIXME: Shouldn't that be UNKNOWN? */ regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); - asprintf (&msg, _("%sExecute Error: %s, "), msg, errbuf); + xasprintf (&msg, _("%sExecute Error: %s, "), msg, errbuf); result = STATE_CRITICAL; } } @@ -1093,10 +1093,10 @@ check_http (void) */ page_len = pagesize; if ((max_page_len > 0) && (page_len > max_page_len)) { - asprintf (&msg, _("%spage size %d too large, "), msg, page_len); + xasprintf (&msg, _("%spage size %d too large, "), msg, page_len); result = max_state_alt(STATE_WARNING, result); } else if ((min_page_len > 0) && (page_len < min_page_len)) { - asprintf (&msg, _("%spage size %d too small, "), msg, page_len); + xasprintf (&msg, _("%spage size %d too small, "), msg, page_len); result = max_state_alt(STATE_WARNING, result); } @@ -1107,7 +1107,7 @@ check_http (void) msg[strlen(msg)-3] = '\0'; /* check elapsed time */ - asprintf (&msg, + xasprintf (&msg, _("%s - %d bytes in %.3f second response time %s|%s %s"), msg, page_len, elapsed_time, (display_html ? "" : ""), @@ -1214,7 +1214,7 @@ redir (char *pos, char *status_line) if ((url[0] != '/')) { if ((x = strrchr(server_url, '/'))) *x = '\0'; - asprintf (&url, "%s/%s", server_url, url); + xasprintf (&url, "%s/%s", server_url, url); } i = server_port; strcpy (type, server_type); diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index f83f139..65db851 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c @@ -99,7 +99,7 @@ main (int argc, char *argv[]) textdomain (PACKAGE); if (strstr(argv[0],"check_ldaps")) { - asprintf (&progname, "check_ldaps"); + xasprintf (&progname, "check_ldaps"); } /* Parse extra opts if any */ @@ -145,7 +145,7 @@ main (int argc, char *argv[]) #endif if (ld_port == LDAPS_PORT || ssl_on_connect) { - asprintf (&SERVICE, "LDAPS"); + xasprintf (&SERVICE, "LDAPS"); #if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS) /* ldaps: set option tls */ tls = LDAP_OPT_X_TLS_HARD; @@ -162,7 +162,7 @@ main (int argc, char *argv[]) return STATE_CRITICAL; #endif /* LDAP_OPT_X_TLS */ } else if (starttls) { - asprintf (&SERVICE, "LDAP-TLS"); + xasprintf (&SERVICE, "LDAP-TLS"); #if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S) /* ldap with startTLS: set option version */ if (ldap_get_option(ld,LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS ) @@ -389,7 +389,7 @@ void print_help (void) { char *myport; - asprintf (&myport, "%d", DEFAULT_PORT); + xasprintf (&myport, "%d", DEFAULT_PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_load.c b/plugins/check_load.c index 1bdb06a..780ffff 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -186,7 +186,7 @@ main (int argc, char **argv) /* we got this far, so assume OK until we've measured */ result = STATE_OK; - asprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15); + xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15); for(i = 0; i < 3; i++) { if(la[i] > cload[i]) { diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index 4fd9bc0..a822651 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c @@ -191,7 +191,7 @@ main (int argc, char **argv) result = STATE_WARNING; } - asprintf (&error_message, _("%s. In = %0.1f %s, %s. Out = %0.1f %s|%s %s\n"), + xasprintf (&error_message, _("%s. In = %0.1f %s, %s. Out = %0.1f %s|%s %s\n"), (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate, incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_outgoing_rate, outgoing_speed_rating, diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index d9b4e53..4fbdc2b 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -369,7 +369,7 @@ void print_help (void) { char *myport; - asprintf (&myport, "%d", MYSQL_PORT); + xasprintf (&myport, "%d", MYSQL_PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index cf9d8df..0bb83c3 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c @@ -233,7 +233,7 @@ process_arguments (int argc, char **argv) print_help (); exit (STATE_OK); case 'q': - asprintf(&sql_query, "%s", optarg); + xasprintf(&sql_query, "%s", optarg); break; case 'w': warning = optarg; @@ -277,7 +277,7 @@ void print_help (void) { char *myport; - asprintf (&myport, "%d", MYSQL_PORT); + xasprintf (&myport, "%d", MYSQL_PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index 6485aa9..c8cdbc0 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c @@ -137,7 +137,7 @@ main (int argc, char **argv) chld_out.line[i][pos+1] = 0x0; } if ( cols >= expected_cols ) { - asprintf (&procargs, "%s", chld_out.line[i] + pos); + xasprintf (&procargs, "%s", chld_out.line[i] + pos); strip (procargs); /* Some ps return full pathname for command. This removes path */ diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 60806bb..89c4d8d 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c @@ -135,13 +135,13 @@ int main(int argc, char **argv){ case CHECK_CLIENTVERSION: - asprintf(&send_buffer, "%s&1", req_password); + xasprintf(&send_buffer, "%s&1", req_password); fetch_data (server_address, server_port, send_buffer); if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) { - asprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list); + xasprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list); return_code = STATE_WARNING; } else { - asprintf (&output_message, "%s", recv_buffer); + xasprintf (&output_message, "%s", recv_buffer); return_code = STATE_OK; } break; @@ -167,7 +167,7 @@ int main(int argc, char **argv){ lvalue_list[2+offset]<=(unsigned long)100) { /* Send request and retrieve data */ - asprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]); + xasprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]); fetch_data (server_address, server_port, send_buffer); utilization=strtoul(recv_buffer,NULL,10); @@ -178,11 +178,11 @@ int main(int argc, char **argv){ else if(utilization >= lvalue_list[1+offset] && return_code= min_peer_sel){ if(verbose) printf("Getting offset, jitter and stratum for peer %.2x\n", ntohs(peers[i].assoc)); - asprintf(&data, ""); + xasprintf(&data, ""); do{ setup_control_request(&req, OP_READVAR, 2); req.assoc = peers[i].assoc; @@ -318,7 +318,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji DBG(print_ntp_control_message(&req)); if(!(req.op&REM_ERROR)) - asprintf(&data, "%s%s", data, req.data); + xasprintf(&data, "%s%s", data, req.data); } while(req.op&REM_MORE); if(req.op&REM_ERROR) { @@ -603,41 +603,41 @@ int main(int argc, char *argv[]){ switch (result) { case STATE_CRITICAL : - asprintf(&result_line, _("NTP CRITICAL:")); + xasprintf(&result_line, _("NTP CRITICAL:")); break; case STATE_WARNING : - asprintf(&result_line, _("NTP WARNING:")); + xasprintf(&result_line, _("NTP WARNING:")); break; case STATE_OK : - asprintf(&result_line, _("NTP OK:")); + xasprintf(&result_line, _("NTP OK:")); break; default : - asprintf(&result_line, _("NTP UNKNOWN:")); + xasprintf(&result_line, _("NTP UNKNOWN:")); break; } if(!syncsource_found) - asprintf(&result_line, "%s %s,", result_line, _("Server not synchronized")); + xasprintf(&result_line, "%s %s,", result_line, _("Server not synchronized")); else if(li_alarm) - asprintf(&result_line, "%s %s,", result_line, _("Server has the LI_ALARM bit set")); + xasprintf(&result_line, "%s %s,", result_line, _("Server has the LI_ALARM bit set")); if(offset_result == STATE_UNKNOWN){ - asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); - asprintf(&perfdata_line, ""); + xasprintf(&result_line, "%s %s", result_line, _("Offset unknown")); + xasprintf(&perfdata_line, ""); } else { - asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); - asprintf(&perfdata_line, "%s", perfd_offset(offset)); + xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); + xasprintf(&perfdata_line, "%s", perfd_offset(offset)); } if (do_jitter) { - asprintf(&result_line, "%s, jitter=%f", result_line, jitter); - asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); + xasprintf(&result_line, "%s, jitter=%f", result_line, jitter); + xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); } if (do_stratum) { - asprintf(&result_line, "%s, stratum=%i", result_line, stratum); - asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum)); + xasprintf(&result_line, "%s, stratum=%i", result_line, stratum); + xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum)); } if (do_truechimers) { - asprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers); - asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers)); + xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers); + xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers)); } printf("%s|%s\n", result_line, perfdata_line); diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index f0f74b4..d543d6b 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c @@ -564,24 +564,24 @@ int main(int argc, char *argv[]){ switch (result) { case STATE_CRITICAL : - asprintf(&result_line, _("NTP CRITICAL:")); + xasprintf(&result_line, _("NTP CRITICAL:")); break; case STATE_WARNING : - asprintf(&result_line, _("NTP WARNING:")); + xasprintf(&result_line, _("NTP WARNING:")); break; case STATE_OK : - asprintf(&result_line, _("NTP OK:")); + xasprintf(&result_line, _("NTP OK:")); break; default : - asprintf(&result_line, _("NTP UNKNOWN:")); + xasprintf(&result_line, _("NTP UNKNOWN:")); break; } if(offset_result == STATE_UNKNOWN){ - asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); - asprintf(&perfdata_line, ""); + xasprintf(&result_line, "%s %s", result_line, _("Offset unknown")); + xasprintf(&perfdata_line, ""); } else { - asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); - asprintf(&perfdata_line, "%s", perfd_offset(offset)); + xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset); + xasprintf(&perfdata_line, "%s", perfd_offset(offset)); } printf("%s|%s\n", result_line, perfdata_line); diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index 81c5575..6ebe8f8 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c @@ -191,7 +191,7 @@ main(int argc, char **argv) { netware_version = strdup(""); else { recv_buffer[strlen(recv_buffer)-1]=0; - asprintf (&netware_version,_("NetWare %s: "),recv_buffer); + xasprintf (&netware_version,_("NetWare %s: "),recv_buffer); } } else netware_version = strdup(""); @@ -215,7 +215,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"UTIL%s\r\n",temp_buffer); + xasprintf (&send_buffer,"UTIL%s\r\n",temp_buffer); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -236,7 +236,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && utilization >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("Load %s - %s %s-min load average = %lu%%|load%s=%lu;%lu;%lu;0;100"), state_text(result), uptime, @@ -264,7 +264,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && current_connections >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("Conns %s - %lu current connections|Conns=%lu;%lu;%lu;;"), state_text(result), current_connections, @@ -289,7 +289,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && cache_hits <= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s: Long term cache hits = %lu%%"), state_text(result), cache_hits); @@ -311,7 +311,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && cache_buffers <= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s: Total cache buffers = %lu|Cachebuffers=%lu;%lu;%lu;;"), state_text(result), cache_buffers, @@ -336,7 +336,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && cache_buffers >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s: Dirty cache buffers = %lu|Dirty-Cache-Buffers=%lu;%lu;%lu;;"), state_text(result), cache_buffers, @@ -361,7 +361,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && lru_time <= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s: LRU sitting time = %lu minutes"), state_text(result), lru_time); @@ -373,13 +373,13 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKF%s\r\n",volume_name); + xasprintf (&send_buffer,"VKF%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { free_disk_space=strtoul(recv_buffer,NULL,10); @@ -387,7 +387,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && free_disk_space <= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s%lu KB free on volume %s|KBFree%s=%lu;%lu;%lu;;"), (result==STATE_OK)?"":_("Only "), free_disk_space, @@ -401,13 +401,13 @@ main(int argc, char **argv) { /* check MB free space on volume */ } else if (vars_to_check==VMF) { - asprintf (&send_buffer,"VMF%s\r\n",volume_name); + xasprintf (&send_buffer,"VMF%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { free_disk_space=strtoul(recv_buffer,NULL,10); @@ -415,7 +415,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && free_disk_space <= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s%lu MB free on volume %s|MBFree%s=%lu;%lu;%lu;;"), (result==STATE_OK)?"":_("Only "), free_disk_space, @@ -428,13 +428,13 @@ main(int argc, char **argv) { /* check MB used space on volume */ } else if (vars_to_check==VMU) { - asprintf (&send_buffer,"VMU%s\r\n",volume_name); + xasprintf (&send_buffer,"VMU%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { free_disk_space=strtoul(recv_buffer,NULL,10); @@ -442,7 +442,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && free_disk_space <= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s%lu MB used on volume %s|MBUsed%s=%lu;%lu;%lu;;"), (result==STATE_OK)?"":_("Only "), free_disk_space, @@ -460,14 +460,14 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKF%s\r\n",volume_name); + xasprintf (&send_buffer,"VKF%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { @@ -477,7 +477,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKS%s\r\n",volume_name); + xasprintf (&send_buffer,"VKS%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -491,7 +491,7 @@ main(int argc, char **argv) { result=STATE_WARNING; free_disk_space/=1024; total_disk_space/=1024; - asprintf (&output_message,_("%lu MB (%lu%%) free on volume %s - total %lu MB|FreeMB%s=%lu;%lu;%lu;0;100"), + xasprintf (&output_message,_("%lu MB (%lu%%) free on volume %s - total %lu MB|FreeMB%s=%lu;%lu;%lu;0;100"), free_disk_space, percent_free_space, volume_name, @@ -525,7 +525,7 @@ main(int argc, char **argv) { result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); temp_buffer=strtok(recv_buffer,"\r\n"); - asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer); + xasprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer); /* check to see if logins are enabled */ } else if (vars_to_check==LOGINS) { @@ -542,13 +542,13 @@ main(int argc, char **argv) { else result=STATE_WARNING; - asprintf (&output_message,_("Logins are %s"),(result==STATE_OK)?_("enabled"):_("disabled")); + xasprintf (&output_message,_("Logins are %s"),(result==STATE_OK)?_("enabled"):_("disabled")); /* check NRM Health Status Summary*/ } else if (vars_to_check==NRMH) { - asprintf (&send_buffer,"NRMH\r\n"); + xasprintf (&send_buffer,"NRMH\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -557,15 +557,15 @@ main(int argc, char **argv) { if (nrm_health_status==2) { result=STATE_OK; - asprintf (&output_message,_("CRITICAL - NRM Status is bad!")); + xasprintf (&output_message,_("CRITICAL - NRM Status is bad!")); } else { if (nrm_health_status==1) { result=STATE_WARNING; - asprintf (&output_message,_("Warning - NRM Status is suspect!")); + xasprintf (&output_message,_("Warning - NRM Status is suspect!")); } - asprintf (&output_message,_("OK - NRM Status is good!")); + xasprintf (&output_message,_("OK - NRM Status is good!")); } @@ -576,7 +576,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S15\r\n"); + xasprintf (&send_buffer,"S15\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -586,7 +586,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S16\r\n"); + xasprintf (&send_buffer,"S16\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -607,7 +607,7 @@ main(int argc, char **argv) { result=STATE_WARNING; } - asprintf (&output_message,_("%lu of %lu (%lu%%) packet receive buffers used"),used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers); + xasprintf (&output_message,_("%lu of %lu (%lu%%) packet receive buffers used"),used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers); /* check SAP table entries */ } else if (vars_to_check==SAPENTRIES) { @@ -616,9 +616,9 @@ main(int argc, char **argv) { my_tcp_connect (server_address, server_port, &sd); if (sap_number==-1) - asprintf (&send_buffer,"S9\r\n"); + xasprintf (&send_buffer,"S9\r\n"); else - asprintf (&send_buffer,"S9.%d\r\n",sap_number); + xasprintf (&send_buffer,"S9.%d\r\n",sap_number); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -631,9 +631,9 @@ main(int argc, char **argv) { result=STATE_WARNING; if (sap_number==-1) - asprintf (&output_message,_("%lu entries in SAP table"),sap_entries); + xasprintf (&output_message,_("%lu entries in SAP table"),sap_entries); else - asprintf (&output_message,_("%lu entries in SAP table for SAP type %d"),sap_entries,sap_number); + xasprintf (&output_message,_("%lu entries in SAP table for SAP type %d"),sap_entries,sap_number); /* check KB purgeable space on volume */ } else if (vars_to_check==VKP) { @@ -641,13 +641,13 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKP%s\r\n",volume_name); + xasprintf (&send_buffer,"VKP%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { purgeable_disk_space=strtoul(recv_buffer,NULL,10); @@ -655,7 +655,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value) result=STATE_WARNING; - asprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), + xasprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), (result==STATE_OK)?"":_("Only "), purgeable_disk_space, volume_name, @@ -667,13 +667,13 @@ main(int argc, char **argv) { /* check MB purgeable space on volume */ } else if (vars_to_check==VMP) { - asprintf (&send_buffer,"VMP%s\r\n",volume_name); + xasprintf (&send_buffer,"VMP%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { purgeable_disk_space=strtoul(recv_buffer,NULL,10); @@ -681,7 +681,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value) result=STATE_WARNING; - asprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), + xasprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), (result==STATE_OK)?"":_("Only "), purgeable_disk_space, volume_name, @@ -697,14 +697,14 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKP%s\r\n",volume_name); + xasprintf (&send_buffer,"VKP%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { @@ -714,7 +714,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKS%s\r\n",volume_name); + xasprintf (&send_buffer,"VKS%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -727,7 +727,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && percent_purgeable_space >= warning_value) result=STATE_WARNING; purgeable_disk_space/=1024; - asprintf (&output_message,_("%lu MB (%lu%%) purgeable on volume %s|Purgeable%s=%lu;%lu;%lu;0;100"), + xasprintf (&output_message,_("%lu MB (%lu%%) purgeable on volume %s|Purgeable%s=%lu;%lu;%lu;0;100"), purgeable_disk_space, percent_purgeable_space, volume_name, @@ -744,13 +744,13 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKNP%s\r\n",volume_name); + xasprintf (&send_buffer,"VKNP%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); @@ -758,7 +758,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && non_purgeable_disk_space >= warning_value) result=STATE_WARNING; - asprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name); + xasprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name); } /* check % not yet purgeable space on volume */ @@ -767,14 +767,14 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKNP%s\r\n",volume_name); + xasprintf (&send_buffer,"VKNP%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); + xasprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); result=STATE_CRITICAL; } else { @@ -784,7 +784,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"VKS%s\r\n",volume_name); + xasprintf (&send_buffer,"VKS%s\r\n",volume_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -797,7 +797,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && percent_non_purgeable_space >= warning_value) result=STATE_WARNING; purgeable_disk_space/=1024; - asprintf (&output_message,_("%lu MB (%lu%%) not yet purgeable on volume %s"),non_purgeable_disk_space,percent_non_purgeable_space,volume_name); + xasprintf (&output_message,_("%lu MB (%lu%%) not yet purgeable on volume %s"),non_purgeable_disk_space,percent_non_purgeable_space,volume_name); } /* check # of open files */ @@ -806,7 +806,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S18\r\n"); + xasprintf (&send_buffer,"S18\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -818,7 +818,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && open_files >= warning_value) result=STATE_WARNING; - asprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"), + xasprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"), open_files, open_files, warning_value, @@ -831,7 +831,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S17\r\n"); + xasprintf (&send_buffer,"S17\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -843,7 +843,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && abended_threads >= warning_value) result=STATE_WARNING; - asprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"), + xasprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"), abended_threads, abended_threads, warning_value, @@ -855,7 +855,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S20\r\n"); + xasprintf (&send_buffer,"S20\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -865,7 +865,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S21\r\n"); + xasprintf (&send_buffer,"S21\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -877,7 +877,7 @@ main(int argc, char **argv) { else if (check_warning_value==TRUE && current_service_processes >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%lu current service processes (%lu max)|Processes=%lu;%lu;%lu;0;%lu"), current_service_processes, max_service_processes, @@ -892,7 +892,7 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S22\r\n"); + xasprintf (&send_buffer,"S22\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -901,10 +901,10 @@ main(int argc, char **argv) { if (time_sync_status==0) { result=STATE_CRITICAL; - asprintf (&output_message,_("CRITICAL - Time not in sync with network!")); + xasprintf (&output_message,_("CRITICAL - Time not in sync with network!")); } else { - asprintf (&output_message,_("OK - Time in sync with network!")); + xasprintf (&output_message,_("OK - Time in sync with network!")); } @@ -927,7 +927,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && lru_time <= warning_value) result=STATE_WARNING; - asprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time); + xasprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time); /* check % dirty cacheobuffers as a percentage of the total*/ @@ -946,7 +946,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && dirty_cache_buffers <= warning_value) result=STATE_WARNING; - asprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"), + xasprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"), dirty_cache_buffers, dirty_cache_buffers, warning_value, @@ -968,7 +968,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && total_cache_buffers <= warning_value) result=STATE_WARNING; - asprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"), + xasprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"), total_cache_buffers, total_cache_buffers, warning_value, @@ -979,21 +979,21 @@ main(int argc, char **argv) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S13\r\n"); + xasprintf (&send_buffer,"S13\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; recv_buffer[strlen(recv_buffer)-1]=0; - asprintf (&output_message,_("NDS Version %s"),recv_buffer); + xasprintf (&output_message,_("NDS Version %s"),recv_buffer); } else if (vars_to_check==UPTIME) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"UPTIME\r\n"); + xasprintf (&send_buffer,"UPTIME\r\n"); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; @@ -1002,35 +1002,35 @@ main(int argc, char **argv) { recv_buffer[sizeof(recv_buffer)-1]=0; recv_buffer[strlen(recv_buffer)-1]=0; - asprintf (&output_message,_("Up %s"),recv_buffer); + xasprintf (&output_message,_("Up %s"),recv_buffer); } else if (vars_to_check==NLM) { close(sd); my_tcp_connect (server_address, server_port, &sd); - asprintf (&send_buffer,"S24:%s\r\n",nlm_name); + xasprintf (&send_buffer,"S24:%s\r\n",nlm_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; recv_buffer[strlen(recv_buffer)-1]=0; if (strcmp(recv_buffer,"-1")) { - asprintf (&output_message,_("Module %s version %s is loaded"),nlm_name,recv_buffer); + xasprintf (&output_message,_("Module %s version %s is loaded"),nlm_name,recv_buffer); } else { result=STATE_CRITICAL; - asprintf (&output_message,_("Module %s is not loaded"),nlm_name); + xasprintf (&output_message,_("Module %s is not loaded"),nlm_name); } } else if (vars_to_check==NRMP) { - asprintf (&send_buffer,"NRMP:%s\r\n",nrmp_name); + xasprintf (&send_buffer,"NRMP:%s\r\n",nrmp_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmp_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmp_name); result=STATE_CRITICAL; } else { nrmp_value=strtoul(recv_buffer,NULL,10); @@ -1038,7 +1038,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nrmp_value <= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nrmp_name, nrmp_value, @@ -1050,13 +1050,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NRMM) { - asprintf (&send_buffer,"NRMM:%s\r\n",nrmm_name); + xasprintf (&send_buffer,"NRMM:%s\r\n",nrmm_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmm_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmm_name); result=STATE_CRITICAL; } else { nrmm_value=strtoul(recv_buffer,NULL,10); @@ -1064,7 +1064,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nrmm_value <= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nrmm_name, nrmm_value, @@ -1076,13 +1076,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NRMS) { - asprintf (&send_buffer,"NRMS:%s\r\n",nrms_name); + xasprintf (&send_buffer,"NRMS:%s\r\n",nrms_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrms_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrms_name); result=STATE_CRITICAL; } else { nrms_value=strtoul(recv_buffer,NULL,10); @@ -1090,7 +1090,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nrms_value >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nrms_name, nrms_value, @@ -1102,13 +1102,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NSS1) { - asprintf (&send_buffer,"NSS1:%s\r\n",nss1_name); + xasprintf (&send_buffer,"NSS1:%s\r\n",nss1_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss1_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss1_name); result=STATE_CRITICAL; } else { nss1_value=strtoul(recv_buffer,NULL,10); @@ -1116,7 +1116,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nss1_value >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nss1_name, nss1_value, @@ -1128,13 +1128,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NSS2) { - asprintf (&send_buffer,"NSS2:%s\r\n",nss2_name); + xasprintf (&send_buffer,"NSS2:%s\r\n",nss2_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss2_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss2_name); result=STATE_CRITICAL; } else { nss2_value=strtoul(recv_buffer,NULL,10); @@ -1142,7 +1142,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nss2_value >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nss2_name, nss2_value, @@ -1154,13 +1154,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NSS3) { - asprintf (&send_buffer,"NSS3:%s\r\n",nss3_name); + xasprintf (&send_buffer,"NSS3:%s\r\n",nss3_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss3_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss3_name); result=STATE_CRITICAL; } else { nss3_value=strtoul(recv_buffer,NULL,10); @@ -1168,7 +1168,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nss3_value >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nss3_name, nss3_value, @@ -1180,13 +1180,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NSS4) { - asprintf (&send_buffer,"NSS4:%s\r\n",nss4_name); + xasprintf (&send_buffer,"NSS4:%s\r\n",nss4_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss4_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss4_name); result=STATE_CRITICAL; } else { nss4_value=strtoul(recv_buffer,NULL,10); @@ -1194,7 +1194,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nss4_value >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nss4_name, nss4_value, @@ -1206,13 +1206,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NSS5) { - asprintf (&send_buffer,"NSS5:%s\r\n",nss5_name); + xasprintf (&send_buffer,"NSS5:%s\r\n",nss5_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss5_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss5_name); result=STATE_CRITICAL; } else { nss5_value=strtoul(recv_buffer,NULL,10); @@ -1220,7 +1220,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nss5_value >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nss5_name, nss5_value, @@ -1232,13 +1232,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NSS6) { - asprintf (&send_buffer,"NSS6:%s\r\n",nss6_name); + xasprintf (&send_buffer,"NSS6:%s\r\n",nss6_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss6_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss6_name); result=STATE_CRITICAL; } else { nss6_value=strtoul(recv_buffer,NULL,10); @@ -1246,7 +1246,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nss6_value >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nss6_name, nss6_value, @@ -1258,13 +1258,13 @@ main(int argc, char **argv) { } else if (vars_to_check==NSS7) { - asprintf (&send_buffer,"NSS7:%s\r\n",nss7_name); + xasprintf (&send_buffer,"NSS7:%s\r\n",nss7_name); result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); if (result!=STATE_OK) return result; if (!strcmp(recv_buffer,"-1\n")) { - asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss7_name); + xasprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss7_name); result=STATE_CRITICAL; } else { nss7_value=strtoul(recv_buffer,NULL,10); @@ -1272,7 +1272,7 @@ main(int argc, char **argv) { result=STATE_CRITICAL; else if (check_warning_value==TRUE && nss7_value >= warning_value) result=STATE_WARNING; - asprintf (&output_message, + xasprintf (&output_message, _("%s is %lu|%s=%lu;%lu;%lu;;"), nss7_name, nss7_value, @@ -1591,7 +1591,7 @@ int process_arguments(int argc, char **argv) { void print_help(void) { char *myport; - asprintf (&myport, "%d", PORT); + xasprintf (&myport, "%d", PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c index 16ada20..95977e9 100644 --- a/plugins/check_overcr.c +++ b/plugins/check_overcr.c @@ -409,7 +409,7 @@ void print_help (void) { char *myport; - asprintf (&myport, "%d", PORT); + xasprintf (&myport, "%d", PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 19c3117..69edae7 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c @@ -417,7 +417,7 @@ print_help (void) { char *myport; - asprintf (&myport, "%d", DEFAULT_PORT); + xasprintf (&myport, "%d", DEFAULT_PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 473f9f2..eef2195 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -121,12 +121,12 @@ main (int argc, char **argv) /* does the host address of number of packets argument come first? */ #ifdef PING_PACKETS_FIRST # ifdef PING_HAS_TIMEOUT - asprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]); + xasprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]); # else - asprintf (&cmd, rawcmd, max_packets, addresses[i]); + xasprintf (&cmd, rawcmd, max_packets, addresses[i]); # endif #else - asprintf (&cmd, rawcmd, addresses[i], max_packets); + xasprintf (&cmd, rawcmd, addresses[i], max_packets); #endif if (verbose >= 2) @@ -491,7 +491,7 @@ run_ping (const char *cmd, const char *addr) if (warn_text == NULL) { warn_text = strdup(_("System call sent warnings to stderr ")); } else { - asprintf(&warn_text, "%s %s", warn_text, _("System call sent warnings to stderr ")); + xasprintf(&warn_text, "%s %s", warn_text, _("System call sent warnings to stderr ")); } } } @@ -540,7 +540,7 @@ error_scan (char buf[MAX_INPUT_BUFFER], const char *addr) if (warn_text == NULL) warn_text = strdup (_(WARN_DUPLICATES)); else if (! strstr (warn_text, _(WARN_DUPLICATES)) && - asprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1) + xasprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1) die (STATE_UNKNOWN, _("Unable to realloc warn_text\n")); return (STATE_WARNING); } diff --git a/plugins/check_procs.c b/plugins/check_procs.c index d875a61..2f2dcc5 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -137,7 +137,7 @@ main (int argc, char **argv) input_buffer = malloc (MAX_INPUT_BUFFER); procprog = malloc (MAX_INPUT_BUFFER); - asprintf (&metric_name, "PROCS"); + xasprintf (&metric_name, "PROCS"); metric = METRIC_PROCS; /* Parse extra opts if any */ @@ -176,7 +176,7 @@ main (int argc, char **argv) printf ("%s", input_line); strcpy (procprog, ""); - asprintf (&procargs, "%s", ""); + xasprintf (&procargs, "%s", ""); cols = sscanf (input_line, PS_FORMAT, PS_VARLIST); @@ -186,7 +186,7 @@ main (int argc, char **argv) } if ( cols >= expected_cols ) { resultsum = 0; - asprintf (&procargs, "%s", input_line + pos); + xasprintf (&procargs, "%s", input_line + pos); strip (procargs); /* Some ps return full pathname for command. This removes path */ @@ -250,12 +250,12 @@ main (int argc, char **argv) if (metric != METRIC_PROCS) { if (i == STATE_WARNING) { warn++; - asprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog); + xasprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog); result = max_state (result, i); } if (i == STATE_CRITICAL) { crit++; - asprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog); + xasprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog); result = max_state (result, i); } } @@ -393,7 +393,7 @@ process_arguments (int argc, char **argv) break; case 'p': /* process id */ if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { - asprintf (&fmt, "%s%sPPID = %d", (fmt ? fmt : "") , (options ? ", " : ""), ppid); + xasprintf (&fmt, "%s%sPPID = %d", (fmt ? fmt : "") , (options ? ", " : ""), ppid); options |= PPID; break; } @@ -403,7 +403,7 @@ process_arguments (int argc, char **argv) break; else statopts = optarg; - asprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); + xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); options |= STAT; break; case 'u': /* user or user id */ @@ -423,7 +423,7 @@ process_arguments (int argc, char **argv) uid = pw->pw_uid; } user = pw->pw_name; - asprintf (&fmt, "%s%sUID = %d (%s)", (fmt ? fmt : ""), (options ? ", " : ""), + xasprintf (&fmt, "%s%sUID = %d (%s)", (fmt ? fmt : ""), (options ? ", " : ""), uid, user); options |= USER; break; @@ -433,7 +433,7 @@ process_arguments (int argc, char **argv) break; else prog = optarg; - asprintf (&fmt, _("%s%scommand name '%s'"), (fmt ? fmt : ""), (options ? ", " : ""), + xasprintf (&fmt, _("%s%scommand name '%s'"), (fmt ? fmt : ""), (options ? ", " : ""), prog); options |= PROG; break; @@ -443,7 +443,7 @@ process_arguments (int argc, char **argv) break; else args = optarg; - asprintf (&fmt, "%s%sargs '%s'", (fmt ? fmt : ""), (options ? ", " : ""), args); + xasprintf (&fmt, "%s%sargs '%s'", (fmt ? fmt : ""), (options ? ", " : ""), args); options |= ARGS; break; case CHAR_MAX+1: @@ -459,19 +459,19 @@ process_arguments (int argc, char **argv) temp_string[i]=','; i++; } - asprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), temp_string); + xasprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), temp_string); options |= EREG_ARGS; break; case 'r': /* RSS */ if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) { - asprintf (&fmt, "%s%sRSS >= %d", (fmt ? fmt : ""), (options ? ", " : ""), rss); + xasprintf (&fmt, "%s%sRSS >= %d", (fmt ? fmt : ""), (options ? ", " : ""), rss); options |= RSS; break; } usage4 (_("RSS must be an integer!")); case 'z': /* VSZ */ if (sscanf (optarg, "%d%[^0-9]", &vsz, tmp) == 1) { - asprintf (&fmt, "%s%sVSZ >= %d", (fmt ? fmt : ""), (options ? ", " : ""), vsz); + xasprintf (&fmt, "%s%sVSZ >= %d", (fmt ? fmt : ""), (options ? ", " : ""), vsz); options |= VSZ; break; } @@ -479,13 +479,13 @@ process_arguments (int argc, char **argv) case 'P': /* PCPU */ /* TODO: -P 1.5.5 is accepted */ if (sscanf (optarg, "%f%[^0-9.]", &pcpu, tmp) == 1) { - asprintf (&fmt, "%s%sPCPU >= %.2f", (fmt ? fmt : ""), (options ? ", " : ""), pcpu); + xasprintf (&fmt, "%s%sPCPU >= %.2f", (fmt ? fmt : ""), (options ? ", " : ""), pcpu); options |= PCPU; break; } usage4 (_("PCPU must be a float!")); case 'm': - asprintf (&metric_name, "%s", optarg); + xasprintf (&metric_name, "%s", optarg); if ( strcmp(optarg, "PROCS") == 0) { metric = METRIC_PROCS; break; @@ -523,8 +523,8 @@ process_arguments (int argc, char **argv) if (cmax == -1 && argv[c]) cmax = atoi (argv[c++]); if (statopts == NULL && argv[c]) { - asprintf (&statopts, "%s", argv[c++]); - asprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); + xasprintf (&statopts, "%s", argv[c++]); + xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); options |= STAT; } diff --git a/plugins/check_radius.c b/plugins/check_radius.c index c2c93ee..e54105b 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c @@ -328,7 +328,7 @@ void print_help (void) { char *myport; - asprintf (&myport, "%d", PW_AUTH_UDP_PORT); + xasprintf (&myport, "%d", PW_AUTH_UDP_PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_real.c b/plugins/check_real.c index d67e190..18240f3 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c @@ -403,7 +403,7 @@ void print_help (void) { char *myport; - asprintf (&myport, "%d", PORT); + xasprintf (&myport, "%d", PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 77ac5ce..6b3f9dd 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -156,15 +156,15 @@ main (int argc, char **argv) } } if(use_ehlo) - asprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n"); + xasprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n"); else - asprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n"); + xasprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n"); if (verbose) printf("HELOCMD: %s", helocmd); /* initialize the MAIL command with optional FROM command */ - asprintf (&cmd_str, "%sFROM:<%s>%s", mail_command, from_arg, "\r\n"); + xasprintf (&cmd_str, "%sFROM:<%s>%s", mail_command, from_arg, "\r\n"); if (verbose && smtp_use_dummycmd) printf ("FROM CMD: %s", cmd_str); @@ -299,7 +299,7 @@ main (int argc, char **argv) } while (n < ncommands) { - asprintf (&cmd_str, "%s%s", commands[n], "\r\n"); + xasprintf (&cmd_str, "%s%s", commands[n], "\r\n"); my_send(cmd_str, strlen(cmd_str)); if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose) printf("%s", buffer); @@ -336,12 +336,12 @@ main (int argc, char **argv) do { if (authuser == NULL) { result = STATE_CRITICAL; - asprintf(&error_msg, _("no authuser specified, ")); + xasprintf(&error_msg, _("no authuser specified, ")); break; } if (authpass == NULL) { result = STATE_CRITICAL; - asprintf(&error_msg, _("no authpass specified, ")); + xasprintf(&error_msg, _("no authpass specified, ")); break; } @@ -351,7 +351,7 @@ main (int argc, char **argv) printf (_("sent %s\n"), "AUTH LOGIN"); if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) { - asprintf(&error_msg, _("recv() failed after AUTH LOGIN, ")); + xasprintf(&error_msg, _("recv() failed after AUTH LOGIN, ")); result = STATE_WARNING; break; } @@ -360,7 +360,7 @@ main (int argc, char **argv) if (strncmp (buffer, "334", 3) != 0) { result = STATE_CRITICAL; - asprintf(&error_msg, _("invalid response received after AUTH LOGIN, ")); + xasprintf(&error_msg, _("invalid response received after AUTH LOGIN, ")); break; } @@ -374,7 +374,7 @@ main (int argc, char **argv) if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) { result = STATE_CRITICAL; - asprintf(&error_msg, _("recv() failed after sending authuser, ")); + xasprintf(&error_msg, _("recv() failed after sending authuser, ")); break; } if (verbose) { @@ -382,7 +382,7 @@ main (int argc, char **argv) } if (strncmp (buffer, "334", 3) != 0) { result = STATE_CRITICAL; - asprintf(&error_msg, _("invalid response received after authuser, ")); + xasprintf(&error_msg, _("invalid response received after authuser, ")); break; } /* encode authpass with base64 */ @@ -395,7 +395,7 @@ main (int argc, char **argv) } if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) { result = STATE_CRITICAL; - asprintf(&error_msg, _("recv() failed after sending authpass, ")); + xasprintf(&error_msg, _("recv() failed after sending authpass, ")); break; } if (verbose) { @@ -403,14 +403,14 @@ main (int argc, char **argv) } if (strncmp (buffer, "235", 3) != 0) { result = STATE_CRITICAL; - asprintf(&error_msg, _("invalid response received after authpass, ")); + xasprintf(&error_msg, _("invalid response received after authpass, ")); break; } break; } while (0); } else { result = STATE_CRITICAL; - asprintf(&error_msg, _("only authtype LOGIN is supported, ")); + xasprintf(&error_msg, _("only authtype LOGIN is supported, ")); } } @@ -654,7 +654,7 @@ process_arguments (int argc, char **argv) usage2 (_("Invalid hostname/address"), argv[c]); } else { - asprintf (&server_address, "127.0.0.1"); + xasprintf (&server_address, "127.0.0.1"); } } @@ -787,7 +787,7 @@ void print_help (void) { char *myport; - asprintf (&myport, "%d", SMTP_PORT); + xasprintf (&myport, "%d", SMTP_PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index a5a88d2..2d9861b 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -255,9 +255,9 @@ main (int argc, char **argv) command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); command_line[0] = snmpcmd; command_line[1] = strdup ("-t"); - asprintf (&command_line[2], "%d", timeout_interval); + xasprintf (&command_line[2], "%d", timeout_interval); command_line[3] = strdup ("-r"); - asprintf (&command_line[4], "%d", retries); + xasprintf (&command_line[4], "%d", retries); command_line[5] = strdup ("-m"); command_line[6] = strdup (miblist); command_line[7] = "-v"; @@ -267,16 +267,16 @@ main (int argc, char **argv) command_line[9 + i] = authpriv[i]; } - asprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); + xasprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); /* This is just for display purposes, so it can remain a string */ - asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", + xasprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", server_address, port); for (i = 0; i < numoids; i++) { command_line[9 + numauthpriv + 1 + i] = oids[i]; - asprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); + xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); } command_line[9 + numauthpriv + 1 + numoids] = NULL; @@ -371,14 +371,14 @@ main (int argc, char **argv) if (dq_count) { /* unfinished line */ /* copy show verbatim first */ if (!mult_resp) mult_resp = strdup(""); - asprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show); + xasprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show); /* then strip out unmatched double-quote from single-line output */ if (show[0] == '"') show++; /* Keep reading until we match end of double-quoted string */ for (line++; line < chld_out.lines; line++) { ptr = chld_out.line[line]; - asprintf (&mult_resp, "%s%s\n", mult_resp, ptr); + xasprintf (&mult_resp, "%s%s\n", mult_resp, ptr); COUNT_SEQ(ptr, bk_count, dq_count) while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') { @@ -424,11 +424,11 @@ main (int argc, char **argv) /* Convert to per second, then use multiplier */ temp_double = temp_double/duration*rate_multiplier; iresult = get_status(temp_double, thlds[i]); - asprintf (&show, conv, temp_double); + xasprintf (&show, conv, temp_double); } } else { iresult = get_status(response_value[i], thlds[i]); - asprintf (&show, conv, response_value[i]); + xasprintf (&show, conv, response_value[i]); } } @@ -472,16 +472,16 @@ main (int argc, char **argv) /* Prepend a label for this OID if there is one */ if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) - asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, + xasprintf (&outbuff, "%s%s%s %s%s%s", outbuff, (i == 0) ? " " : output_delim, labels[i], mark (iresult), show, mark (iresult)); else - asprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim, + xasprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim, mark (iresult), show, mark (iresult)); /* Append a unit string for this OID if there is one */ if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) - asprintf (&outbuff, "%s %s", outbuff, unitv[i]); + xasprintf (&outbuff, "%s %s", outbuff, unitv[i]); /* Write perfdata with whatever can be parsed by strtod, if possible */ ptr = NULL; @@ -523,7 +523,7 @@ main (int argc, char **argv) current_length=0; for(i=0; i 120.0) ups_utility_deviation = 120.0 - ups_utility_voltage; @@ -211,13 +211,13 @@ main (int argc, char **argv) else if (check_warn==TRUE && ups_utility_deviation>=warning_value) { result = max_state (result, STATE_WARNING); } - asprintf (&data, "%s", + xasprintf (&data, "%s", perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", check_warn, (long)(1000*warning_value), check_crit, (long)(1000*critical_value), TRUE, 0, FALSE, 0)); } else { - asprintf (&data, "%s", + xasprintf (&data, "%s", perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); } @@ -231,7 +231,7 @@ main (int argc, char **argv) else { supported_options |= UPS_BATTPCT; ups_battery_percent = atof (temp_buffer); - asprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); + xasprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); if (check_variable == UPS_BATTPCT) { if (check_crit==TRUE && ups_battery_percent <= critical_value) { @@ -240,13 +240,13 @@ main (int argc, char **argv) else if (check_warn==TRUE && ups_battery_percent<=warning_value) { result = max_state (result, STATE_WARNING); } - asprintf (&data, "%s %s", data, + xasprintf (&data, "%s %s", data, perfdata ("battery", (long)ups_battery_percent, "%", check_warn, (long)(1000*warning_value), check_crit, (long)(1000*critical_value), TRUE, 0, TRUE, 100)); } else { - asprintf (&data, "%s %s", data, + xasprintf (&data, "%s %s", data, perfdata ("battery", (long)ups_battery_percent, "%", FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); } @@ -260,7 +260,7 @@ main (int argc, char **argv) else { supported_options |= UPS_LOADPCT; ups_load_percent = atof (temp_buffer); - asprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); + xasprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); if (check_variable == UPS_LOADPCT) { if (check_crit==TRUE && ups_load_percent>=critical_value) { @@ -269,13 +269,13 @@ main (int argc, char **argv) else if (check_warn==TRUE && ups_load_percent>=warning_value) { result = max_state (result, STATE_WARNING); } - asprintf (&data, "%s %s", data, + xasprintf (&data, "%s %s", data, perfdata ("load", (long)ups_load_percent, "%", check_warn, (long)(1000*warning_value), check_crit, (long)(1000*critical_value), TRUE, 0, TRUE, 100)); } else { - asprintf (&data, "%s %s", data, + xasprintf (&data, "%s %s", data, perfdata ("load", (long)ups_load_percent, "%", FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); } @@ -291,12 +291,12 @@ main (int argc, char **argv) if (temp_output_c) { tunits="degC"; ups_temperature = atof (temp_buffer); - asprintf (&message, "%sTemp=%3.1fC", message, ups_temperature); + xasprintf (&message, "%sTemp=%3.1fC", message, ups_temperature); } else { tunits="degF"; ups_temperature = (atof (temp_buffer) * 1.8) + 32; - asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); + xasprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); } if (check_variable == UPS_TEMP) { @@ -306,13 +306,13 @@ main (int argc, char **argv) else if (check_warn == TRUE && ups_temperature>=warning_value) { result = max_state (result, STATE_WARNING); } - asprintf (&data, "%s %s", data, + xasprintf (&data, "%s %s", data, perfdata ("temp", (long)ups_temperature, tunits, check_warn, (long)(1000*warning_value), check_crit, (long)(1000*critical_value), TRUE, 0, FALSE, 0)); } else { - asprintf (&data, "%s %s", data, + xasprintf (&data, "%s %s", data, perfdata ("temp", (long)ups_temperature, tunits, FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); } @@ -321,7 +321,7 @@ main (int argc, char **argv) /* if the UPS does not support any options we are looking for, report an error */ if (supported_options == UPS_NONE) { result = STATE_CRITICAL; - asprintf (&message, _("UPS does not support any available options\n")); + xasprintf (&message, _("UPS does not support any available options\n")); } /* reset timeout */ @@ -595,7 +595,7 @@ void print_help (void) { char *myport; - asprintf (&myport, "%d", PORT); + xasprintf (&myport, "%d", PORT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_users.c b/plugins/check_users.c index 3766292..c581fb2 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c @@ -89,7 +89,7 @@ main (int argc, char **argv) if (result == STATE_UNKNOWN) printf ("%s\n", _("Unable to read output")); else { - asprintf (&perf, "%s", perfdata ("users", users, "", + xasprintf (&perf, "%s", perfdata ("users", users, "", TRUE, wusers, TRUE, cusers, TRUE, 0, diff --git a/plugins/negate.c b/plugins/negate.c index 96f4557..493988e 100644 --- a/plugins/negate.c +++ b/plugins/negate.c @@ -104,7 +104,7 @@ main (int argc, char **argv) *sub = '\0'; sub += strlen (state_text (result)); /* then put everything back together */ - asprintf (&chld_out.line[i], "%s%s%s", chld_out.line[i], state_text (state[result]), sub); + xasprintf (&chld_out.line[i], "%s%s%s", chld_out.line[i], state_text (state[result]), sub); } } printf ("%s\n", chld_out.line[i]); diff --git a/plugins/urlize.c b/plugins/urlize.c index 6bb42db..30b2a35 100644 --- a/plugins/urlize.c +++ b/plugins/urlize.c @@ -102,7 +102,7 @@ main (int argc, char **argv) cmd = strdup (argv[optind++]); for (c = optind; c < argc; c++) { - asprintf (&cmd, "%s %s", cmd, argv[c]); + xasprintf (&cmd, "%s %s", cmd, argv[c]); } child_process = spopen (cmd); diff --git a/plugins/utils.c b/plugins/utils.c index 4537390..8827e31 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -358,7 +358,7 @@ strscpy (char *dest, const char *src) if (src == NULL) return NULL; - asprintf (&dest, "%s", src); + xasprintf (&dest, "%s", src); return dest; } @@ -513,6 +513,33 @@ strpcat (char *dest, const char *src, const char *str) return dest; } + +/****************************************************************************** + * + * asprintf, but die on failure + * + ******************************************************************************/ + +int +xvasprintf (char **strp, const char *fmt, va_list ap) +{ + int result = vasprintf (strp, fmt, ap); + if (result == -1 || *strp == NULL) + die (STATE_UNKNOWN, _("failed malloc in xvasprintf\n")); + return result; +} + +int +xasprintf (char **strp, const char *fmt, ...) +{ + va_list ap; + int result; + va_start (ap, fmt); + result = xvasprintf (strp, fmt, ap); + va_end (ap); + return result; +} + /****************************************************************************** * * Print perfdata in a standard format @@ -534,25 +561,25 @@ char *perfdata (const char *label, char *data = NULL; if (strpbrk (label, "'= ")) - asprintf (&data, "'%s'=%ld%s;", label, val, uom); + xasprintf (&data, "'%s'=%ld%s;", label, val, uom); else - asprintf (&data, "%s=%ld%s;", label, val, uom); + xasprintf (&data, "%s=%ld%s;", label, val, uom); if (warnp) - asprintf (&data, "%s%ld;", data, warn); + xasprintf (&data, "%s%ld;", data, warn); else - asprintf (&data, "%s;", data); + xasprintf (&data, "%s;", data); if (critp) - asprintf (&data, "%s%ld;", data, crit); + xasprintf (&data, "%s%ld;", data, crit); else - asprintf (&data, "%s;", data); + xasprintf (&data, "%s;", data); if (minp) - asprintf (&data, "%s%ld", data, minv); + xasprintf (&data, "%s%ld", data, minv); if (maxp) - asprintf (&data, "%s;%ld", data, maxv); + xasprintf (&data, "%s;%ld", data, maxv); return data; } @@ -573,29 +600,29 @@ char *fperfdata (const char *label, char *data = NULL; if (strpbrk (label, "'= ")) - asprintf (&data, "'%s'=", label); + xasprintf (&data, "'%s'=", label); else - asprintf (&data, "%s=", label); + xasprintf (&data, "%s=", label); - asprintf (&data, "%s%f", data, val); - asprintf (&data, "%s%s;", data, uom); + xasprintf (&data, "%s%f", data, val); + xasprintf (&data, "%s%s;", data, uom); if (warnp) - asprintf (&data, "%s%f", data, warn); + xasprintf (&data, "%s%f", data, warn); - asprintf (&data, "%s;", data); + xasprintf (&data, "%s;", data); if (critp) - asprintf (&data, "%s%f", data, crit); + xasprintf (&data, "%s%f", data, crit); - asprintf (&data, "%s;", data); + xasprintf (&data, "%s;", data); if (minp) - asprintf (&data, "%s%f", data, minv); + xasprintf (&data, "%s%f", data, minv); if (maxp) { - asprintf (&data, "%s;", data); - asprintf (&data, "%s%f", data, maxv); + xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%f", data, maxv); } return data; diff --git a/plugins/utils.h b/plugins/utils.h index 3c3f189..822be94 100644 --- a/plugins/utils.h +++ b/plugins/utils.h @@ -81,6 +81,8 @@ char *strscpy (char *, const char *); char *strnl (char *); char *strpcpy (char *, const char *, const char *); char *strpcat (char *, const char *, const char *); +int xvasprintf (char **strp, const char *fmt, va_list ap); +int xasprintf (char **strp, const char *fmt, ...); int max_state (int a, int b); int max_state_alt (int a, int b); -- cgit v0.10-9-g596f