The nxstyle check on CI flagged three spots in monkey_main.c where a
declaration block runs directly into the following statement. Insert a
blank line after the declarations at each location; no logic change.
Fixes the Check job failure on PR #3784:
https://github.com/apache/nuttx-apps/actions/runs/34935981535/job/104273851956?pr=3784
Before:
```
graphics/input/monkey/monkey_main.c:223:2: error: Missing blank line after declarations
graphics/input/monkey/monkey_main.c:363:2: error: Missing blank line after declarations
graphics/input/monkey/monkey_main.c:526:6: error: Missing blank line after declarations
```
After:
```
nxstyle monkey_main.c -> exit 0
```
Assisted-by: Claude Code (GLM-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
Block SIGTERM at startup and add it to the sigtimedwait() set in
monkey_wait(): a blocked signal is never swallowed by the handler, it
either wakes the in-progress wait or stays pending on the task until
the next sigtimedwait() returns it immediately, so the exit through
the regular monkey_delete() cleanup path is deterministic. Because
the kernel keeps the signal mask and pending queue per task, sibling
monkey instances (e.g. multiple instances started for different
input devices) each stop independently, and no shared state is
involved.
Also add a signal_handler() that logs the received signal and
register it for SIGTSTP/SIGCONT/SIGTERM, so these signals never fall
back to their default actions and stay consumable by sigtimedwait()
/ sigwaitinfo().
Before:
kill -15 <pid> terminates the task via the default SIGTERM action
with no cleanup: no "monkey_delete: OK" is ever printed.
After:
kill -15 <pid> exits within one loop iteration (<= one event period,
100-500ms by default) via monkey_delete(), independently for each
running instance, and restarting monkey works.
Testing:
Built and verified on the NuttX simulator (host: Ubuntu 22.04):
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
# enable in build/.config:
# CONFIG_INPUT=y
# CONFIG_GRAPHICS_INPUT_MONKEY=y
# CONFIG_NSH_MAXARGUMENTS=16
ninja -C build olddefconfig && ninja -C build
./build/nuttx
Run in the nsh prompt (uinput injection mode):
nsh> monkey -t 0x11 -p 100-300 -s 454x454 & (uinput touch)
nsh> monkey -t 0x12 -p 100-300 -s 454x454 -b 0 & (uinput button)
nsh> ps
nsh> kill -15 <pid>
ps with both instances running (each monkey task shows "Waiting
Signal" with SIGMASK 0x8000, i.e. SIGTERM blocked while sitting in
sigtimedwait):
TID PID PPID PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK COMMAND
0 0 0 0 FIFO Kthread - Ready 0000000000000000 0069584 Idle_Task
1 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
2 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
4 4 0 100 FIFO Task - Waiting Semaphore 0000000000000000 0067496 init_main
9 9 4 100 FIFO Task - Running 0000000000000000 0067504 sh
10 10 9 110 FIFO Task - Waiting Signal 0000000000008000 0069472 monkey -t 0x11 -p 100-300 -s 454x454
11 11 9 110 FIFO Task - Waiting Signal 0000000000008000 0069448 monkey -t 0x12 -p 100-300 -s 454x454 -b 0
After "kill -15 10" (touch instance exits, button instance
unaffected):
nsh> kill -15 10
[monkey] monkey_wait: Recv sig: SIGTERM
[monkey] monkey_delete: OK
nsh> ps
TID PID PPID PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK COMMAND
0 0 0 0 FIFO Kthread - Ready 0000000000000000 0069584 Idle_Task
1 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
2 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
4 4 0 100 FIFO Task - Waiting Semaphore 0000000000000000 0067496 init_main
9 9 4 100 FIFO Task - Running 0000000000000000 0067504 sh
11 11 9 110 FIFO Task - Waiting Signal 0000000000008000 0069448 monkey -t 0x12 -p 100-300 -s 454x454 -b 0
After "kill -15 11" (second instance exits the same way, no monkey
task left):
nsh> kill -15 11
[monkey] monkey_wait: Recv sig: SIGTERM
[monkey] monkey_delete: OK
nsh> ps
TID PID PPID PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK COMMAND
0 0 0 0 FIFO Kthread - Ready 0000000000000000 0069584 Idle_Task
1 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
2 0 0 224 FIFO Kthread - Waiting Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
4 4 0 100 FIFO Task - Waiting Semaphore 0000000000000000 0067496 init_main
9 9 4 100 FIFO Task - Running 0000000000000000 0067504 sh
A new instance started after both kills (PID 12) runs normally and
is again stopped cleanly by kill -15.
Note: on the simulator the uinput devices register as /dev/utouch
and /dev/ubutton, while monkey opens /dev/input0 and /dev/buttons;
the run above used a local (uncommitted) path patch to work around
this. On a board where the device paths match, no patch is needed.
Assisted-by: Claude Code (glm-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>