Skip to content

Commit

Permalink
drivers/main.c, docs/nut-names.txt: introduce "driver.state" tracking [
Browse files Browse the repository at this point in the history
  • Loading branch information
jimklimov committed Jan 5, 2023
1 parent 222ee95 commit 10be1a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
10 changes: 10 additions & 0 deletions docs/nut-names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,16 @@ driver: Internal driver information
cmdline -x) setting | (varies)
| driver.flag.xxx | Flag xxx (ups.conf or
cmdline -x) status | enabled (or absent)
| driver.state | Current state in driver's
lifecycle, primarily to help
readers discern long-running
init (with full device walk)
or cleanup stages from
the stable working loop | init.starting, init.quiet,
init.device, init.info,
init.updateinfo (first walk),
updateinfo, quiet, dumping,
cleanup.upsdrv, cleanup.exit
|===============================================================================

server: Internal server information
Expand Down
3 changes: 2 additions & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 3067 utf-8
personal_ws-1.1 en 3068 utf-8
AAS
ABI
ACFAIL
Expand Down Expand Up @@ -2146,6 +2146,7 @@ licensor
licensors
liebert
liebertgxt
lifecycle
linesensitivity
linevoltage
linkdoc
Expand Down
20 changes: 19 additions & 1 deletion drivers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,16 @@ static void vartab_free(void)
}
}

static void exit_upsdrv_cleanup(void)
{
dstate_setinfo("driver.state", "cleanup.upsdrv");
upsdrv_cleanup();
}

static void exit_cleanup(void)
{
dstate_setinfo("driver.state", "cleanup.exit");

free(chroot_path);
free(device_path);
free(user);
Expand Down Expand Up @@ -691,6 +699,8 @@ int main(int argc, char **argv)
int i, do_forceshutdown = 0;
int update_count = 0;

dstate_setinfo("driver.state", "init.starting");

atexit(exit_cleanup);

/* pick up a default from configure --with-user */
Expand Down Expand Up @@ -996,10 +1006,12 @@ int main(int argc, char **argv)
* when its a pdu! */
dstate_setinfo("device.type", "ups");

dstate_setinfo("driver.state", "init.device");
upsdrv_initups();
dstate_setinfo("driver.state", "init.quiet");

/* UPS is detected now, cleanup upon exit */
atexit(upsdrv_cleanup);
atexit(exit_upsdrv_cleanup);

/* now see if things are very wrong out there */
if (upsdrv_info.status == DRV_BROKEN) {
Expand All @@ -1023,8 +1035,11 @@ int main(int argc, char **argv)
syslogbit_set();

/* get the base data established before allowing connections */
dstate_setinfo("driver.state", "init.info");
upsdrv_initinfo();
dstate_setinfo("driver.state", "init.updateinfo");
upsdrv_updateinfo();
dstate_setinfo("driver.state", "init.quiet");

if (dstate_getinfo("driver.flag.ignorelb")) {
int have_lb_method = 0;
Expand Down Expand Up @@ -1154,12 +1169,15 @@ int main(int argc, char **argv)
gettimeofday(&timeout, NULL);
timeout.tv_sec += poll_interval;

dstate_setinfo("driver.state", "updateinfo");
upsdrv_updateinfo();
dstate_setinfo("driver.state", "quiet");

/* Dump the data tree (in upsc-like format) to stdout and exit */
if (dump_data) {
/* Wait for 'dump_data' update loops to ensure data completion */
if (update_count == dump_data) {
dstate_setinfo("driver.state", "dumping");
dstate_dump();
exit_flag = 1;
}
Expand Down

0 comments on commit 10be1a9

Please sign in to comment.