Skip to content

Commit 0ee8833

Browse files
committed
drivers/main.c, conf/ups.conf.sample, docs/man/ups.conf.txt: Introduce reconnect_report_freq to manage verbosity of on-going reconnect_trying() streak [#3541]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent 25e936a commit 0ee8833

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

conf/ups.conf.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ maxretry = 3
124124
# indefinitely (e.g. data cable fell out, or the data path
125125
# to a networked UPS was lost for a significant time).
126126
#
127+
# reconnect_report_freq: OPTIONAL. This can be set as a global variable
128+
# above your first UPS definition and it can also be set in a
129+
# UPS section, and used in conjunction with reconnect_max_tries
130+
# to report progress (and on-going lack of success) every N
131+
# attempts, to avoid flooding the logs. A non-positive value
132+
# disables such updates completely (default).
133+
#
127134
# debug_min: OPTIONAL. Specify a minimum debug level for all driver daemons
128135
# and for the upsdrvctl tool (when specified at global level),
129136
# or for this driver daemon (when specified in a driver section),

docs/man/ups.conf.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ A negative value (default) means to try reconnecting indefinitely (e.g. data
113113
cable fell out, or the data path to a networked UPS was lost for a significant
114114
time).
115115

116+
*reconnect_report_freq*::
117+
118+
Optional. This can be used in conjunction with `reconnect_max_tries` to
119+
report progress (and on-going lack of success) every `N` attempts, to avoid
120+
flooding the logs.
121+
+
122+
A non-positive value disables such updates completely (default).
123+
116124
*maxstartdelay*::
117125

118126
Optional. Same as the UPS field of the same name, but this is the
@@ -358,6 +366,11 @@ Optional. This can be set as a global variable above your first UPS
358366
definition and it can also be set in a UPS section. See explanation
359367
above, in the global section.
360368

369+
*reconnect_report_freq*::
370+
Optional. This can be set as a global variable above your first UPS
371+
definition and it can also be set in a UPS section. See explanation
372+
above, in the global section.
373+
361374
*maxretry*::
362375
Optional. This can be set as a global variable above your first UPS
363376
definition and it can also be set in a UPS section. See explanation

drivers/main.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ vartab_t *vartab_h = NULL;
102102
time_t poll_interval = 2;
103103
static char *chroot_path = NULL, *user = NULL, *group = NULL;
104104
static int user_from_cmdline = 0, group_from_cmdline = 0,
105-
reconnect_max_tries = -1, reconnect_count = 0;
105+
reconnect_max_tries = -1, reconnect_count = 0, reconnect_report_freq = -1;
106106

107107
/* signal handling */
108108
int exit_flag = 0;
@@ -1410,6 +1410,15 @@ static int main_arg(char *var, char *val)
14101410
}
14111411
}
14121412

1413+
if (!strcmp(var, "reconnect_report_freq")) {
1414+
int intval = -1;
1415+
if ( str_to_int (val, &intval, 10) ) {
1416+
reconnect_report_freq = intval;
1417+
} else {
1418+
upslogx(LOG_INFO, "WARNING : Invalid reconnect_report_freq value found in ups.conf global settings");
1419+
}
1420+
}
1421+
14131422
/* only for upsdrvctl - ignored here */
14141423
if (!strcmp(var, "sdorder"))
14151424
return 1; /* handled */
@@ -1596,6 +1605,17 @@ static void do_global_args(const char *var, const char *val)
15961605
return;
15971606
}
15981607

1608+
if (!strcmp(var, "reconnect_report_freq")) {
1609+
int intval = -1;
1610+
if ( str_to_int (val, &intval, 10) ) {
1611+
reconnect_report_freq = intval;
1612+
} else {
1613+
upslogx(LOG_INFO, "WARNING : Invalid reconnect_report_freq value found in ups.conf global settings");
1614+
}
1615+
1616+
return;
1617+
}
1618+
15991619
/* Allow to specify its minimal debugging level for all drivers -
16001620
* admins can set more with command-line args, but can't set
16011621
* less without changing config. Should help debug of services.
@@ -2260,6 +2280,10 @@ int reconnect_trying(reconnect_state_t trying) {
22602280
"max %d attempts, then will exit",
22612281
upsname, reconnect_max_tries);
22622282
}
2283+
} else if (reconnect_report_freq > 0 && (reconnect_count % reconnect_report_freq) == 0) {
2284+
upslogx(LOG_WARNING, "Driver still reconnecting "
2285+
"to the device [%s] for %d attempts",
2286+
upsname, reconnect_count);
22632287
}
22642288

22652289
if (reconnect_count < INT_MAX) {

0 commit comments

Comments
 (0)