Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report full path to driver socket (when we listen or fail to connect) #2771

Merged
merged 11 commits into from
Jan 19, 2025

Conversation

jimklimov
Copy link
Member

@jimklimov jimklimov commented Jan 18, 2025

Follows up from #2764 discussion.

Also reshuffle path-related char arrays to use a common NUT_PATH_MAX large enough for different platforms.
Note that internally data server and driver programs generally deal with short base filenames of the sockets (e.g. in ups->fn values), assuming that they chdir into the state path first. When people build custom NUT and mix some things from that build and others from packaging, they are at risk of using different state paths in different programs (e.g. /var/state/ups and (/var)/run/nut) and this change should help discover and rectify this in troubleshooting, or rule it out as not the problem in a discussed case.

Examples of output from make check-NIT-sandbox-devel:

  • upsd starting, not seeing UPSes:
Sun Jan 19 10:15:55 UTC 2025 [DEBUG] [sandbox] Tried to start UPSD as PID 953682
Network UPS Tools upsd 2.8.2.1902-1902-gd1fb34894 (development iteration after 2.8.2)
listening on localhost port 12345
not listening on 127.0.0.1 port 12345
listening on ::1 port 12345
Can't connect to UPS [UPS2] (/home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS2): No such file or directory
Can't connect to UPS [UPS1] (/home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS1): No such file or directory
Can't connect to UPS [dummy] (/home/jim/nut/tests/NIT/tmp/run/dummy-ups-dummy): No such file or directory
Found 3 UPS defined in ups.conf
/usr/local/ups/share/cmdvartab not found - disabling descriptions
  • Drivers started a bit later:
Network UPS Tools 2.8.2.1902-1902-gd1fb34894 (development iteration after 2.8.2) - Device simulation and repeater driver 0.20
Network UPS Tools 2.8.2.1902-1902-gd1fb34894 (development iteration after 2.8.2) - Device simulation and repeater driver 0.20
Network UPS Tools 2.8.2.1902-1902-gd1fb34894 (development iteration after 2.8.2) - Device simulation and repeater driver 0.20
Listening on socket /home/jim/nut/tests/NIT/tmp/run/dummy-ups-dummy
Running as foreground process, but saving a PID file anyway
Listening on socket /home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS1
Running as foreground process, but saving a PID file anyway
Listening on socket /home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS2
Running as foreground process, but saving a PID file anyway
sock_connect: enabling asynchronous mode (auto)
sock_connect: enabling asynchronous mode (auto)
sock_connect: enabling asynchronous mode (auto)
  • ...and upsd sees them:
Connected to UPS [dummy]: dummy-ups-dummy
Connected to UPS [UPS1]: dummy-ups-UPS1
Connected to UPS [UPS2]: dummy-ups-UPS2
  • driver killed off later, while upsd is running:
  13.069585     [D2:953915] mainloop: polling 6 filedescriptors
Signal 15: exiting
13.603506   [D2:953915] mainloop: polling 6 filedescriptors
  13.603652     [D1:953915] mainloop: UPS [UPS1] is not currently connected, trying to reconnect
  13.603679     [D2:953915] sstate_connect: preparing UNIX socket dummy-ups-UPS1
  13.603708     [D2:953915] sstate_connect: failed to connect() UNIX socket dummy-ups-UPS1 (/home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS1)
  13.603738     Can't connect to UPS [UPS1] (/home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS1): No such file or directory
  13.603762     [D1:953915] mainloop: UPS [UPS1] is still not connected (FD -1)
  13.603767     [D2:953915] mainloop: polling 5 filedescriptors
...
  • restarted the missing driver:
...
  45.372413     [D1:954304] mainloop: UPS [UPS1] is not currently connected, trying to reconnect
  45.372460     [D2:954304] sstate_connect: preparing UNIX socket dummy-ups-UPS1
  45.372486     [D2:954304] sstate_connect: failed to connect() UNIX socket dummy-ups-UPS1 (/home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS1)
  45.372521     [D1:954304] mainloop: UPS [UPS1] is still not connected (FD -1)
  45.372544     [D2:954304] mainloop: polling 5 filedescriptors
   1.004226     [D1:954347] entering parse_data_file()
   1.004309     [D1:954347] leaving (paused)...
   1.004438     Listening on socket /home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS1
   1.004579     [D2:954347] dstate_init: sock /home/jim/nut/tests/NIT/tmp/run/dummy-ups-UPS1 open on fd 4
   1.004638     Running as foreground process, not saving a PID file
   1.004710     [D1:954347] Driver initialization completed, beginning regular infinite loop
   1.004771     [D1:954347] upsnotify: notify about state NOTIFY_STATE_READY_WITH_PID with libsystemd: was requested, but not running as a service unit now, will not spam more about it
   1.004780     [D1:954347] upsnotify: failed to notify about state NOTIFY_STATE_READY_WITH_PID: no notification tech defined, will not spam more about it
   1.004787     [D1:954347] upsnotify: logged the systemd watchdog situation once, will not spam more about it
   1.004798     [D1:954347] upsdrv_updateinfo...
  46.373262     [D1:954304] mainloop: UPS [UPS1] is not currently connected, trying to reconnect
  46.373311     [D2:954304] sstate_connect: preparing UNIX socket dummy-ups-UPS1
  46.373354     Connected to UPS [UPS1]: dummy-ups-UPS1
  46.373382     [D1:954304] mainloop: UPS [UPS1] is now connected as FD 8
  46.373388     [D2:954304] mainloop: polling 5 filedescriptors
  46.482778     [D2:954304] write: [destfd=7] [len=26] [VAR dummy ups.status "OB"]
  46.482819     [D2:954304] mainloop: polling 6 filedescriptors
   2.004960     [D1:954347] entering parse_data_file()
   2.005027     [D1:954347] leaving (paused)...
   2.005086     sock_connect: enabling asynchronous mode (auto)
   2.005128     [D3:954347] sock_connect: new connection on fd 5
   2.005165     [D2:954347] send_to_one: sending SETINFO battery.charge "90"
   2.005208     [D2:954347] send_to_one: sending SETFLAGS battery.charge RW
   2.005247     [D2:954347] send_to_one: sending SETINFO battery.charge.low "30"
  46.852973     [D2:954304] mainloop: polling 6 filedescriptors
...
  • Final exit of upsd with one driver not connected (invalid FD, killed off again):
...
 473.982332   mainloop: Interrupted system call
 473.982380     Signal 2: exiting
 473.982390     [D1:953915] upsd_cleanup: starting the end-game
 473.982445     [D1:953915] driver_free: forgetting UPS [dummy] (FD 5)
 473.982491     [D1:953915] driver_free: forgetting UPS [UPS1] (FD -1)
 473.982516     [D1:953915] driver_free: forgetting UPS [UPS2] (FD 6)
 473.982569     [D1:953915] upsd_cleanup: finished

@jimklimov jimklimov added enhancement refactor/fightwarn PR or issue proposal to improve code maintainability without functional changes, or to fix warnings C-str Issues and PRs about C/C++ methods, headers and data types dealing with strings and memory blocks labels Jan 18, 2025
@jimklimov jimklimov added this to the 2.8.3 milestone Jan 18, 2025
@jimklimov jimklimov merged commit cb499ae into networkupstools:master Jan 19, 2025
30 checks passed
@jimklimov jimklimov deleted the issue-2764 branch January 19, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-str Issues and PRs about C/C++ methods, headers and data types dealing with strings and memory blocks enhancement refactor/fightwarn PR or issue proposal to improve code maintainability without functional changes, or to fix warnings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant