Skip to content

common/common.c: compareprocname(): Linux /proc/X/exe pseudo-symlink can end with "(deleted)"…#3021

Merged
jimklimov merged 1 commit intonetworkupstools:masterfrom
jimklimov:issue-3020
Jul 17, 2025
Merged

common/common.c: compareprocname(): Linux /proc/X/exe pseudo-symlink can end with "(deleted)"…#3021
jimklimov merged 1 commit intonetworkupstools:masterfrom
jimklimov:issue-3020

Conversation

@jimklimov
Copy link
Copy Markdown
Member

@jimklimov jimklimov commented Jul 16, 2025

…if the program was removed or replaced, breaking detection that a PID describes a running copy of our program

Before this fix, the running process was not detected and signaled (e.g. for config reload):

:; ./server/upsd -DDDDDD -c reload
Network UPS Tools upsd 2.8.3.544.37-581+gbc306fb5a (development iteration after 2.8.3)
   0.000000     [D3] getprocname: /proc is an accessible directory, investigating
   0.000021     [D3] getprocname: located symlink for PID 3245141 at: /proc/3245141/exe
   0.000032     [D1] getprocname: determined process name for PID 3245141: /usr/local/ups/sbin/upsd (deleted)
   0.000037     [D1] compareprocname: did not find any match of program names for PID 3245141 of '/usr/local/ups/sbin/upsd (deleted)'=>'upsd (deleted)' and checked 'upsd'=>'upsd'
   0.000050     [D3] getprocname: /proc is an accessible directory, investigating
   0.000065     [D3] getprocname: located symlink for PID 3253997 at: /proc/3253997/exe
   0.000074     [D1] getprocname: determined process name for PID 3253997: /usr/local/src/nut-pve/server/upsd
   0.000079     [D1] compareprocname: did not find any match of program names for PID 3245141 of '/usr/local/ups/sbin/upsd (deleted)'=>'upsd (deleted)' and checked '/usr/local/src/nut-pve/server/upsd'=>'upsd'
   0.000083     [D1] sendsignalpid: ran at least one check, and all such checks found a process name for PID 3245141 and failed to match: found procname='/usr/local/ups/sbin/upsd (deleted)', expected progname='upsd' (res=0), current progname='/usr/local/src/nut-pve/server/upsd' (res=0)
   0.000086     Tried to signal PID 3245141 which exists but is not of expected program 'upsd' nor current '/usr/local/src/nut-pve/server/upsd'
   0.000090     [D1] Just failed to send signal, no daemon was running
   0.000093     Failed to signal the currently running daemon (if any)
   0.000095     Try 'systemctl reload nut-server.service' or add '-P $PID' argument

With this fix:

:; ./server/upsd -DDDDDD -c reload
Network UPS Tools upsd 2.8.3.544.1-545+gc504cc2f86 (development iteration after 2.8.3)
   0.000000     [D3] getprocname: /proc is an accessible directory, investigating
   0.000029     [D3] getprocname: located symlink for PID 3245141 at: /proc/3245141/exe
   0.000043     [D1] getprocname: determined process name for PID 3245141: /usr/local/ups/sbin/upsd (deleted)
   0.000051     [D2] compareprocname: re-evaluate the substring without a special tail: '/usr/local/ups/sbin/upsd (deleted)'=>'/usr/local/ups/sbin/upsd'
   0.000062     [D1] compareprocname: case-sensitive base name hit for PID 3245141 of '/usr/local/ups/sbin/upsd'=>'upsd' and checked 'upsd'=>'upsd'
   0.000066     [D1] compareprocname: original program file of running PID 3245141 named '/usr/local/ups/sbin/upsd (deleted)' was removed or replaced, but matches our 'upsd'
   0.000080     [D1] Signaled old daemon OK

journalctl>
Jul 16 23:16:22 pve nut-server[3245141]: mainloop: Interrupted system call
Jul 16 23:16:22 pve nut-server[3245141]: SIGHUP: reloading configuration
Jul 16 23:16:22 pve nut-server[3245141]: Applying DEBUG_MIN 6 from upsd.conf
...

…(deleted)" if the program was removed or replaced

Signed-off-by: Jim Klimov <[email protected]>
@jimklimov jimklimov added enhancement service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug Linux Some issues are specific to Linux as a platform portability We want NUT to build and run everywhere possible labels Jul 16, 2025
@jimklimov jimklimov added this to the 2.8.4 milestone Jul 16, 2025
@AppVeyorBot
Copy link
Copy Markdown

@jimklimov jimklimov merged commit ded7789 into networkupstools:master Jul 17, 2025
30 checks passed
@jimklimov jimklimov deleted the issue-3020 branch July 17, 2025 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Linux Some issues are specific to Linux as a platform portability We want NUT to build and run everywhere possible service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants