Fix FreeBSD signal numbers: SIGTSTP, SIGCHLD, SIGCONT and 6 others were hardcoded to Linux values
ober
5d316a5c64006962006d9fdec367a8e026ec75fe
--- a/lib/std/os/signal.sls +++ b/lib/std/os/signal.sls @@ -24,6 +24,7 @@ ;; POSIX kill(pid, sig) (define kill (foreign-procedure "kill" (int int) int)) + ;; Signal numbers that are the same on Linux and FreeBSD (define SIGHUP 1) (define SIGINT 2) (define SIGQUIT 3) @@ -36,31 +37,47 @@ (define SIGPIPE 13) (define SIGALRM 14) (define SIGTERM 15) - (define SIGUSR1 10) - (define SIGUSR2 12) - (define SIGCHLD 17) - (define SIGCONT 18) - (define SIGSTOP 19) - (define SIGTSTP 20) (define SIGTTIN 21) (define SIGTTOU 22) - (define SIGURG 23) (define SIGXCPU 24) (define SIGXFSZ 25) (define SIGVTALRM 26) (define SIGPROF 27) (define SIGWINCH 28) - (define SIGIO 29) - (define SIGSYS 31) + + ;; Signal numbers that differ between Linux and FreeBSD. + ;; Detect platform at load time via uname. + (define %freebsd? + (or (guard (e [#t #f]) + (equal? (machine-type) 'ta6fb)) + (guard (e [#t #f]) + (memq (machine-type) '(ta6fb a6fb ti3fb i3fb tarm64fb arm64fb))) + ;; Fallback for static builds: check for FreeBSD kernel file + (guard (e [#t #f]) + (file-exists? "/boot/kernel/kernel")) + #f)) + + (define SIGUSR1 (if %freebsd? 30 10)) + (define SIGUSR2 (if %freebsd? 31 12)) + (define SIGSYS (if %freebsd? 12 31)) + (define SIGURG (if %freebsd? 16 23)) + (define SIGSTOP (if %freebsd? 17 19)) + (define SIGTSTP (if %freebsd? 18 20)) + (define SIGCONT (if %freebsd? 19 18)) + (define SIGCHLD (if %freebsd? 20 17)) + (define SIGIO (if %freebsd? 23 29)) (define signal-names - '((1 . "SIGHUP") (2 . "SIGINT") (3 . "SIGQUIT") (4 . "SIGILL") + `((1 . "SIGHUP") (2 . "SIGINT") (3 . "SIGQUIT") (4 . "SIGILL") (5 . "SIGTRAP") (6 . "SIGABRT") (8 . "SIGFPE") (9 . "SIGKILL") - (10 . "SIGUSR1") (11 . "SIGSEGV") (12 . "SIGUSR2") (13 . "SIGPIPE") - (14 . "SIGALRM") (15 . "SIGTERM") (17 . "SIGCHLD") (18 . "SIGCONT") - (19 . "SIGSTOP") (20 . "SIGTSTP") (21 . "SIGTTIN") (22 . "SIGTTOU") - (23 . "SIGURG") (24 . "SIGXCPU") (25 . "SIGXFSZ") (26 . "SIGVTALRM") - (27 . "SIGPROF") (28 . "SIGWINCH") (29 . "SIGIO") (31 . "SIGSYS"))) + (,SIGUSR1 . "SIGUSR1") (11 . "SIGSEGV") (,SIGUSR2 . "SIGUSR2") + (13 . "SIGPIPE") (14 . "SIGALRM") (15 . "SIGTERM") + (,SIGCHLD . "SIGCHLD") (,SIGCONT . "SIGCONT") + (,SIGSTOP . "SIGSTOP") (,SIGTSTP . "SIGTSTP") + (21 . "SIGTTIN") (22 . "SIGTTOU") + (,SIGURG . "SIGURG") (24 . "SIGXCPU") (25 . "SIGXFSZ") + (26 . "SIGVTALRM") (27 . "SIGPROF") (28 . "SIGWINCH") + (,SIGIO . "SIGIO") (,SIGSYS . "SIGSYS"))) ;; --- Signal handler registration ---