Skip to content

Commit

Permalink
tools/nut-scanner/nut-scanner.c: count auto-selected subnets, loudly …
Browse files Browse the repository at this point in the history
…warn if none were chosen [networkupstools#2244]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 15, 2024
1 parent c57fc18 commit 54b8d09
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tools/nut-scanner/nut-scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ static void handle_arg_cidr(const char *arg_addr, int *auto_nets_ptr)
long masklen_hosts_limit = 8;
char *s = NULL;
int errno_saved;
size_t auto_subnets_found = 0;

#ifdef HAVE_GETIFADDRS
/* NOTE: this ifdef is more precise than ifdef WIN32; assuming
Expand Down Expand Up @@ -925,6 +926,8 @@ static void handle_arg_cidr(const char *arg_addr, int *auto_nets_ptr)
nutscan_add_ip_range(&ip_ranges_list, start_ip, end_ip);
start_ip = NULL;
end_ip = NULL;

auto_subnets_found++;
} /* else AF_UNIX or a dozen other types we do not care about here */
}
}
Expand All @@ -945,7 +948,12 @@ static void handle_arg_cidr(const char *arg_addr, int *auto_nets_ptr)
}
#endif

upsdebugx(3, "Finished %s('%s')", __func__, arg_addr);
if (!auto_subnets_found) {
upsdebugx(0, "WARNING: A '-m auto*' request selected no subnets!\n"
"Please check for reasons with higher debug verbosity (up to 6).");
}
upsdebugx(3, "Finished %s('%s'), selected %" PRIuSIZE " subnets automatically",
__func__, arg_addr, auto_subnets_found);
}

static void show_usage(void)
Expand Down

0 comments on commit 54b8d09

Please sign in to comment.