[MDEV-16084] Calling exit() from a signal handler is unsafe Created: 2018-05-03  Updated: 2018-05-03  Resolved: 2018-05-03

Status: Closed
Project: MariaDB Server
Component/s: Tests
Fix Version/s: 10.0.36, 10.1.33, 10.2.15, 10.3.7

Type: Task Priority: Major
Reporter: Vladislav Vaintroub Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None


 Description   

marko noticed a deadlock in safe_process, in exit() from a signal hander.

Quoth the StackOverflow https://stackoverflow.com/a/8833602/547065 talking about async-signal-safe-functions in POSIX: "...you can see functions _Exit(), _exit() and abort(), but notably not exit(). So you shalt not call it from a signal handler."

See also http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html

Thread 1 (Thread 0x7f1e8904e740 (LWP 6393)):
#0  __lll_lock_wait_private ()
    at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
#1  0x00007f1e87f8371b in __run_exit_handlers (status=5, 
    listp=0x7f1e88300718 <__exit_funcs>, 
    run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true)
    at exit.c:56
#2  0x00007f1e87f8392a in __GI_exit (status=<optimized out>) at exit.c:139
#3  0x0000558b27bce288 in kill_child (was_killed=false)
    at /mariadb/10.3/mysql-test/lib/My/SafeProcess/safe_process.cc:119
#4  0x0000558b27bce32e in handle_signal (sig=15)
    at /mariadb/10.3/mysql-test/lib/My/SafeProcess/safe_process.cc:139
#5  <signal handler called>
#6  __run_exit_handlers (status=0, listp=0x7f1e88300718 <__exit_funcs>, 
    run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true)
    at exit.c:120
#7  0x00007f1e87f8392a in __GI_exit (status=<optimized out>) at exit.c:139
#8  0x0000558b27bce249 in kill_child (was_killed=true)
    at /mariadb/10.3/mysql-test/lib/My/SafeProcess/safe_process.cc:111
#9  0x0000558b27bce32e in handle_signal (sig=17)
    at /mariadb/10.3/mysql-test/lib/My/SafeProcess/safe_process.cc:139
#10 <signal handler called>
#11 0x00007f1e88010404 in __GI___nanosleep (
    requested_time=requested_time@entry=0x7ffe7a09e860, 
    remaining=remaining@entry=0x7ffe7a09e860)
    at ../sysdeps/unix/sysv/linux/nanosleep.c:28
#12 0x00007f1e8801030a in __sleep (seconds=0) at ../sysdeps/posix/sleep.c:55
#13 0x0000558b27bce9cf in main (argc=10, argv=0x7ffe7a09eb08)
    at /mariadb/10.3/mysql-test/lib/My/SafeProcess/safe_process.cc:301


Generated at Thu Feb 08 08:26:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.