From c0bcad7feb18bd1e3a1f98f2f41c437925a8dbf0 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 4 Nov 2024 23:12:18 +0100 Subject: check_disk: Initialize most variables --- plugins/check_disk.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'plugins') diff --git a/plugins/check_disk.c b/plugins/check_disk.c index d1d1b92a..037a6f7a 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -156,20 +156,20 @@ static struct name_list *seen = NULL; int main(int argc, char **argv) { int result = STATE_UNKNOWN; int disk_result = STATE_UNKNOWN; - char *output; - char *ignored; - char *details; - char *perf; - char *perf_ilabel; + char *output = NULL; + char *ignored = NULL; + char *details = NULL; + char *perf = NULL; + char *perf_ilabel = NULL; char *preamble = " - free space:"; char *ignored_preamble = " - ignored paths:"; - char *flag_header; - int temp_result; + char *flag_header = NULL; + int temp_result = STATE_UNKNOWN; - struct mount_entry *me; - struct fs_usage fsp; - struct parameter_list *temp_list; - struct parameter_list *path; + struct mount_entry *me = NULL; + struct fs_usage fsp = {0}; + struct parameter_list *temp_list = NULL; + struct parameter_list *path = NULL; #ifdef __CYGWIN__ char mountdir[32]; -- cgit v1.2.3-74-g34f1 From 88d991773b6d8ac416ad2931ea8debc949555c7a Mon Sep 17 00:00:00 2001 From: William Date: Wed, 6 Nov 2024 14:00:23 +1000 Subject: Add dontfrag/random for fping Support the dont fragment and randomise packet data options for check_fping --- plugins/check_fping.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'plugins') diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 49235e28..67fa2363 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -60,6 +60,8 @@ static int packet_count = PACKET_COUNT; static int target_timeout = 0; static int packet_interval = 0; static bool verbose = false; +static bool dontfrag = false; +static bool randomize_packet_data = false; static int cpl; static int wpl; static double crta; @@ -103,6 +105,11 @@ int main(int argc, char **argv) { xasprintf(&option_string, "%s-S %s ", option_string, sourceip); if (sourceif) xasprintf(&option_string, "%s-I %s ", option_string, sourceif); + if (dontfrag) + xasprintf(&option_string, "%s-M ", option_string); + if (randomize_packet_data) + xasprintf(&option_string, "%s-R ", option_string); + #ifdef PATH_TO_FPING6 if (address_family != AF_INET && is_inet6_addr(server)) @@ -279,6 +286,8 @@ int process_arguments(int argc, char **argv) { {"help", no_argument, 0, 'h'}, {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, + {"dontfrag", no_argument, 0, 'M'}, + {"random", no_argument, 0, 'R'}, {0, 0, 0, 0}}; rv[PL] = NULL; @@ -390,6 +399,12 @@ int process_arguments(int argc, char **argv) { else usage(_("Interval must be a positive integer")); break; + case 'R': + randomize_packet_data = true; + break; + case 'M': + dontfrag = true; + break; } } @@ -470,6 +485,10 @@ void print_help(void) { printf(" %s\n", _("name or IP Address of sourceip")); printf(" %s\n", "-I, --sourceif=IF"); printf(" %s\n", _("source interface name")); + printf(" %s\n", "-M, --dontfrag"); + printf(" %s\n", _("set the Don't Fragment flag")); + printf(" %s\n", "-R, --random"); + printf(" %s\n", _("random packet data (to foil link data compression)")); printf(UT_VERBOSE); printf("\n"); printf(" %s\n", _("THRESHOLD is ,%% where is the round trip average travel time (ms)")); -- cgit v1.2.3-74-g34f1 From d5ed947e312bcb8f0c4e46c4ea9f39918387efc3 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 8 Nov 2024 14:07:29 +1000 Subject: Add missed changes for dontfrag Due to a mistake with git the command line args were not properly updated. --- plugins/check_fping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 67fa2363..c1d03ece 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -7,7 +7,7 @@ * * Description: * - * This file contains the check_disk plugin + * This file contains the check_fping plugin * * This plugin will use the fping command to ping the specified host for a * fast check @@ -304,7 +304,7 @@ int process_arguments(int argc, char **argv) { } while (1) { - c = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:46", longopts, &option); + c = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option); if (c == -1 || c == EOF || c == 1) break; -- cgit v1.2.3-74-g34f1 From 962053e6ab58ade05a43eb222a0308770ce89634 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:48:58 +0100 Subject: check_apt: clang-format --- plugins/check_apt.c | 504 ++++++++++++++++++++++++++-------------------------- 1 file changed, 251 insertions(+), 253 deletions(-) (limited to 'plugins') diff --git a/plugins/check_apt.c b/plugins/check_apt.c index 5e4021b5..02af1a43 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -42,14 +42,14 @@ const char *email = "devel@monitoring-plugins.org"; typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; /* Character for hidden input file option (for testing). */ -#define INPUT_FILE_OPT CHAR_MAX+1 +#define INPUT_FILE_OPT CHAR_MAX + 1 /* the default opts can be overridden via the cmdline */ #define UPGRADE_DEFAULT_OPTS "-o 'Debug::NoLocking=true' -s -qq" -#define UPDATE_DEFAULT_OPTS "-q" +#define UPDATE_DEFAULT_OPTS "-q" /* until i commit the configure.in patch which gets this, i'll define * it here as well */ #ifndef PATH_TO_APTGET -# define PATH_TO_APTGET "/usr/bin/apt-get" +# define PATH_TO_APTGET "/usr/bin/apt-get" #endif /* PATH_TO_APTGET */ /* String found at the beginning of the apt output lines we're interested in */ #define PKGINST_PREFIX "Inst " @@ -62,91 +62,84 @@ void print_help(void); void print_usage(void); /* construct the appropriate apt-get cmdline */ -char* construct_cmdline(upgrade_type u, const char *opts); +char *construct_cmdline(upgrade_type u, const char *opts); /* run an apt-get update */ int run_update(void); /* run an apt-get upgrade */ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist); /* add another clause to a regexp */ -char* add_to_regexp(char *expr, const char *next); +char *add_to_regexp(char *expr, const char *next); /* extract package name from Inst line */ -char* pkg_name(char *line); +char *pkg_name(char *line); /* string comparison function for qsort */ int cmpstringp(const void *p1, const void *p2); /* configuration variables */ -static int verbose = 0; /* -v */ -static bool list = false; /* list packages available for upgrade */ -static bool do_update = false; /* whether to call apt-get update */ -static bool only_critical = false; /* whether to warn about non-critical updates */ +static int verbose = 0; /* -v */ +static bool list = false; /* list packages available for upgrade */ +static bool do_update = false; /* whether to call apt-get update */ +static bool only_critical = false; /* whether to warn about non-critical updates */ static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */ -static char *upgrade_opts = NULL; /* options to override defaults for upgrade */ -static char *update_opts = NULL; /* options to override defaults for update */ -static char *do_include = NULL; /* regexp to only include certain packages */ -static char *do_exclude = NULL; /* regexp to only exclude certain packages */ -static char *do_critical = NULL; /* regexp specifying critical packages */ -static char *input_filename = NULL; /* input filename for testing */ +static char *upgrade_opts = NULL; /* options to override defaults for upgrade */ +static char *update_opts = NULL; /* options to override defaults for update */ +static char *do_include = NULL; /* regexp to only include certain packages */ +static char *do_exclude = NULL; /* regexp to only exclude certain packages */ +static char *do_critical = NULL; /* regexp specifying critical packages */ +static char *input_filename = NULL; /* input filename for testing */ /* number of packages available for upgrade to return WARNING status */ static int packages_warning = 1; /* other global variables */ -static int stderr_warning = 0; /* if a cmd issued output on stderr */ -static int exec_warning = 0; /* if a cmd exited non-zero */ +static int stderr_warning = 0; /* if a cmd issued output on stderr */ +static int exec_warning = 0; /* if a cmd exited non-zero */ -int main (int argc, char **argv) { - int result=STATE_UNKNOWN, packages_available=0, sec_count=0; - char **packages_list=NULL, **secpackages_list=NULL; +int main(int argc, char **argv) { + int result = STATE_UNKNOWN, packages_available = 0, sec_count = 0; + char **packages_list = NULL, **secpackages_list = NULL; /* Parse extra opts if any */ - argv=np_extra_opts(&argc, argv, progname); + argv = np_extra_opts(&argc, argv, progname); if (process_arguments(argc, argv) == ERROR) usage_va(_("Could not parse arguments")); /* Set signal handling and alarm timeout */ - if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { + if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) { usage_va(_("Cannot catch SIGALRM")); } /* handle timeouts gracefully... */ - alarm (timeout_interval); + alarm(timeout_interval); /* if they want to run apt-get update first... */ - if(do_update) result = run_update(); + if (do_update) + result = run_update(); /* apt-get upgrade */ result = max_state(result, run_upgrade(&packages_available, &sec_count, &packages_list, &secpackages_list)); - if(sec_count > 0){ + if (sec_count > 0) { result = max_state(result, STATE_CRITICAL); - } else if(packages_available >= packages_warning && only_critical == false){ + } else if (packages_available >= packages_warning && only_critical == false) { result = max_state(result, STATE_WARNING); - } else if(result > STATE_UNKNOWN){ + } else if (result > STATE_UNKNOWN) { result = STATE_UNKNOWN; } printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s|available_upgrades=%d;;;0 critical_updates=%d;;;0\n"), - state_text(result), - packages_available, - (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade", - sec_count, - (stderr_warning)?" warnings detected":"", - (stderr_warning && exec_warning)?",":"", - (exec_warning)?" errors detected":"", - (stderr_warning||exec_warning)?".":"", - packages_available, - sec_count - ); - - if(list) { - qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp); - qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp); - - for(int i = 0; i < sec_count; i++) + state_text(result), packages_available, (upgrade == DIST_UPGRADE) ? "dist-upgrade" : "upgrade", sec_count, + (stderr_warning) ? " warnings detected" : "", (stderr_warning && exec_warning) ? "," : "", + (exec_warning) ? " errors detected" : "", (stderr_warning || exec_warning) ? "." : "", packages_available, sec_count); + + if (list) { + qsort(secpackages_list, sec_count, sizeof(char *), cmpstringp); + qsort(packages_list, packages_available - sec_count, sizeof(char *), cmpstringp); + + for (int i = 0; i < sec_count; i++) printf("%s (security)\n", secpackages_list[i]); if (only_critical == false) { - for(int i = 0; i < packages_available - sec_count; i++) + for (int i = 0; i < packages_available - sec_count; i++) printf("%s\n", packages_list[i]); } } @@ -155,34 +148,33 @@ int main (int argc, char **argv) { } /* process command-line arguments */ -int process_arguments (int argc, char **argv) { +int process_arguments(int argc, char **argv) { int c; - static struct option longopts[] = { - {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, - {"verbose", no_argument, 0, 'v'}, - {"timeout", required_argument, 0, 't'}, - {"update", optional_argument, 0, 'u'}, - {"upgrade", optional_argument, 0, 'U'}, - {"no-upgrade", no_argument, 0, 'n'}, - {"dist-upgrade", optional_argument, 0, 'd'}, - {"list", no_argument, false, 'l'}, - {"include", required_argument, 0, 'i'}, - {"exclude", required_argument, 0, 'e'}, - {"critical", required_argument, 0, 'c'}, - {"only-critical", no_argument, 0, 'o'}, - {"input-file", required_argument, 0, INPUT_FILE_OPT}, - {"packages-warning", required_argument, 0, 'w'}, - {0, 0, 0, 0} - }; - - while(1) { + static struct option longopts[] = {{"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {"verbose", no_argument, 0, 'v'}, + {"timeout", required_argument, 0, 't'}, + {"update", optional_argument, 0, 'u'}, + {"upgrade", optional_argument, 0, 'U'}, + {"no-upgrade", no_argument, 0, 'n'}, + {"dist-upgrade", optional_argument, 0, 'd'}, + {"list", no_argument, false, 'l'}, + {"include", required_argument, 0, 'i'}, + {"exclude", required_argument, 0, 'e'}, + {"critical", required_argument, 0, 'c'}, + {"only-critical", no_argument, 0, 'o'}, + {"input-file", required_argument, 0, INPUT_FILE_OPT}, + {"packages-warning", required_argument, 0, 'w'}, + {0, 0, 0, 0}}; + + while (1) { c = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); - if(c == -1 || c == EOF || c == 1) break; + if (c == -1 || c == EOF || c == 1) + break; - switch(c) { + switch (c) { case 'h': print_help(); exit(STATE_UNKNOWN); @@ -193,46 +185,49 @@ int process_arguments (int argc, char **argv) { verbose++; break; case 't': - timeout_interval=atoi(optarg); + timeout_interval = atoi(optarg); break; case 'd': - upgrade=DIST_UPGRADE; - if(optarg!=NULL){ - upgrade_opts=strdup(optarg); - if(upgrade_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); + upgrade = DIST_UPGRADE; + if (optarg != NULL) { + upgrade_opts = strdup(optarg); + if (upgrade_opts == NULL) + die(STATE_UNKNOWN, "strdup failed"); } break; case 'U': - upgrade=UPGRADE; - if(optarg!=NULL){ - upgrade_opts=strdup(optarg); - if(upgrade_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); + upgrade = UPGRADE; + if (optarg != NULL) { + upgrade_opts = strdup(optarg); + if (upgrade_opts == NULL) + die(STATE_UNKNOWN, "strdup failed"); } break; case 'n': - upgrade=NO_UPGRADE; + upgrade = NO_UPGRADE; break; case 'u': - do_update=true; - if(optarg!=NULL){ - update_opts=strdup(optarg); - if(update_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); + do_update = true; + if (optarg != NULL) { + update_opts = strdup(optarg); + if (update_opts == NULL) + die(STATE_UNKNOWN, "strdup failed"); } break; case 'l': - list=true; + list = true; break; case 'i': - do_include=add_to_regexp(do_include, optarg); + do_include = add_to_regexp(do_include, optarg); break; case 'e': - do_exclude=add_to_regexp(do_exclude, optarg); + do_exclude = add_to_regexp(do_exclude, optarg); break; case 'c': - do_critical=add_to_regexp(do_critical, optarg); + do_critical = add_to_regexp(do_critical, optarg); break; case 'o': - only_critical=true; + only_critical = true; break; case INPUT_FILE_OPT: input_filename = optarg; @@ -249,46 +244,44 @@ int process_arguments (int argc, char **argv) { return OK; } - /* run an apt-get upgrade */ -int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){ - int result=STATE_UNKNOWN, regres=0, pc=0, spc=0; +int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist) { + int result = STATE_UNKNOWN, regres = 0, pc = 0, spc = 0; struct output chld_out, chld_err; regex_t ireg, ereg, sreg; - char *cmdline=NULL, rerrbuf[64]; + char *cmdline = NULL, rerrbuf[64]; /* initialize ereg as it is possible it is printed while uninitialized */ memset(&ereg, '\0', sizeof(ereg.buffer)); - if(upgrade==NO_UPGRADE) return STATE_OK; + if (upgrade == NO_UPGRADE) + return STATE_OK; /* compile the regexps */ if (do_include != NULL) { - regres=regcomp(&ireg, do_include, REG_EXTENDED); - if (regres!=0) { + regres = regcomp(&ireg, do_include, REG_EXTENDED); + if (regres != 0) { regerror(regres, &ireg, rerrbuf, 64); die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); } } - if(do_exclude!=NULL){ - regres=regcomp(&ereg, do_exclude, REG_EXTENDED); - if(regres!=0) { + if (do_exclude != NULL) { + regres = regcomp(&ereg, do_exclude, REG_EXTENDED); + if (regres != 0) { regerror(regres, &ereg, rerrbuf, 64); - die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), - progname, rerrbuf); + die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); } } const char *crit_ptr = (do_critical != NULL) ? do_critical : SECURITY_RE; - regres=regcomp(&sreg, crit_ptr, REG_EXTENDED); - if(regres!=0) { + regres = regcomp(&sreg, crit_ptr, REG_EXTENDED); + if (regres != 0) { regerror(regres, &ereg, rerrbuf, 64); - die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), - progname, rerrbuf); + die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); } - cmdline=construct_cmdline(upgrade, upgrade_opts); + cmdline = construct_cmdline(upgrade, upgrade_opts); if (input_filename != NULL) { /* read input from a file for testing */ result = cmd_file_read(input_filename, &chld_out, 0); @@ -300,17 +293,18 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg /* apt-get upgrade only changes exit status if there is an * internal error when run in dry-run mode. therefore we will * treat such an error as UNKNOWN */ - if(result != 0){ - exec_warning=1; + if (result != 0) { + exec_warning = 1; result = STATE_UNKNOWN; - fprintf(stderr, _("'%s' exited with non-zero status.\n"), - cmdline); + fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline); } - *pkglist=malloc(sizeof(char *) * chld_out.lines); - if(!pkglist) die(STATE_UNKNOWN, "malloc failed!\n"); - *secpkglist=malloc(sizeof(char *) * chld_out.lines); - if(!secpkglist) die(STATE_UNKNOWN, "malloc failed!\n"); + *pkglist = malloc(sizeof(char *) * chld_out.lines); + if (!pkglist) + die(STATE_UNKNOWN, "malloc failed!\n"); + *secpkglist = malloc(sizeof(char *) * chld_out.lines); + if (!secpkglist) + die(STATE_UNKNOWN, "malloc failed!\n"); /* parse the output, which should only consist of lines like * @@ -321,54 +315,56 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg * we may need to switch to the --print-uris output format, * in which case the logic here will slightly change. */ - for(size_t i = 0; i < chld_out.lines; i++) { - if(verbose){ + for (size_t i = 0; i < chld_out.lines; i++) { + if (verbose) { printf("%s\n", chld_out.line[i]); } /* if it is a package we care about */ if (strncmp(PKGINST_PREFIX, chld_out.line[i], strlen(PKGINST_PREFIX)) == 0 && - (do_include == NULL || regexec(&ireg, chld_out.line[i], 0, NULL, 0) == 0)) { + (do_include == NULL || regexec(&ireg, chld_out.line[i], 0, NULL, 0) == 0)) { /* if we're not excluding, or it's not in the * list of stuff to exclude */ - if(do_exclude==NULL || - regexec(&ereg, chld_out.line[i], 0, NULL, 0)!=0){ + if (do_exclude == NULL || regexec(&ereg, chld_out.line[i], 0, NULL, 0) != 0) { pc++; - if(regexec(&sreg, chld_out.line[i], 0, NULL, 0)==0){ + if (regexec(&sreg, chld_out.line[i], 0, NULL, 0) == 0) { spc++; - if(verbose) printf("*"); - (*secpkglist)[spc-1] = pkg_name(chld_out.line[i]); + if (verbose) + printf("*"); + (*secpkglist)[spc - 1] = pkg_name(chld_out.line[i]); } else { - (*pkglist)[pc-spc-1] = pkg_name(chld_out.line[i]); + (*pkglist)[pc - spc - 1] = pkg_name(chld_out.line[i]); } - if(verbose){ + if (verbose) { printf("*%s\n", chld_out.line[i]); } } } } - *pkgcount=pc; - *secpkgcount=spc; + *pkgcount = pc; + *secpkgcount = spc; /* If we get anything on stderr, at least set warning */ if (input_filename == NULL && chld_err.buflen) { - stderr_warning=1; + stderr_warning = 1; result = max_state(result, STATE_WARNING); - if(verbose){ - for(size_t i = 0; i < chld_err.lines; i++) { + if (verbose) { + for (size_t i = 0; i < chld_err.lines; i++) { fprintf(stderr, "%s\n", chld_err.line[i]); } } } - if (do_include != NULL) regfree(&ireg); + if (do_include != NULL) + regfree(&ireg); regfree(&sreg); - if(do_exclude!=NULL) regfree(&ereg); + if (do_exclude != NULL) + regfree(&ereg); free(cmdline); return result; } /* run an apt-get update (needs root) */ -int run_update(void){ - int result=STATE_UNKNOWN; +int run_update(void) { + int result = STATE_UNKNOWN; struct output chld_out, chld_err; char *cmdline; @@ -378,25 +374,24 @@ int run_update(void){ /* apt-get update changes exit status if it can't fetch packages. * since we were explicitly asked to do so, this is treated as * a critical error. */ - if(result != 0){ - exec_warning=1; + if (result != 0) { + exec_warning = 1; result = STATE_CRITICAL; - fprintf(stderr, _("'%s' exited with non-zero status.\n"), - cmdline); + fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline); } - if(verbose){ - for(size_t i = 0; i < chld_out.lines; i++) { + if (verbose) { + for (size_t i = 0; i < chld_out.lines; i++) { printf("%s\n", chld_out.line[i]); } } /* If we get anything on stderr, at least set warning */ - if(chld_err.buflen){ - stderr_warning=1; + if (chld_err.buflen) { + stderr_warning = 1; result = max_state(result, STATE_WARNING); - if(verbose){ - for(size_t i = 0; i < chld_err.lines; i++) { + if (verbose) { + for (size_t i = 0; i < chld_err.lines; i++) { fprintf(stderr, "%s\n", chld_err.line[i]); } } @@ -405,158 +400,161 @@ int run_update(void){ return result; } -char* pkg_name(char *line){ - char *start=NULL, *space=NULL, *pkg=NULL; - int len=0; +char *pkg_name(char *line) { + char *start = NULL, *space = NULL, *pkg = NULL; + int len = 0; start = line + strlen(PKGINST_PREFIX); len = strlen(start); space = index(start, ' '); - if(space!=NULL){ + if (space != NULL) { len = space - start; } - pkg=malloc(sizeof(char)*(len+1)); - if(!pkg) die(STATE_UNKNOWN, "malloc failed!\n"); + pkg = malloc(sizeof(char) * (len + 1)); + if (!pkg) + die(STATE_UNKNOWN, "malloc failed!\n"); strncpy(pkg, start, len); - pkg[len]='\0'; + pkg[len] = '\0'; return pkg; } -int cmpstringp(const void *p1, const void *p2){ - return strcmp(* (char * const *) p1, * (char * const *) p2); -} +int cmpstringp(const void *p1, const void *p2) { return strcmp(*(char *const *)p1, *(char *const *)p2); } -char* add_to_regexp(char *expr, const char *next){ - char *re=NULL; +char *add_to_regexp(char *expr, const char *next) { + char *re = NULL; - if(expr==NULL){ - re=malloc(sizeof(char)*(strlen("()")+strlen(next)+1)); - if(!re) die(STATE_UNKNOWN, "malloc failed!\n"); + if (expr == NULL) { + re = malloc(sizeof(char) * (strlen("()") + strlen(next) + 1)); + if (!re) + die(STATE_UNKNOWN, "malloc failed!\n"); sprintf(re, "(%s)", next); } else { /* resize it, adding an extra char for the new '|' separator */ - re=realloc(expr, sizeof(char)*(strlen(expr)+1+strlen(next)+1)); - if(!re) die(STATE_UNKNOWN, "realloc failed!\n"); + re = realloc(expr, sizeof(char) * (strlen(expr) + 1 + strlen(next) + 1)); + if (!re) + die(STATE_UNKNOWN, "realloc failed!\n"); /* append it starting at ')' in the old re */ - sprintf((char*)(re+strlen(re)-1), "|%s)", next); + sprintf((char *)(re + strlen(re) - 1), "|%s)", next); } return re; } -char* construct_cmdline(upgrade_type u, const char *opts){ - int len=0; - const char *opts_ptr=NULL, *aptcmd=NULL; - char *cmd=NULL; +char *construct_cmdline(upgrade_type u, const char *opts) { + int len = 0; + const char *opts_ptr = NULL, *aptcmd = NULL; + char *cmd = NULL; - switch(u){ + switch (u) { case UPGRADE: - if(opts==NULL) opts_ptr=UPGRADE_DEFAULT_OPTS; - else opts_ptr=opts; - aptcmd="upgrade"; + if (opts == NULL) + opts_ptr = UPGRADE_DEFAULT_OPTS; + else + opts_ptr = opts; + aptcmd = "upgrade"; break; case DIST_UPGRADE: - if(opts==NULL) opts_ptr=UPGRADE_DEFAULT_OPTS; - else opts_ptr=opts; - aptcmd="dist-upgrade"; + if (opts == NULL) + opts_ptr = UPGRADE_DEFAULT_OPTS; + else + opts_ptr = opts; + aptcmd = "dist-upgrade"; break; case NO_UPGRADE: - if(opts==NULL) opts_ptr=UPDATE_DEFAULT_OPTS; - else opts_ptr=opts; - aptcmd="update"; + if (opts == NULL) + opts_ptr = UPDATE_DEFAULT_OPTS; + else + opts_ptr = opts; + aptcmd = "update"; break; } - len+=strlen(PATH_TO_APTGET)+1; /* "/usr/bin/apt-get " */ - len+=strlen(opts_ptr)+1; /* "opts " */ - len+=strlen(aptcmd)+1; /* "upgrade\0" */ + len += strlen(PATH_TO_APTGET) + 1; /* "/usr/bin/apt-get " */ + len += strlen(opts_ptr) + 1; /* "opts " */ + len += strlen(aptcmd) + 1; /* "upgrade\0" */ - cmd=(char*)malloc(sizeof(char)*len); - if(cmd==NULL) die(STATE_UNKNOWN, "malloc failed"); + cmd = (char *)malloc(sizeof(char) * len); + if (cmd == NULL) + die(STATE_UNKNOWN, "malloc failed"); sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd); return cmd; } /* informative help message */ -void -print_help (void) -{ - print_revision(progname, NP_VERSION); - - printf(_(COPYRIGHT), copyright, email); - - printf("%s\n", _("This plugin checks for software updates on systems that use")); - printf("%s\n", _("package management systems based on the apt-get(8) command")); - printf("%s\n", _("found in Debian GNU/Linux")); - - printf ("\n\n"); - - print_usage(); - - printf(UT_HELP_VRSN); - printf(UT_EXTRA_OPTS); - - printf(UT_PLUG_TIMEOUT, timeout_interval); - - printf (" %s\n", "-n, --no-upgrade"); - printf (" %s\n", _("Do not run the upgrade. Probably not useful (without -u at least).")); - printf (" %s\n", "-l, --list"); - printf (" %s\n", _("List packages available for upgrade. Packages are printed sorted by")); - printf (" %s\n", _("name with security packages listed first.")); - printf (" %s\n", "-i, --include=REGEXP"); - printf (" %s\n", _("Include only packages matching REGEXP. Can be specified multiple times")); - printf (" %s\n", _("the values will be combined together. Any packages matching this list")); - printf (" %s\n", _("cause the plugin to return WARNING status. Others will be ignored.")); - printf (" %s\n", _("Default is to include all packages.")); - printf (" %s\n", "-e, --exclude=REGEXP"); - printf (" %s\n", _("Exclude packages matching REGEXP from the list of packages that would")); - printf (" %s\n", _("otherwise be included. Can be specified multiple times; the values")); - printf (" %s\n", _("will be combined together. Default is to exclude no packages.")); - printf (" %s\n", "-c, --critical=REGEXP"); - printf (" %s\n", _("If the full package information of any of the upgradable packages match")); - printf (" %s\n", _("this REGEXP, the plugin will return CRITICAL status. Can be specified")); - printf (" %s\n", _("multiple times like above. Default is a regexp matching security")); - printf (" %s\n", _("upgrades for Debian and Ubuntu:")); - printf (" \t%s\n", SECURITY_RE); - printf (" %s\n", _("Note that the package must first match the include list before its")); - printf (" %s\n", _("information is compared against the critical list.")); - printf (" %s\n", "-o, --only-critical"); - printf (" %s\n", _("Only warn about upgrades matching the critical list. The total number")); - printf (" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause")); - printf (" %s\n", _("the plugin to return WARNING status.")); - printf (" %s\n", "-w, --packages-warning"); - printf (" %s\n", _("Minimum number of packages available for upgrade to return WARNING status.")); - printf (" %s\n\n", _("Default is 1 package.")); - - printf ("%s\n\n", _("The following options require root privileges and should be used with care:")); - printf (" %s\n", "-u, --update=OPTS"); - printf (" %s\n", _("First perform an 'apt-get update'. An optional OPTS parameter overrides")); - printf (" %s\n", _("the default options. Note: you may also need to adjust the global")); - printf (" %s\n", _("timeout (with -t) to prevent the plugin from timing out if apt-get")); - printf (" %s\n", _("upgrade is expected to take longer than the default timeout.")); - printf (" %s\n", "-U, --upgrade=OPTS"); - printf (" %s\n", _("Perform an upgrade. If an optional OPTS argument is provided,")); - printf (" %s\n", _("apt-get will be run with these command line options instead of the")); - printf (" %s", _("default ")); - printf ("(%s).\n", UPGRADE_DEFAULT_OPTS); - printf (" %s\n", _("Note that you may be required to have root privileges if you do not use")); - printf (" %s\n", _("the default options, which will only run a simulation and NOT perform the upgrade")); - printf (" %s\n", "-d, --dist-upgrade=OPTS"); - printf (" %s\n", _("Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS")); - printf (" %s\n", _("can be provided to override the default options.")); - - printf(UT_SUPPORT); +void print_help(void) { + print_revision(progname, NP_VERSION); + + printf(_(COPYRIGHT), copyright, email); + + printf("%s\n", _("This plugin checks for software updates on systems that use")); + printf("%s\n", _("package management systems based on the apt-get(8) command")); + printf("%s\n", _("found in Debian GNU/Linux")); + + printf("\n\n"); + + print_usage(); + + printf(UT_HELP_VRSN); + printf(UT_EXTRA_OPTS); + + printf(UT_PLUG_TIMEOUT, timeout_interval); + + printf(" %s\n", "-n, --no-upgrade"); + printf(" %s\n", _("Do not run the upgrade. Probably not useful (without -u at least).")); + printf(" %s\n", "-l, --list"); + printf(" %s\n", _("List packages available for upgrade. Packages are printed sorted by")); + printf(" %s\n", _("name with security packages listed first.")); + printf(" %s\n", "-i, --include=REGEXP"); + printf(" %s\n", _("Include only packages matching REGEXP. Can be specified multiple times")); + printf(" %s\n", _("the values will be combined together. Any packages matching this list")); + printf(" %s\n", _("cause the plugin to return WARNING status. Others will be ignored.")); + printf(" %s\n", _("Default is to include all packages.")); + printf(" %s\n", "-e, --exclude=REGEXP"); + printf(" %s\n", _("Exclude packages matching REGEXP from the list of packages that would")); + printf(" %s\n", _("otherwise be included. Can be specified multiple times; the values")); + printf(" %s\n", _("will be combined together. Default is to exclude no packages.")); + printf(" %s\n", "-c, --critical=REGEXP"); + printf(" %s\n", _("If the full package information of any of the upgradable packages match")); + printf(" %s\n", _("this REGEXP, the plugin will return CRITICAL status. Can be specified")); + printf(" %s\n", _("multiple times like above. Default is a regexp matching security")); + printf(" %s\n", _("upgrades for Debian and Ubuntu:")); + printf(" \t%s\n", SECURITY_RE); + printf(" %s\n", _("Note that the package must first match the include list before its")); + printf(" %s\n", _("information is compared against the critical list.")); + printf(" %s\n", "-o, --only-critical"); + printf(" %s\n", _("Only warn about upgrades matching the critical list. The total number")); + printf(" %s\n", _("of upgrades will be printed, but any non-critical upgrades will not cause")); + printf(" %s\n", _("the plugin to return WARNING status.")); + printf(" %s\n", "-w, --packages-warning"); + printf(" %s\n", _("Minimum number of packages available for upgrade to return WARNING status.")); + printf(" %s\n\n", _("Default is 1 package.")); + + printf("%s\n\n", _("The following options require root privileges and should be used with care:")); + printf(" %s\n", "-u, --update=OPTS"); + printf(" %s\n", _("First perform an 'apt-get update'. An optional OPTS parameter overrides")); + printf(" %s\n", _("the default options. Note: you may also need to adjust the global")); + printf(" %s\n", _("timeout (with -t) to prevent the plugin from timing out if apt-get")); + printf(" %s\n", _("upgrade is expected to take longer than the default timeout.")); + printf(" %s\n", "-U, --upgrade=OPTS"); + printf(" %s\n", _("Perform an upgrade. If an optional OPTS argument is provided,")); + printf(" %s\n", _("apt-get will be run with these command line options instead of the")); + printf(" %s", _("default ")); + printf("(%s).\n", UPGRADE_DEFAULT_OPTS); + printf(" %s\n", _("Note that you may be required to have root privileges if you do not use")); + printf(" %s\n", _("the default options, which will only run a simulation and NOT perform the upgrade")); + printf(" %s\n", "-d, --dist-upgrade=OPTS"); + printf(" %s\n", _("Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS")); + printf(" %s\n", _("can be provided to override the default options.")); + + printf(UT_SUPPORT); } - /* simple usage heading */ -void -print_usage(void) -{ - printf ("%s\n", _("Usage:")); - printf ("%s [[-d|-u|-U]opts] [-n] [-l] [-t timeout] [-w packages-warning]\n", progname); +void print_usage(void) { + printf("%s\n", _("Usage:")); + printf("%s [[-d|-u|-U]opts] [-n] [-l] [-t timeout] [-w packages-warning]\n", progname); } -- cgit v1.2.3-74-g34f1 From d7671b8a4a8f7a46f5576be7d6d6644c9cd77000 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 26 Oct 2024 22:52:23 +0200 Subject: check_apt: mindless linter fixes --- plugins/check_apt.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'plugins') diff --git a/plugins/check_apt.c b/plugins/check_apt.c index 02af1a43..16c34caf 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -57,7 +57,7 @@ typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; #define SECURITY_RE "^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" /* some standard functions */ -int process_arguments(int, char **); +int process_arguments(int /*argc*/, char ** /*argv*/); void print_help(void); void print_usage(void); @@ -94,8 +94,11 @@ static int stderr_warning = 0; /* if a cmd issued output on stderr */ static int exec_warning = 0; /* if a cmd exited non-zero */ int main(int argc, char **argv) { - int result = STATE_UNKNOWN, packages_available = 0, sec_count = 0; - char **packages_list = NULL, **secpackages_list = NULL; + int result = STATE_UNKNOWN; + int packages_available = 0; + int sec_count = 0; + char **packages_list = NULL; + char **secpackages_list = NULL; /* Parse extra opts if any */ argv = np_extra_opts(&argc, argv, progname); @@ -246,10 +249,17 @@ int process_arguments(int argc, char **argv) { /* run an apt-get upgrade */ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist) { - int result = STATE_UNKNOWN, regres = 0, pc = 0, spc = 0; - struct output chld_out, chld_err; - regex_t ireg, ereg, sreg; - char *cmdline = NULL, rerrbuf[64]; + int result = STATE_UNKNOWN; + int regres = 0; + int pc = 0; + int spc = 0; + struct output chld_out; + struct output chld_err; + regex_t ireg; + regex_t ereg; + regex_t sreg; + char *cmdline = NULL; + char rerrbuf[64]; /* initialize ereg as it is possible it is printed while uninitialized */ memset(&ereg, '\0', sizeof(ereg.buffer)); @@ -365,7 +375,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg /* run an apt-get update (needs root) */ int run_update(void) { int result = STATE_UNKNOWN; - struct output chld_out, chld_err; + struct output chld_out; + struct output chld_err; char *cmdline; /* run the update */ @@ -401,7 +412,9 @@ int run_update(void) { } char *pkg_name(char *line) { - char *start = NULL, *space = NULL, *pkg = NULL; + char *start = NULL; + char *space = NULL; + char *pkg = NULL; int len = 0; start = line + strlen(PKGINST_PREFIX); @@ -446,7 +459,8 @@ char *add_to_regexp(char *expr, const char *next) { char *construct_cmdline(upgrade_type u, const char *opts) { int len = 0; - const char *opts_ptr = NULL, *aptcmd = NULL; + const char *opts_ptr = NULL; + const char *aptcmd = NULL; char *cmd = NULL; switch (u) { -- cgit v1.2.3-74-g34f1 From b43e913b2c2a380ef59ed3046cac1f0f92b65a9d Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 26 Oct 2024 22:54:15 +0200 Subject: clang-format: always add braces --- .clang-format | 1 + plugins/check_apt.c | 69 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 24 deletions(-) (limited to 'plugins') diff --git a/.clang-format b/.clang-format index 877a53b9..ca411edd 100644 --- a/.clang-format +++ b/.clang-format @@ -9,3 +9,4 @@ IndentPPDirectives: AfterHash SortIncludes: Never AllowShortEnumsOnASingleLine: false BinPackArguments: true +InsertBraces: true diff --git a/plugins/check_apt.c b/plugins/check_apt.c index 16c34caf..288d37cb 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -103,8 +103,9 @@ int main(int argc, char **argv) { /* Parse extra opts if any */ argv = np_extra_opts(&argc, argv, progname); - if (process_arguments(argc, argv) == ERROR) + if (process_arguments(argc, argv) == ERROR) { usage_va(_("Could not parse arguments")); + } /* Set signal handling and alarm timeout */ if (signal(SIGALRM, timeout_alarm_handler) == SIG_ERR) { @@ -115,8 +116,9 @@ int main(int argc, char **argv) { alarm(timeout_interval); /* if they want to run apt-get update first... */ - if (do_update) + if (do_update) { result = run_update(); + } /* apt-get upgrade */ result = max_state(result, run_upgrade(&packages_available, &sec_count, &packages_list, &secpackages_list)); @@ -138,12 +140,14 @@ int main(int argc, char **argv) { qsort(secpackages_list, sec_count, sizeof(char *), cmpstringp); qsort(packages_list, packages_available - sec_count, sizeof(char *), cmpstringp); - for (int i = 0; i < sec_count; i++) + for (int i = 0; i < sec_count; i++) { printf("%s (security)\n", secpackages_list[i]); + } if (only_critical == false) { - for (int i = 0; i < packages_available - sec_count; i++) + for (int i = 0; i < packages_available - sec_count; i++) { printf("%s\n", packages_list[i]); + } } } @@ -174,8 +178,9 @@ int process_arguments(int argc, char **argv) { while (1) { c = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); - if (c == -1 || c == EOF || c == 1) + if (c == -1 || c == EOF || c == 1) { break; + } switch (c) { case 'h': @@ -194,16 +199,18 @@ int process_arguments(int argc, char **argv) { upgrade = DIST_UPGRADE; if (optarg != NULL) { upgrade_opts = strdup(optarg); - if (upgrade_opts == NULL) + if (upgrade_opts == NULL) { die(STATE_UNKNOWN, "strdup failed"); + } } break; case 'U': upgrade = UPGRADE; if (optarg != NULL) { upgrade_opts = strdup(optarg); - if (upgrade_opts == NULL) + if (upgrade_opts == NULL) { die(STATE_UNKNOWN, "strdup failed"); + } } break; case 'n': @@ -213,8 +220,9 @@ int process_arguments(int argc, char **argv) { do_update = true; if (optarg != NULL) { update_opts = strdup(optarg); - if (update_opts == NULL) + if (update_opts == NULL) { die(STATE_UNKNOWN, "strdup failed"); + } } break; case 'l': @@ -264,8 +272,9 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg /* initialize ereg as it is possible it is printed while uninitialized */ memset(&ereg, '\0', sizeof(ereg.buffer)); - if (upgrade == NO_UPGRADE) + if (upgrade == NO_UPGRADE) { return STATE_OK; + } /* compile the regexps */ if (do_include != NULL) { @@ -310,11 +319,13 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg } *pkglist = malloc(sizeof(char *) * chld_out.lines); - if (!pkglist) + if (!pkglist) { die(STATE_UNKNOWN, "malloc failed!\n"); + } *secpkglist = malloc(sizeof(char *) * chld_out.lines); - if (!secpkglist) + if (!secpkglist) { die(STATE_UNKNOWN, "malloc failed!\n"); + } /* parse the output, which should only consist of lines like * @@ -338,8 +349,9 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg pc++; if (regexec(&sreg, chld_out.line[i], 0, NULL, 0) == 0) { spc++; - if (verbose) + if (verbose) { printf("*"); + } (*secpkglist)[spc - 1] = pkg_name(chld_out.line[i]); } else { (*pkglist)[pc - spc - 1] = pkg_name(chld_out.line[i]); @@ -363,11 +375,13 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg } } } - if (do_include != NULL) + if (do_include != NULL) { regfree(&ireg); + } regfree(&sreg); - if (do_exclude != NULL) + if (do_exclude != NULL) { regfree(&ereg); + } free(cmdline); return result; } @@ -426,8 +440,9 @@ char *pkg_name(char *line) { } pkg = malloc(sizeof(char) * (len + 1)); - if (!pkg) + if (!pkg) { die(STATE_UNKNOWN, "malloc failed!\n"); + } strncpy(pkg, start, len); pkg[len] = '\0'; @@ -442,14 +457,16 @@ char *add_to_regexp(char *expr, const char *next) { if (expr == NULL) { re = malloc(sizeof(char) * (strlen("()") + strlen(next) + 1)); - if (!re) + if (!re) { die(STATE_UNKNOWN, "malloc failed!\n"); + } sprintf(re, "(%s)", next); } else { /* resize it, adding an extra char for the new '|' separator */ re = realloc(expr, sizeof(char) * (strlen(expr) + 1 + strlen(next) + 1)); - if (!re) + if (!re) { die(STATE_UNKNOWN, "realloc failed!\n"); + } /* append it starting at ')' in the old re */ sprintf((char *)(re + strlen(re) - 1), "|%s)", next); } @@ -465,24 +482,27 @@ char *construct_cmdline(upgrade_type u, const char *opts) { switch (u) { case UPGRADE: - if (opts == NULL) + if (opts == NULL) { opts_ptr = UPGRADE_DEFAULT_OPTS; - else + } else { opts_ptr = opts; + } aptcmd = "upgrade"; break; case DIST_UPGRADE: - if (opts == NULL) + if (opts == NULL) { opts_ptr = UPGRADE_DEFAULT_OPTS; - else + } else { opts_ptr = opts; + } aptcmd = "dist-upgrade"; break; case NO_UPGRADE: - if (opts == NULL) + if (opts == NULL) { opts_ptr = UPDATE_DEFAULT_OPTS; - else + } else { opts_ptr = opts; + } aptcmd = "update"; break; } @@ -492,8 +512,9 @@ char *construct_cmdline(upgrade_type u, const char *opts) { len += strlen(aptcmd) + 1; /* "upgrade\0" */ cmd = (char *)malloc(sizeof(char) * len); - if (cmd == NULL) + if (cmd == NULL) { die(STATE_UNKNOWN, "malloc failed"); + } sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd); return cmd; } -- cgit v1.2.3-74-g34f1 From ebb4bf4bb4c14807878dab488a66868f7f5751e3 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 26 Oct 2024 22:57:58 +0200 Subject: check_apt: declare local functions static --- plugins/check_apt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'plugins') diff --git a/plugins/check_apt.c b/plugins/check_apt.c index 288d37cb..eb08a061 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -57,22 +57,22 @@ typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; #define SECURITY_RE "^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" /* some standard functions */ -int process_arguments(int /*argc*/, char ** /*argv*/); -void print_help(void); +static int process_arguments(int /*argc*/, char ** /*argv*/); +static void print_help(void); void print_usage(void); /* construct the appropriate apt-get cmdline */ -char *construct_cmdline(upgrade_type u, const char *opts); +static char *construct_cmdline(upgrade_type u, const char *opts); /* run an apt-get update */ -int run_update(void); +static int run_update(void); /* run an apt-get upgrade */ -int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist); +static int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist); /* add another clause to a regexp */ -char *add_to_regexp(char *expr, const char *next); +static char *add_to_regexp(char *expr, const char *next); /* extract package name from Inst line */ -char *pkg_name(char *line); +static char *pkg_name(char *line); /* string comparison function for qsort */ -int cmpstringp(const void *p1, const void *p2); +static int cmpstringp(const void *p1, const void *p2); /* configuration variables */ static int verbose = 0; /* -v */ -- cgit v1.2.3-74-g34f1 From 75ff5b3b51a76081196f41c4b428dc3db50f2664 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:18:26 +0200 Subject: check_apt: localize variables --- plugins/check_apt.c | 65 +++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 37 deletions(-) (limited to 'plugins') diff --git a/plugins/check_apt.c b/plugins/check_apt.c index eb08a061..c2c693eb 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -94,12 +94,6 @@ static int stderr_warning = 0; /* if a cmd issued output on stderr */ static int exec_warning = 0; /* if a cmd exited non-zero */ int main(int argc, char **argv) { - int result = STATE_UNKNOWN; - int packages_available = 0; - int sec_count = 0; - char **packages_list = NULL; - char **secpackages_list = NULL; - /* Parse extra opts if any */ argv = np_extra_opts(&argc, argv, progname); @@ -115,11 +109,16 @@ int main(int argc, char **argv) { /* handle timeouts gracefully... */ alarm(timeout_interval); + int result = STATE_UNKNOWN; /* if they want to run apt-get update first... */ if (do_update) { result = run_update(); } + int packages_available = 0; + int sec_count = 0; + char **packages_list = NULL; + char **secpackages_list = NULL; /* apt-get upgrade */ result = max_state(result, run_upgrade(&packages_available, &sec_count, &packages_list, &secpackages_list)); @@ -156,8 +155,6 @@ int main(int argc, char **argv) { /* process command-line arguments */ int process_arguments(int argc, char **argv) { - int c; - static struct option longopts[] = {{"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, @@ -175,14 +172,14 @@ int process_arguments(int argc, char **argv) { {"packages-warning", required_argument, 0, 'w'}, {0, 0, 0, 0}}; - while (1) { - c = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); + while (true) { + int option_char = getopt_long(argc, argv, "hVvt:u::U::d::nli:e:c:ow:", longopts, NULL); - if (c == -1 || c == EOF || c == 1) { + if (option_char == -1 || option_char == EOF || option_char == 1) { break; } - switch (c) { + switch (option_char) { case 'h': print_help(); exit(STATE_UNKNOWN); @@ -257,18 +254,7 @@ int process_arguments(int argc, char **argv) { /* run an apt-get upgrade */ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist) { - int result = STATE_UNKNOWN; - int regres = 0; - int pc = 0; - int spc = 0; - struct output chld_out; - struct output chld_err; - regex_t ireg; regex_t ereg; - regex_t sreg; - char *cmdline = NULL; - char rerrbuf[64]; - /* initialize ereg as it is possible it is printed while uninitialized */ memset(&ereg, '\0', sizeof(ereg.buffer)); @@ -276,6 +262,9 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg return STATE_OK; } + int regres = 0; + regex_t ireg; + char rerrbuf[64]; /* compile the regexps */ if (do_include != NULL) { regres = regcomp(&ireg, do_include, REG_EXTENDED); @@ -293,6 +282,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg } } + regex_t sreg; const char *crit_ptr = (do_critical != NULL) ? do_critical : SECURITY_RE; regres = regcomp(&sreg, crit_ptr, REG_EXTENDED); if (regres != 0) { @@ -300,6 +290,10 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); } + int result = STATE_UNKNOWN; + struct output chld_out; + struct output chld_err; + char *cmdline = NULL; cmdline = construct_cmdline(upgrade, upgrade_opts); if (input_filename != NULL) { /* read input from a file for testing */ @@ -336,6 +330,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg * we may need to switch to the --print-uris output format, * in which case the logic here will slightly change. */ + int pc = 0; + int spc = 0; for (size_t i = 0; i < chld_out.lines; i++) { if (verbose) { printf("%s\n", chld_out.line[i]); @@ -389,12 +385,12 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg /* run an apt-get update (needs root) */ int run_update(void) { int result = STATE_UNKNOWN; - struct output chld_out; - struct output chld_err; char *cmdline; - /* run the update */ cmdline = construct_cmdline(NO_UPGRADE, update_opts); + + struct output chld_out; + struct output chld_err; result = np_runcmd(cmdline, &chld_out, &chld_err, 0); /* apt-get update changes exit status if it can't fetch packages. * since we were explicitly asked to do so, this is treated as @@ -426,20 +422,16 @@ int run_update(void) { } char *pkg_name(char *line) { - char *start = NULL; - char *space = NULL; - char *pkg = NULL; - int len = 0; + char *start = line + strlen(PKGINST_PREFIX); - start = line + strlen(PKGINST_PREFIX); - len = strlen(start); + int len = strlen(start); - space = index(start, ' '); + char *space = index(start, ' '); if (space != NULL) { len = space - start; } - pkg = malloc(sizeof(char) * (len + 1)); + char *pkg = malloc(sizeof(char) * (len + 1)); if (!pkg) { die(STATE_UNKNOWN, "malloc failed!\n"); } @@ -475,10 +467,8 @@ char *add_to_regexp(char *expr, const char *next) { } char *construct_cmdline(upgrade_type u, const char *opts) { - int len = 0; const char *opts_ptr = NULL; const char *aptcmd = NULL; - char *cmd = NULL; switch (u) { case UPGRADE: @@ -507,11 +497,12 @@ char *construct_cmdline(upgrade_type u, const char *opts) { break; } + int len = 0; len += strlen(PATH_TO_APTGET) + 1; /* "/usr/bin/apt-get " */ len += strlen(opts_ptr) + 1; /* "opts " */ len += strlen(aptcmd) + 1; /* "upgrade\0" */ - cmd = (char *)malloc(sizeof(char) * len); + char *cmd = (char *)malloc(sizeof(char) * len); if (cmd == NULL) { die(STATE_UNKNOWN, "malloc failed"); } -- cgit v1.2.3-74-g34f1 From 540d609d845869a5c826f8190bdfed47db1e4259 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:50:22 +0100 Subject: check_apt: clang-format --- plugins/check_apt.c | 64 ++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) (limited to 'plugins') diff --git a/plugins/check_apt.c b/plugins/check_apt.c index c2c693eb..ac89f816 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -1,33 +1,33 @@ /***************************************************************************** -* -* Monitoring check_apt plugin -* -* License: GPL -* Copyright (c) 2006-2024 Monitoring Plugins Development Team -* -* Original author: Sean Finney -* -* Description: -* -* This file contains the check_apt plugin -* -* Check for available updates in apt package management systems -* -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* -*****************************************************************************/ + * + * Monitoring check_apt plugin + * + * License: GPL + * Copyright (c) 2006-2024 Monitoring Plugins Development Team + * + * Original author: Sean Finney + * + * Description: + * + * This file contains the check_apt plugin + * + * Check for available updates in apt package management systems + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *****************************************************************************/ const char *progname = "check_apt"; const char *copyright = "2006-2024"; @@ -39,7 +39,11 @@ const char *email = "devel@monitoring-plugins.org"; #include "regex.h" /* some constants */ -typedef enum { UPGRADE, DIST_UPGRADE, NO_UPGRADE } upgrade_type; +typedef enum { + UPGRADE, + DIST_UPGRADE, + NO_UPGRADE +} upgrade_type; /* Character for hidden input file option (for testing). */ #define INPUT_FILE_OPT CHAR_MAX + 1 -- cgit v1.2.3-74-g34f1 From 4079ba3c474054af6c8bb2c3b426540b2de01628 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:37:30 +0100 Subject: check_apt: Purify run_upgrade function --- plugins/check_apt.c | 66 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'plugins') diff --git a/plugins/check_apt.c b/plugins/check_apt.c index ac89f816..1eda45dd 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -69,8 +69,18 @@ void print_usage(void); static char *construct_cmdline(upgrade_type u, const char *opts); /* run an apt-get update */ static int run_update(void); + +typedef struct { + int errorcode; + int package_count; + int security_package_count; + char **packages_list; + char **secpackages_list; +} run_upgrade_result; + /* run an apt-get upgrade */ -static int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist); +static run_upgrade_result run_upgrade(void); + /* add another clause to a regexp */ static char *add_to_regexp(char *expr, const char *next); /* extract package name from Inst line */ @@ -119,12 +129,14 @@ int main(int argc, char **argv) { result = run_update(); } - int packages_available = 0; - int sec_count = 0; - char **packages_list = NULL; - char **secpackages_list = NULL; /* apt-get upgrade */ - result = max_state(result, run_upgrade(&packages_available, &sec_count, &packages_list, &secpackages_list)); + run_upgrade_result upgrad_res = run_upgrade(); + + result = max_state(result, upgrad_res.errorcode); + int packages_available = upgrad_res.package_count; + int sec_count = upgrad_res.security_package_count; + char **packages_list = upgrad_res.packages_list; + char **secpackages_list = upgrad_res.secpackages_list; if (sec_count > 0) { result = max_state(result, STATE_CRITICAL); @@ -257,13 +269,18 @@ int process_arguments(int argc, char **argv) { } /* run an apt-get upgrade */ -int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist) { +run_upgrade_result run_upgrade(void) { regex_t ereg; /* initialize ereg as it is possible it is printed while uninitialized */ memset(&ereg, '\0', sizeof(ereg.buffer)); + run_upgrade_result result = { + .errorcode = STATE_UNKNOWN, + }; + if (upgrade == NO_UPGRADE) { - return STATE_OK; + result.errorcode = STATE_OK; + return result; } int regres = 0; @@ -294,33 +311,32 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); } - int result = STATE_UNKNOWN; struct output chld_out; struct output chld_err; char *cmdline = NULL; cmdline = construct_cmdline(upgrade, upgrade_opts); if (input_filename != NULL) { /* read input from a file for testing */ - result = cmd_file_read(input_filename, &chld_out, 0); + result.errorcode = cmd_file_read(input_filename, &chld_out, 0); } else { /* run the upgrade */ - result = np_runcmd(cmdline, &chld_out, &chld_err, 0); + result.errorcode = np_runcmd(cmdline, &chld_out, &chld_err, 0); } /* apt-get upgrade only changes exit status if there is an * internal error when run in dry-run mode. therefore we will * treat such an error as UNKNOWN */ - if (result != 0) { + if (result.errorcode != STATE_OK) { exec_warning = 1; - result = STATE_UNKNOWN; + result.errorcode = STATE_UNKNOWN; fprintf(stderr, _("'%s' exited with non-zero status.\n"), cmdline); } - *pkglist = malloc(sizeof(char *) * chld_out.lines); + char **pkglist = malloc(sizeof(char *) * chld_out.lines); if (!pkglist) { die(STATE_UNKNOWN, "malloc failed!\n"); } - *secpkglist = malloc(sizeof(char *) * chld_out.lines); + char **secpkglist = malloc(sizeof(char *) * chld_out.lines); if (!secpkglist) { die(STATE_UNKNOWN, "malloc failed!\n"); } @@ -334,8 +350,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg * we may need to switch to the --print-uris output format, * in which case the logic here will slightly change. */ - int pc = 0; - int spc = 0; + int package_counter = 0; + int security_package_counter = 0; for (size_t i = 0; i < chld_out.lines; i++) { if (verbose) { printf("%s\n", chld_out.line[i]); @@ -346,15 +362,15 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg /* if we're not excluding, or it's not in the * list of stuff to exclude */ if (do_exclude == NULL || regexec(&ereg, chld_out.line[i], 0, NULL, 0) != 0) { - pc++; + package_counter++; if (regexec(&sreg, chld_out.line[i], 0, NULL, 0) == 0) { - spc++; + security_package_counter++; if (verbose) { printf("*"); } - (*secpkglist)[spc - 1] = pkg_name(chld_out.line[i]); + (secpkglist)[security_package_counter - 1] = pkg_name(chld_out.line[i]); } else { - (*pkglist)[pc - spc - 1] = pkg_name(chld_out.line[i]); + (pkglist)[package_counter - security_package_counter - 1] = pkg_name(chld_out.line[i]); } if (verbose) { printf("*%s\n", chld_out.line[i]); @@ -362,13 +378,15 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg } } } - *pkgcount = pc; - *secpkgcount = spc; + result.package_count = package_counter; + result.security_package_count = security_package_counter; + result.packages_list = pkglist; + result.secpackages_list = secpkglist; /* If we get anything on stderr, at least set warning */ if (input_filename == NULL && chld_err.buflen) { stderr_warning = 1; - result = max_state(result, STATE_WARNING); + result.errorcode = max_state(result.errorcode, STATE_WARNING); if (verbose) { for (size_t i = 0; i < chld_err.lines; i++) { fprintf(stderr, "%s\n", chld_err.line[i]); -- cgit v1.2.3-74-g34f1 From 2031a5acebc8ade6b3775bae769b1decc1747be9 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:20:03 +0100 Subject: check_overcr: delare file local variables static --- plugins/check_overcr.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'plugins') diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c index e80d4775..599540b7 100644 --- a/plugins/check_overcr.c +++ b/plugins/check_overcr.c @@ -52,23 +52,22 @@ enum { PORT = 2000 }; -char *server_address = NULL; -int server_port = PORT; -double warning_value = 0L; -double critical_value = 0L; -bool check_warning_value = false; -bool check_critical_value = false; -enum checkvar vars_to_check = NONE; -int cmd_timeout = 1; - -int netstat_port = 0; -char *disk_name = NULL; -char *process_name = NULL; -char send_buffer[MAX_INPUT_BUFFER]; - -int process_arguments(int, char **); +static char *server_address = NULL; +static int server_port = PORT; +static double warning_value = 0L; +static double critical_value = 0L; +static bool check_warning_value = false; +static bool check_critical_value = false; +static enum checkvar vars_to_check = NONE; + +static int netstat_port = 0; +static char *disk_name = NULL; +static char *process_name = NULL; +static char send_buffer[MAX_INPUT_BUFFER]; + +static int process_arguments(int, char **); void print_usage(void); -void print_help(void); +static void print_help(void); int main(int argc, char **argv) { int result = STATE_UNKNOWN; -- cgit v1.2.3-74-g34f1 From b7b8abb8533d8d21e76481eb26bae9215e56b2fd Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:30:38 +0100 Subject: check_ldap: delare file local variables static --- plugins/check_ldap.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'plugins') diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 1c728292..87818da6 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c @@ -47,37 +47,37 @@ enum { DEFAULT_PORT = 389 }; -int process_arguments (int, char **); -int validate_arguments (void); -void print_help (void); +static int process_arguments (int, char **); +static int validate_arguments (void); +static void print_help (void); void print_usage (void); -char ld_defattr[] = "(objectclass=*)"; -char *ld_attr = ld_defattr; -char *ld_host = NULL; -char *ld_base = NULL; -char *ld_passwd = NULL; -char *ld_binddn = NULL; -int ld_port = -1; +static char ld_defattr[] = "(objectclass=*)"; +static char *ld_attr = ld_defattr; +static char *ld_host = NULL; +static char *ld_base = NULL; +static char *ld_passwd = NULL; +static char *ld_binddn = NULL; +static int ld_port = -1; #ifdef HAVE_LDAP_SET_OPTION -int ld_protocol = DEFAULT_PROTOCOL; +static int ld_protocol = DEFAULT_PROTOCOL; #endif #ifndef LDAP_OPT_SUCCESS # define LDAP_OPT_SUCCESS LDAP_SUCCESS #endif -double warn_time = UNDEFINED; -double crit_time = UNDEFINED; -thresholds *entries_thresholds = NULL; -struct timeval tv; -char* warn_entries = NULL; -char* crit_entries = NULL; -bool starttls = false; -bool ssl_on_connect = false; -bool verbose = false; +static double warn_time = UNDEFINED; +static double crit_time = UNDEFINED; +static thresholds *entries_thresholds = NULL; +static struct timeval tv; +static char* warn_entries = NULL; +static char* crit_entries = NULL; +static bool starttls = false; +static bool ssl_on_connect = false; +static bool verbose = false; /* for ldap tls */ -char *SERVICE = "LDAP"; +static char *SERVICE = "LDAP"; int main (int argc, char *argv[]) -- cgit v1.2.3-74-g34f1 From 458af516886dc6e6373734f4c5b48ea0ffa7e987 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:32:45 +0100 Subject: check_mysql: delare file local variables static --- plugins/check_mysql.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'plugins') diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 1f0b7099..8a73772d 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -45,23 +45,23 @@ const char *email = "devel@monitoring-plugins.org"; #include #include -char *db_user = NULL; -char *db_host = NULL; -char *db_socket = NULL; -char *db_pass = NULL; -char *db = NULL; -char *ca_cert = NULL; -char *ca_dir = NULL; -char *cert = NULL; -char *key = NULL; -char *ciphers = NULL; -bool ssl = false; -char *opt_file = NULL; -char *opt_group = NULL; -unsigned int db_port = MYSQL_PORT; -bool check_slave = false; -bool ignore_auth = false; -int verbose = 0; +static char *db_user = NULL; +static char *db_host = NULL; +static char *db_socket = NULL; +static char *db_pass = NULL; +static char *db = NULL; +static char *ca_cert = NULL; +static char *ca_dir = NULL; +static char *cert = NULL; +static char *key = NULL; +static char *ciphers = NULL; +static bool ssl = false; +static char *opt_file = NULL; +static char *opt_group = NULL; +static unsigned int db_port = MYSQL_PORT; +static bool check_slave = false; +static bool ignore_auth = false; +static int verbose = 0; static double warning_time = 0; static double critical_time = 0; @@ -91,11 +91,11 @@ static const char *metric_counter[LENGTH_METRIC_COUNTER] = { #define MYSQLDUMP_THREADS_QUERY "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'" -thresholds *my_threshold = NULL; +static thresholds *my_threshold = NULL; -int process_arguments (int, char **); -int validate_arguments (void); -void print_help (void); +static int process_arguments (int, char **); +static int validate_arguments (void); +static void print_help (void); void print_usage (void); int -- cgit v1.2.3-74-g34f1 From c7124379cd4e70d91e9af6eec4cf414849dc77d7 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:34:24 +0100 Subject: check_nt: delare file local variables static --- plugins/check_nt.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'plugins') diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 413aad6b..dec0b668 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c @@ -59,26 +59,25 @@ enum { PORT = 1248 }; -char *server_address = NULL; -char *volume_name = NULL; -int server_port = PORT; -char *value_list = NULL; -char *req_password = NULL; -unsigned long lvalue_list[MAX_VALUE_LIST]; -unsigned long warning_value = 0L; -unsigned long critical_value = 0L; -bool check_warning_value = false; -bool check_critical_value = false; -enum checkvars vars_to_check = CHECK_NONE; -bool show_all = false; - -char recv_buffer[MAX_INPUT_BUFFER]; - -void fetch_data(const char *address, int port, const char *sendb); -int process_arguments(int, char **); -void preparelist(char *string); -bool strtoularray(unsigned long *array, char *string, const char *delim); -void print_help(void); +static char *server_address = NULL; +static int server_port = PORT; +static char *value_list = NULL; +static char *req_password = NULL; +static unsigned long lvalue_list[MAX_VALUE_LIST]; +static unsigned long warning_value = 0L; +static unsigned long critical_value = 0L; +static bool check_warning_value = false; +static bool check_critical_value = false; +static enum checkvars vars_to_check = CHECK_NONE; +static bool show_all = false; + +static char recv_buffer[MAX_INPUT_BUFFER]; + +static void fetch_data(const char *address, int port, const char *sendb); +static int process_arguments(int /*argc*/, char ** /*argv*/); +static void preparelist(char *string); +static bool strtoularray(unsigned long *array, char *string, const char *delim); +static void print_help(void); void print_usage(void); int main(int argc, char **argv) { -- cgit v1.2.3-74-g34f1 From e3efbb796a58e02eceeef2e12b1f159d687a1b2b Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:35:27 +0100 Subject: check_ntp: delare file local variables static --- plugins/check_ntp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 55a49460..d33f8786 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c @@ -47,10 +47,10 @@ static bool do_jitter = false; static char *jwarn="5000"; static char *jcrit="10000"; -int process_arguments (int, char **); -thresholds *offset_thresholds = NULL; -thresholds *jitter_thresholds = NULL; -void print_help (void); +static int process_arguments (int /*argc*/, char ** /*argv*/); +static thresholds *offset_thresholds = NULL; +static thresholds *jitter_thresholds = NULL; +static void print_help (void); void print_usage (void); /* number of times to perform each request to get a good average. */ -- cgit v1.2.3-74-g34f1 From 5130e5b0d3591866488bd03b00ca383cd7674b3c Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:36:41 +0100 Subject: check_nwstat: delare file local variables static --- plugins/check_nwstat.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'plugins') diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index 3af63603..176dfbc8 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c @@ -89,30 +89,30 @@ enum { PORT = 9999 }; -char *server_address = NULL; -char *volume_name = NULL; -char *nlm_name = NULL; -char *nrmp_name = NULL; -char *nrmm_name = NULL; -char *nrms_name = NULL; -char *nss1_name = NULL; -char *nss2_name = NULL; -char *nss3_name = NULL; -char *nss4_name = NULL; -char *nss5_name = NULL; -char *nss6_name = NULL; -char *nss7_name = NULL; -int server_port = PORT; -unsigned long warning_value = 0L; -unsigned long critical_value = 0L; -bool check_warning_value = false; -bool check_critical_value = false; -bool check_netware_version = false; -enum checkvar vars_to_check = NONE; -int sap_number = -1; - -int process_arguments(int, char **); -void print_help(void); +static char *server_address = NULL; +static char *volume_name = NULL; +static char *nlm_name = NULL; +static char *nrmp_name = NULL; +static char *nrmm_name = NULL; +static char *nrms_name = NULL; +static char *nss1_name = NULL; +static char *nss2_name = NULL; +static char *nss3_name = NULL; +static char *nss4_name = NULL; +static char *nss5_name = NULL; +static char *nss6_name = NULL; +static char *nss7_name = NULL; +static int server_port = PORT; +static unsigned long warning_value = 0L; +static unsigned long critical_value = 0L; +static bool check_warning_value = false; +static bool check_critical_value = false; +static bool check_netware_version = false; +static enum checkvar vars_to_check = NONE; +static int sap_number = -1; + +static int process_arguments(int /*argc*/, char ** /*argv*/); +static void print_help(void); void print_usage(void); int main(int argc, char **argv) { -- cgit v1.2.3-74-g34f1 From 99bb7dd0f8f6962e12a3b0e4cd8bab0ebb278f0f Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:39:08 +0100 Subject: check_procs: delare file local variables static --- plugins/check_procs.c | 56 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'plugins') diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 5777ba07..53c93c0b 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -51,17 +51,17 @@ const char *email = "devel@monitoring-plugins.org"; #include #endif -int process_arguments (int, char **); -int validate_arguments (void); -int convert_to_seconds (char *); -void print_help (void); +static int process_arguments (int /*argc*/, char ** /*argv*/); +static int validate_arguments (void); +static int convert_to_seconds (char * /*etime*/); +static void print_help (void); void print_usage (void); -char *warning_range = NULL; -char *critical_range = NULL; -thresholds *procs_thresholds = NULL; +static char *warning_range = NULL; +static char *critical_range = NULL; +static thresholds *procs_thresholds = NULL; -int options = 0; /* bitmask of filter criteria to test against */ +static int options = 0; /* bitmask of filter criteria to test against */ #define ALL 1 #define STAT 2 #define PPID 4 @@ -89,27 +89,25 @@ enum metric { }; enum metric metric = METRIC_PROCS; -int verbose = 0; -int uid; -pid_t ppid; -int vsz; -int rss; -float pcpu; -char *statopts; -char *prog; -char *exclude_progs; -char **exclude_progs_arr = NULL; -char exclude_progs_counter = 0; -char *args; -char *input_filename = NULL; -regex_t re_args; -char *fmt; -char *fails; -char tmp[MAX_INPUT_BUFFER]; -int kthread_filter = 0; -int usepid = 0; /* whether to test for pid or /proc/pid/exe */ - -FILE *ps_input = NULL; +static int verbose = 0; +static int uid; +static pid_t ppid; +static int vsz; +static int rss; +static float pcpu; +static char *statopts; +static char *prog; +static char *exclude_progs; +static char **exclude_progs_arr = NULL; +static char exclude_progs_counter = 0; +static char *args; +static char *input_filename = NULL; +static regex_t re_args; +static char *fmt; +static char *fails; +static char tmp[MAX_INPUT_BUFFER]; +static int kthread_filter = 0; +static int usepid = 0; /* whether to test for pid or /proc/pid/exe */ static int stat_exe (const pid_t pid, struct stat *buf) { -- cgit v1.2.3-74-g34f1 From 54042ac52f7883cf45176f084f63f22b3fdc235c Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:39:44 +0100 Subject: check_procs: use proper escape for % --- plugins/check_procs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 53c93c0b..1d78ccee 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -832,7 +832,7 @@ be the total number of running processes\n\n")); printf (" %s\n", "check_procs -w 50000 -c 100000 --metric=VSZ"); printf (" %s\n\n", _("Alert if VSZ of any processes over 50K or 100K")); printf (" %s\n", "check_procs -w 10 -c 20 --metric=CPU"); - printf (" %s\n", _("Alert if CPU of any processes over 10\% or 20\%")); + printf (" %s\n", _("Alert if CPU of any processes over 10%% or 20%%")); printf (UT_SUPPORT); } -- cgit v1.2.3-74-g34f1 From 0c592fa860367099924841cf390ea9f580a922ec Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:44:21 +0100 Subject: check_ide_smart: fix misleading static declaration --- plugins/check_ide_smart.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index 381dbd80..9640ef70 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c @@ -113,12 +113,10 @@ typedef struct values_s { __u8 checksum; } __attribute__((packed)) values_t; -struct { +static struct { __u8 value; char *text; -} - -static offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"}, +} offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"}, {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}}; static struct { -- cgit v1.2.3-74-g34f1 From 6644a81c5795f71ec8acd60da76f8cef052e5ad5 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:45:53 +0100 Subject: check_radius: delare file local variables static --- plugins/check_radius.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'plugins') diff --git a/plugins/check_radius.c b/plugins/check_radius.c index 8ed19e55..d9ff8fa7 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c @@ -46,8 +46,8 @@ const char *email = "devel@monitoring-plugins.org"; #include #endif -int process_arguments (int, char **); -void print_help (void); +static int process_arguments (int /*argc*/, char ** /*argv*/); +static void print_help (void); void print_usage (void); #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) @@ -78,22 +78,22 @@ void print_usage (void); #define REJECT_RC BADRESP_RC #endif -int my_rc_read_config(char *); +static int my_rc_read_config(char * /*a*/); #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) -rc_handle *rch = NULL; +static rc_handle *rch = NULL; #endif -char *server = NULL; -char *username = NULL; -char *password = NULL; -char *nasid = NULL; -char *nasipaddress = NULL; -char *expect = NULL; -char *config_file = NULL; -unsigned short port = PW_AUTH_UDP_PORT; -int retries = 1; -bool verbose = false; +static char *server = NULL; +static char *username = NULL; +static char *password = NULL; +static char *nasid = NULL; +static char *nasipaddress = NULL; +static char *expect = NULL; +static char *config_file = NULL; +static unsigned short port = PW_AUTH_UDP_PORT; +static int retries = 1; +static bool verbose = false; /****************************************************************************** -- cgit v1.2.3-74-g34f1 From d330b975b3c580c385c736c8a52209919de1d582 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:47:32 +0100 Subject: check_smtp: delare file local variables static --- plugins/check_smtp.c | 94 +++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 48 deletions(-) (limited to 'plugins') diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index bc175287..c73693c0 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -64,61 +64,59 @@ enum { #define EHLO_SUPPORTS_STARTTLS 1 -int process_arguments (int, char **); -int validate_arguments (void); -void print_help (void); +static int process_arguments (int, char **); +static int validate_arguments (void); +static void print_help (void); void print_usage (void); -void smtp_quit(void); -int recvline(char *, size_t); -int recvlines(char *, size_t); -int my_close(void); +static void smtp_quit(void); +static int recvline(char *, size_t); +static int recvlines(char *, size_t); +static int my_close(void); #include "regex.h" -char regex_expect[MAX_INPUT_BUFFER] = ""; -regex_t preg; -regmatch_t pmatch[10]; -char timestamp[20] = ""; -char errbuf[MAX_INPUT_BUFFER]; -int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; -int eflags = 0; -int errcode, excode; - -int server_port = SMTP_PORT; -int server_port_option = 0; -char *server_address = NULL; -char *server_expect = NULL; -char *mail_command = NULL; -char *from_arg = NULL; -int send_mail_from=0; -int ncommands=0; -int command_size=0; -int nresponses=0; -int response_size=0; -char **commands = NULL; -char **responses = NULL; -char *authtype = NULL; -char *authuser = NULL; -char *authpass = NULL; -double warning_time = 0; -bool check_warning_time = false; -double critical_time = 0; -bool check_critical_time = false; -int verbose = 0; -bool use_ssl = false; -bool use_starttls = false; -bool use_sni = false; -bool use_proxy_prefix = false; -bool use_ehlo = false; -bool use_lhlo = false; -bool ssl_established = false; -char *localhostname = NULL; -int sd; -char buffer[MAX_INPUT_BUFFER]; +static regex_t preg; +static regmatch_t pmatch[10]; +static char errbuf[MAX_INPUT_BUFFER]; +static int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; +static int eflags = 0; +static int errcode, excode; + +static int server_port = SMTP_PORT; +static int server_port_option = 0; +static char *server_address = NULL; +static char *server_expect = NULL; +static char *mail_command = NULL; +static char *from_arg = NULL; +static int send_mail_from=0; +static int ncommands=0; +static int command_size=0; +static int nresponses=0; +static int response_size=0; +static char **commands = NULL; +static char **responses = NULL; +static char *authtype = NULL; +static char *authuser = NULL; +static char *authpass = NULL; +static double warning_time = 0; +static bool check_warning_time = false; +static double critical_time = 0; +static bool check_critical_time = false; +static int verbose = 0; +static bool use_ssl = false; +static bool use_starttls = false; +static bool use_sni = false; +static bool use_proxy_prefix = false; +static bool use_ehlo = false; +static bool use_lhlo = false; +static bool ssl_established = false; +static char *localhostname = NULL; +static int sd; +static char buffer[MAX_INPUT_BUFFER]; enum { TCP_PROTOCOL = 1, UDP_PROTOCOL = 2, }; -bool ignore_send_quit_failure = false; +static bool ignore_send_quit_failure = false; int -- cgit v1.2.3-74-g34f1 From 6848e618c0eb54563707bf473fbd8c4acf6d2b2d Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:49:37 +0100 Subject: check_ups: delare file local variables static --- plugins/check_ups.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/check_ups.c b/plugins/check_ups.c index adb7ab81..5dfa72a4 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c @@ -97,13 +97,13 @@ ups_config ups_config_init(void) { } // Forward declarations -int determine_status(ups_config *, int *supported_options); -int get_ups_variable(const char *, char *, const ups_config config); +static int determine_status(ups_config * /*config*/, int *supported_options); +static int get_ups_variable(const char * /*varname*/, char * /*buf*/, ups_config config); -int process_arguments(int, char **, ups_config *); -int validate_arguments(ups_config); -void print_help(void); -void print_usage(void); +static int process_arguments(int /*argc*/, char ** /*argv*/, ups_config * /*config*/); +static int validate_arguments(ups_config /*config*/); +static void print_help(void); +static void print_usage(void); int main(int argc, char **argv) { setlocale(LC_ALL, ""); -- cgit v1.2.3-74-g34f1 From b830c7a3e07ea5cd7b8253c4c9fadecd9ad621b6 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:51:14 +0100 Subject: check_smtp: delare previously missed file local variables static --- plugins/check_smtp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index c73693c0..e6369e63 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -40,8 +40,8 @@ const char *email = "devel@monitoring-plugins.org"; #include #ifdef HAVE_SSL -bool check_cert = false; -int days_till_exp_warn, days_till_exp_crit; +static bool check_cert = false; +static int days_till_exp_warn, days_till_exp_crit; # define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) # define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) #else /* ifndef HAVE_SSL */ -- cgit v1.2.3-74-g34f1 From bd5608b9fc5d2b3db9f3c9026d279f8928ab4d0c Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:51:39 +0100 Subject: check_ups: do not declare print_usage static --- plugins/check_ups.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 5dfa72a4..526a29df 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c @@ -103,7 +103,7 @@ static int get_ups_variable(const char * /*varname*/, char * /*buf*/, ups_config static int process_arguments(int /*argc*/, char ** /*argv*/, ups_config * /*config*/); static int validate_arguments(ups_config /*config*/); static void print_help(void); -static void print_usage(void); +void print_usage(void); int main(int argc, char **argv) { setlocale(LC_ALL, ""); -- cgit v1.2.3-74-g34f1 From 6eb5be9e30b23035632b674f6b46c18313cde63b Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 9 Nov 2024 10:49:21 +0100 Subject: Fix argument order of calloc on several occasions --- lib/utils_cmd.c | 2 +- plugins/check_tcp.c | 2 +- plugins/runcmd.c | 2 +- plugins/utils.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 416cf824..18350ac0 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c @@ -290,7 +290,7 @@ int cmd_run(const char *cmdstring, output *out, output *err, int flags) { /* each arg must be whitespace-separated, so args can be a maximum * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */ argc = (cmdlen >> 1) + 2; - argv = calloc(sizeof(char *), argc); + argv = calloc((size_t)argc, sizeof(char *)); if (argv == NULL) { printf("%s\n", _("Could not malloc argv array in popen()")); diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index c13ac767..49ad096c 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c @@ -119,7 +119,7 @@ int main(int argc, char **argv) { /* set up a reasonable buffer at first (will be realloc()'ed if * user specifies other options) */ - server_expect = calloc(sizeof(char *), 2); + server_expect = calloc(2, sizeof(char *)); /* determine defaults for this service's protocol */ if (!strncmp(SERVICE, "UDP", 3)) { diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 2e53dc0b..74843149 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c @@ -130,7 +130,7 @@ static int np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) { /* each arg must be whitespace-separated, so args can be a maximum * of (len / 2) + 1. We add 1 extra to the mix for NULL termination */ argc = (cmdlen >> 1) + 2; - argv = calloc(sizeof(char *), argc); + argv = calloc(argc, sizeof(char *)); if (argv == NULL) { printf("%s\n", _("Could not malloc argv array in popen()")); diff --git a/plugins/utils.c b/plugins/utils.c index f11db731..6d366e3d 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -185,7 +185,7 @@ bool is_percentage_expression(const char str[]) { return false; } - char *foo = calloc(sizeof(char), len + 1); + char *foo = calloc(len + 1, sizeof(char)); if (!foo) { die(STATE_UNKNOWN, _("calloc failed \n")); -- cgit v1.2.3-74-g34f1 From f1dae440753b7d36346b0e0a516f69b3ff5d1546 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:26:09 +0100 Subject: Fix false formatting directive in printf --- plugins/check_curl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 1d27da28..8ea73ce1 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -525,7 +525,7 @@ int check_http(void) { // use the host_name later on to make SNI happy if (use_ssl && host_name != NULL) { if ((res = lookup_host(server_address, addrstr, DEFAULT_BUFFER_SIZE / 2)) != 0) { - snprintf(msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %d"), server_address, res, + snprintf(msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), server_address, res, gai_strerror(res)); die(STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); } -- cgit v1.2.3-74-g34f1