Repository navigation
wd_rtsp.sh: read process, socket and CPU state from /proc - #489
Closed
grzesiczek1 wants to merge 1 commit into
Closed
grzesiczek1 wants to merge 1 commit into
grzesiczek1 wants to merge 1 commit into
Conversation
Every 10 s the watchdog ran ps, top and netstat through grep and awk pipelines, about 35 processes per loop on a single-core camera. The checks now use shell builtins only: - one pass over /proc/*/comm finds rRTSPServer and counts h264grabber, rmm, cloud and mqttv4; - established connections on the RTSP port come from /proc/net/tcp and /proc/net/tcp6; - a locked rRTSPServer is detected from utime + stime in /proc/PID/stat instead of "0.0" in top's %CPU column (which top takes from the same counters over 0.1 s). The first sample takes 1 s, the nine that confirm a lock 0.3 s each; - DISABLE_CLOUD is read from system.conf with read. The actions, their order and the log messages are unchanged. Three details differ: - process names are compared exactly; ps | grep rmm also matched any other command line containing "rmm", which could hide a missing rmm; - after check_grabber restarts the grabbers and rRTSPServer, check_rtsp is skipped until the next loop, so it does not judge the old PID; - while a possible lock is being counted the loop had no sleep at all. It now pauses 1 s when no CPU sample was taken in that loop. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alienatedsec
added a commit
that referenced
this pull request
Nov 16, 2026
wd_rtsp.sh: read process, socket and CPU state from /proc Conflicts resolved: kept our MQTT=no guard in check_mqttv4(), which now uses the new /proc-based N_MQTTV4 counter instead of a ps|grep pipeline.
Owner
|
Hi @grzesiczek1 I already merged your pull requests to |
This was referenced Nov 17, 2026
alienatedsec
pushed a commit
that referenced
this pull request
Nov 17, 2026
The MQTT check added with #489 calls get_config in every loop, which runs a subshell plus grep, cut and awk: 4 processes every 10 seconds, also when MQTT is off. Use the read_conf helper from #489 instead, as check_cloud does for DISABLE_CLOUD. The setting is still read in every loop, and mqttv4 is only checked when MQTT=yes. The value is now quoted. Before, with no MQTT line in system.conf (or an empty value) the unquoted empty expansion made the test fail with "unknown operand", the guard did not return, and mqttv4 was restarted anyway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to point 1 of #485; the same kind of change was merged for
wd.shinroleoroleo/yi-hack-Allwinner-v2#1200. Every 10 s
wd_rtsp.shrunspsthree times,toptwiceand
netstatonce, each throughgrepandawkpipelines, plusget_config. In a testfixture that is 34–35 new processes per healthy loop, on a single-core camera.
This PR reads the same state with shell builtins:
/proc/*/commper loop findsrRTSPServerand countsh264grabber,rmm,cloudandmqttv4. The h264grabber count keeps the meaning ithas since wd_rtsp.sh: restart grabbers when an expected one is missing #483.
/proc/net/tcpand/proc/net/tcp6, thecondition wd_rtsp.sh: make the locked rRTSPServer check work #482 checks with
netstat.utime + stimefrom/proc/PID/statover asample time, instead of reading
0.0intop's%CPUcolumn.top -n 1takes thatcolumn from the same counters over 0.1 s. The first sample takes 1 s; the nine that
confirm a lock take 0.3 s each (1 s if
sleeptakes no fractions). As before, this runsonly while a client is connected.
DISABLE_CLOUDis still read fromsystem.confin every loop, withreadinsteadof
grep | cut | awk.The actions, their order and the log messages are unchanged. Three details differ:
ps | grep rmmalso matched any other commandline containing
rmm, which would hide a missingrmm.check_grabberrestarts the grabbers and rRTSPServer,check_rtspwaits for thenext loop, so it does not judge the PID it saw before the restart.
COUNTER > 0) the loop has nosleep. If theclients disconnect at that point, the counter is never reset and the loop spins until a
client connects again. The loop now pauses 1 s whenever it took no CPU sample.
Tests
Both versions ran under QEMU with the BusyBox 1.36.1 of a camera running 0.4.1, in their
own PID and network namespace. The daemons are stand-in processes with the right names and
real local TCP sockets. The recovery commands log the action and then really do it on the
stand-ins, so a recovery brings the fixture back to a healthy state.
rebootonly logs.31 checks pass:
cloudmissing whileDISABLE_CLOUD=no;once, for: rRTSPServer missing, one of three h264grabber missing,
rmmmissing,cloudmissing withDISABLE_CLOUD=yes,mqttv4missing, a locked rRTSPServer withclients, and
RTSP=no.Master takes ten 0.1-second samples, so it also suspects a server that was merely idle
for a moment. Here the first sample is one second long, and a restart needs ten samples
in a row without a single CPU tick (3.7 s of sampling). Both restart times come from a fast host; on the camera
the pipelines of master take longer.
On a Yi Outdoor (3.0.0.0A, 0.4.1) a copy of this script with the actions replaced by log
lines ran for 24 hours next to the real watchdog while an NVR recorded over RTSP/TCP: about
7,800 loops, no intended actions (no restart, no "possible locked"), and 692 s of CPU time
for the script itself, 0.8 % of the single core.
🤖 Generated with Claude Code