Skip to content

Instantly share code, notes, and snippets.

@kamilion
Created August 17, 2019 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamilion/45fa75a009cf4777ecbdc5494ef69920 to your computer and use it in GitHub Desktop.
Save kamilion/45fa75a009cf4777ecbdc5494ef69920 to your computer and use it in GitHub Desktop.
Micropython usignal.py for phusion passenger's my_init
import ffilib
# Full linux signal list:
#Spec - Default Action - Description
#SIG_DFL = 0
#SIG_IGN = 1
#SIGHUP = 1 # P1990 - Terminate - Hangup detected on controlling terminal or death of controlling process
#SIGINT = 2 # P1990 - Terminate - Interrupt from keyboard
#SIGQUIT = 3 # P1990 - Core dump - Quit from keyboard
#SIGILL = 4 # P1990 - Core dump - Illegal Instruction
#SIGABRT = 5 # P1990 - Core dump - Abort signal from abort(3)
#SIGIOT = 6 # - - Core dump - IOT trap. A synonym for SIGABRT
#SIGBUS = 7 # P2001 - Core dump - Bus error (bad memory access) (Toasty!)
#SIGFPE = 8 # P1990 - Core dump - Floating-point exception
#SIGKILL = 9 # P1990 - Terminate - Kill signal
#SIGUSR1 = 10 # P1990 - Terminate - User-defined signal 1
#SIGSEGV = 11 # P1990 - Core dump - Invalid memory reference (Toasty!)
#SIGUSR2 = 12 # P1990 - Terminate - User-defined signal 2
#SIGPIPE = 13 # P1990 - Terminate - Broken pipe: write to pipe with no readers; see pipe(7) (Toasty!)
#SIGALRM = 14 # P1990 - Terminate - Timer signal from alarm(2)
#SIGTERM = 15 # P1990 - Terminate - Termination signal
#SIGSTKFLT = 16 # - - Terminate - Stack fault on coprocessor (unused) (Toasty!)
#SIGCHLD = 17 # P1990 - Ignore - Child stopped or terminated
#SIGCONT = 18 # P1990 - Continue - Continue process if stopped
#SIGSTOP = 19 # P1990 - Stop - Stop process
#SIGTSTP = 20 # P1990 - Stop - Stop typed at terminal
#SIGTTIN = 21 # P1990 - Stop - Terminal input for background process
#SIGTTOU = 22 # P1990 - Stop - Terminal output for background process
#SIGURG = 23 # P2001 - Ignore - Urgent condition on socket (4.2BSD)
#SIGXCPU = 24 # P2001 - Core dump - CPU time limit exceeded (4.2BSD) (Toasty!)
#SIGXFSZ = 25 # P2001 - Core dump - File size limit exceeded (4.2BSD) (Toasty!)
#SIGVTALRM = 26 # P2001 - Terminate - Virtual alarm clock (4.2BSD)
#SIGPROF = 27 # P2001 - Terminate - Profiling timer expired
#SIGWINCH = 28 # - - Ignore - Window resize signal (4.3BSD, Sun)
#SIGIO = 29 # - - Terminate - I/O now possible (4.2BSD)
#SIGPOLL = 29 # P2001 - Terminate - Pollable event (Sys V). Synonym for SIGIO
#SIGPWR = 30 # - - Terminate - Power failure (System V) (UNUSED) (Toasty!)
#SIGSYS = 31 # P2001 - Core dump - Bad system call (SVr4); See also: seccomp(2) !gettimeofday64?~ (Toasty!)
# Original:
SIG_DFL = 0
SIG_IGN = 1
SIGHUP = 1 # New!
SIGINT = 2
SIGQUIT = 3 # New!
SIGPIPE = 13
SIGTERM = 15
# We need:
# Needed for my_init
SIGALRM = 14
SIGCHLD = 17
SIGCONT = 18
SIGSTOP = 19
# Remote console Window Changed size
SIGWINCH = 28
libc = ffilib.libc()
signal_i = libc.func("i", "signal", "ii")
signal_p = libc.func("i", "signal", "ip")
def signal(n, handler):
if isinstance(handler, int):
return signal_i(n, handler)
import ffi
cb = ffi.callback("v", handler, "i")
return signal_p(n, cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment