Junbo-Zheng opened a new pull request, #3784:
URL: https://github.com/apache/nuttx-apps/pull/3784

   ## Summary
   
   `monkey` did not register any signal handler, so `kill -15 <pid>` ran the 
kernel default action and terminated the task immediately, skipping the 
`monkey_delete()` cleanup path (recorder data not flushed, resources not 
released).
   
   This blocks SIGTERM at startup via `sigprocmask()` and adds it to the 
`sigtimedwait()` set in `monkey_wait()`: a blocked signal is never swallowed by 
a 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()`.
   
   ## Impact
   
   - **Users**: monkey now exits through its cleanup path on SIGTERM instead of 
being killed by the default action; behavior of the monkey test tool only.
   - **Build**: None -- no build system or Kconfig change.
   - **Hardware**: None -- `graphics/input/monkey` only, no board code.
   - **Documentation**: None.
   - **Security & Compatibility**: None.
   
   ## 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 &
       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 Signal" with SIGMASK 
0x8000, i.e. SIGTERM blocked while sitting in sigtimedwait):
   
       TID   PID  PPID PRI POLICY   TYPE    NPX ST        STACK COMMAND
         0     0     0   0 FIFO     Kthread   - Ready              
0000000000000000 0069584 Idle_Task
         1     0     0 224 FIFO     Kthread   - Wa00000 0067456 sim_loop_wq 
0x71204b2003f00x71204b200478
         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      - Ru00000 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      - Wa08000 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 ST        STACK COMMAND
         0     0     0   0 FIFO     Kthread   - Re00000 0069584 Idle_Task
         1     0     0 224 FIFO     Kthread   - Wa00000 0067456 sim_loop_wq 
0x71204b2003f0 0x71204b200478
         2     0     0 224 FIFO     Kthread   - Wa00000 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      - Wa08000 0069448 monkey -t 0x12 
-p 100-300 -s454x454 -b 0
   
   After "kill -15 11" the second instance exits the same way and no monkey 
task remains in ps. A new instance started after both kills runs normally and 
is again stopped cleanly by kill -15.
   
   Signed-off-by: Junbo Zheng <[email protected]>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to