Skip to content

Commit

Permalink
Refactor nut_report_config_flags() from many programs into common.c [n…
Browse files Browse the repository at this point in the history
  • Loading branch information
jimklimov committed Jan 21, 2023
1 parent 630f0d1 commit 4d64fa0
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 35 deletions.
6 changes: 2 additions & 4 deletions clients/upsc.c
Expand Up @@ -57,8 +57,7 @@ static void usage(const char *prog)
printf(" -c - lists each client connected on <ups>, one per line.\n");
printf(" <ups> - upsd server, <upsname>[@<hostname>[:<port>]] form\n");

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();
}

static void printvar(const char *var)
Expand Down Expand Up @@ -235,8 +234,7 @@ int main(int argc, char **argv)
break;

case 'V':
upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();

fatalx(EXIT_SUCCESS, "Network UPS Tools upscmd %s", UPS_VERSION);
#ifndef HAVE___ATTRIBUTE__NORETURN
Expand Down
6 changes: 2 additions & 4 deletions clients/upscmd.c
Expand Up @@ -65,8 +65,7 @@ static void usage(const char *prog)
printf(" <command> Valid instant command - test.panel.start, etc.\n");
printf(" [<value>] Additional data for command - number of seconds, etc.\n");

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();
}

static void print_cmd(char *cmdname)
Expand Down Expand Up @@ -312,8 +311,7 @@ int main(int argc, char **argv)
break;

case 'V':
upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();

fatalx(EXIT_SUCCESS, "Network UPS Tools upscmd %s", UPS_VERSION);
#ifndef HAVE___ATTRIBUTE__NORETURN
Expand Down
6 changes: 2 additions & 4 deletions clients/upslog.c
Expand Up @@ -176,8 +176,7 @@ static void help(const char *prog)
printf("\n");
printf("See the upslog(8) man page for more information.\n");

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();

exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -504,8 +503,7 @@ int main(int argc, char **argv)
break;

case 'V':
upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();
exit(EXIT_SUCCESS);

case 'p':
Expand Down
8 changes: 3 additions & 5 deletions clients/upsmon.c
Expand Up @@ -2182,8 +2182,7 @@ static void help(const char *arg_progname)
printf(" -4 IPv4 only\n");
printf(" -6 IPv6 only\n");

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();

exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -2500,9 +2499,8 @@ int main(int argc, char *argv[])
run_as_user = xstrdup(optarg);
break;
case 'V':
/* just show the banner */
upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
/* just show the optional CONFIG_FLAGS banner */
nut_report_config_flags();
exit(EXIT_SUCCESS);
case '4':
opt_af = AF_INET;
Expand Down
6 changes: 2 additions & 4 deletions clients/upsrw.c
Expand Up @@ -66,8 +66,7 @@ static void usage(const char *prog)
printf("\n");
printf("Call without -s to show all possible read/write variables (same as -l).\n");

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();
}

static void clean_exit(void)
Expand Down Expand Up @@ -669,8 +668,7 @@ int main(int argc, char **argv)
break;
case 'V':
printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();
exit(EXIT_SUCCESS);
case 'h':
default:
Expand Down
6 changes: 6 additions & 0 deletions common/common.c
Expand Up @@ -937,6 +937,12 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
return ret;
}

void nut_report_config_flags(void)
{
upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
}

static void vupslog(int priority, const char *fmt, va_list va, int use_strerror)
{
int ret;
Expand Down
6 changes: 2 additions & 4 deletions drivers/main.c
Expand Up @@ -134,8 +134,7 @@ static void help_msg(void)
{
vartab_t *tmp;

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();

printf("\nusage: %s (-a <id>|-s <id>) [OPTIONS]\n", progname);

Expand Down Expand Up @@ -831,8 +830,7 @@ int main(int argc, char **argv)
break;
case 'V':
/* already printed the banner for program name */
upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();
exit(EXIT_SUCCESS);
case 'x':
splitxarg(optarg);
Expand Down
5 changes: 5 additions & 0 deletions include/common.h
Expand Up @@ -312,6 +312,11 @@ void fatal_with_errno(int status, const char *fmt, ...)
void fatalx(int status, const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3))) __attribute__((noreturn));

/* Report CONFIG_FLAGS used for this build of NUT similarly to how
* upsdebugx(1, ...) would do it, but not limiting the string length
*/
void nut_report_config_flags(void);

extern int nut_debug_level;
extern int nut_log_level;

Expand Down
6 changes: 2 additions & 4 deletions server/upsd.c
Expand Up @@ -1507,8 +1507,7 @@ static void help(const char *arg_progname)
printf(" -4 IPv4 only\n");
printf(" -6 IPv6 only\n");

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();

exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -1636,8 +1635,7 @@ int main(int argc, char **argv)

case 'V':
/* Note - we already printed the banner for program name */
upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
UPS_VERSION, CONFIG_FLAGS);
nut_report_config_flags();

exit(EXIT_SUCCESS);

Expand Down
8 changes: 2 additions & 6 deletions tools/nut-scanner/nut-scanner.c
Expand Up @@ -178,8 +178,7 @@ static void show_usage()
/* NOTE: This code uses `nutscan_avail_*` global vars from nutscan-init.c */
puts("nut-scanner : utility for detection of available power devices.\n");

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
NUT_VERSION_MACRO, CONFIG_FLAGS);
nut_report_config_flags();

puts("OPTIONS:");
printf(" -C, --complete_scan: Scan all available devices except serial ports (default).\n");
Expand Down Expand Up @@ -652,10 +651,7 @@ int main(int argc, char *argv[])
break;
case 'V':
printf("Network UPS Tools - %s\n", NUT_VERSION_MACRO);

upsdebugx(1, "Network UPS Tools version %s configured with flags: %s",
NUT_VERSION_MACRO, CONFIG_FLAGS);

nut_report_config_flags();
exit(EXIT_SUCCESS);
case 'a':
printf("OLDNUT\n");
Expand Down

0 comments on commit 4d64fa0

Please sign in to comment.