Repository navigation
Description
Summary
When a continuous termux-sensor -s … stream is stopped by killing the CLI process (broken output socket) instead of sending termux-sensor -c first, sensor listeners stay registered in Termux:API. A subsequent termux-sensor -c then prints Sensor cleanup unnecessary and does not unregister, so gravity/accelerometer stay occupied until Termux:API (and often Termux) are force-stopped.
Expected
- Closing/killing the streaming client should unregister listeners (or otherwise release sensors).
termux-sensor -cshould always unregister listeners if any are still registered, even whenoutputWriteris already null.
Actual
From current SensorAPI.java:
SensorOutputWritererror path only nullsoutputWriterviaonErrorListener— it does not callunregisterListener.cleanupHandler(-c) only unregisters whenoutputWriter != null:
if (outputWriter != null) {
outputWriter.interrupt();
outputWriter = null;
sensorManager.unregisterListener(sensorEventListener);
result.message = "Sensor cleanup successful!";
} else {
result.message = "Sensor cleanup unnecessary";
}So the failure order is:
termux-sensor -s gravity -d 100(stream)- Kill the CLI → socket error →
outputWriter = null, listeners still registered termux-sensor -c→ “cleanup unnecessary” → sensors still held
Contrast with SensorReaderService.cleanup() / onDestroy(), which always unregisters when sensorManager != null.
Repro
# terminal A
termux-sensor -s gravity -d 100
# terminal B — kill the PID of the process in A, then:
termux-sensor -c
# often: Sensor cleanup unnecessary
# sensors remain stuck for other apps / a new termux-sensor -s until force-stopSuggested fix
- In the
SensorOutputWritererror / finish path: alwaysunregisterListener(same ascleanup()). - In
cleanupHandler: always unregister if listeners may still be active (do not gate solely onoutputWriter != null), or track a separate “listening” flag.
Impact / consumers
fount’s Termux logo gravity (termux-sensor child process) must call -c before killing the stream CLI to avoid this. After a kill-first leak, -c cannot recover without force-stopping apps.
When this is fixed upstream, clients can still keep -c-before-kill as the documented stop sequence; kill-then--c and abrupt CLI death should also release sensors.
Follow-up for fount (when closed)
After upstream fix lands in a Termux:API release:
- Re-check
imgs/icon_anime/gravity_acquire/termux.mjsstop path — keep-cbefore kill (correct API usage), but abrupt kill / exit-only paths should no longer brick sensors. - Optional: simplify or drop process-
exitbelt-and-suspenders if no longer needed for this leak. - Manual Termux: start
fount logo, kill-sCLI without-c, confirm sensors still release /-crecovers.
Activity