Skip to content

Commit

Permalink
NEWS.adoc, drivers/main.c: exit_cleanup(): avoid upsnotify() at exit …
Browse files Browse the repository at this point in the history
…if CLI args were fatally useless

Note also earlier change in commit d6112a3

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Feb 4, 2025
1 parent c3379a1 commit ae33dfe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ https://github.com/networkupstools/nut/milestone/11
now to report human-friendly text instead of internal enum codes. Follow-up
to [issue #1590, PR #1777, PR #2136]
- drivers should no longer print warning messages about not-initializing the
notification subsystem because not running as a service when they are either
started explicitly to show the help message, or when their CLI arguments
are fatally wrong (no UPS name, no `port`, invalid trailing keywords...)
- drivers, `upsd`, `upsmon`: reduce "scary noise" about failure to `fopen()`
the PID file (which most of the time means that no previous instance of
the daemon was running to potentially conflict with), especially useless
Expand Down
13 changes: 12 additions & 1 deletion drivers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static int nut_debug_level_protocol = -1;
/* everything else */
static char *pidfn = NULL;
static int help_only = 0,
cli_args_accepted = 0,
dump_data = 0; /* Store the update_count requested */
#endif /* DRIVERS_MAIN_WITHOUT_MAIN */

Expand Down Expand Up @@ -796,7 +797,7 @@ int do_loop_shutdown_commands(const char *sdcmds, char **cmdused) {
"too deeply nested, this seems to be either "
"a NUT programming error or a mis-configuration "
"of your 'sdcommands' setting", NUT_STRARG(upsname));
}
}

if (cmdused) {
if (*cmdused)
Expand Down Expand Up @@ -1833,6 +1834,15 @@ static void exit_cleanup(void)
dstate_setinfo("driver.state", "cleanup.exit");

if (!dump_data && !help_only) {
if (!cli_args_accepted && !getenv("NUT_QUIET_INIT_UPSNOTIFY")) {
/* Default to not yelling about notification method support (or
* lack thereof) when CLI arguments did not get handled early on.
* Set envvar to cause "upsnotify_report_verbosity = 1" in
* common.c::upsnotify() (if still applicable; if already
* reported - oh well).
*/
setenv("NUT_QUIET_INIT_UPSNOTIFY", "yes", 0);
}
upsnotify(NOTIFY_STATE_STOPPING, "exit_cleanup()");
}

Expand Down Expand Up @@ -2333,6 +2343,7 @@ int main(int argc, char **argv)
"Try -h for help.");
}

cli_args_accepted = 1;
assign_debug_level();

new_uid = get_user_pwent(user);
Expand Down

0 comments on commit ae33dfe

Please sign in to comment.