代码之家  ›  专栏  ›  技术社区  ›  vitaly.v.ch

我需要glibc提供的异步信号安全函数列表

  •  13
  • vitaly.v.ch  · 技术社区  · 15 年前

    4 回复  |  直到 15 年前
        1
  •  15
  •   Airsource Ltd    15 年前

    我敢肯定你一定要去看电影 documentation

    编辑 怎么样 this list 那么?

    从…起 man signal :

    NOTES
    
       The effects of this call in a multi-threaded process are unspecified.
    
    
       The routine handler must be very careful,  since  processing  elsewhere
       was interrupted at some arbitrary point. POSIX has the concept of "safe
       function".  If a signal interrupts  an  unsafe  function,  and  handler
       calls  an  unsafe  function, then the behavior is undefined. Safe func-
       tions are listed explicitly in the various standards.  The POSIX.1-2003
       list is
    
       _Exit()  _exit()  abort()  accept()  access()  aio_error() aio_return()
       aio_suspend() alarm() bind() cfgetispeed() cfgetospeed()  cfsetispeed()
       cfsetospeed() chdir() chmod() chown() clock_gettime() close() connect()
       creat() dup() dup2() execle() execve() fchmod() fchown() fcntl() fdata-
       sync()   fork()   fpathconf()  fstat()  fsync()  ftruncate()  getegid()
       geteuid() getgid() getgroups() getpeername() getpgrp()  getpid()  getp-
       pid()   getsockname()  getsockopt()  getuid()  kill()  link()  listen()
       lseek() lstat()  mkdir()  mkfifo()  open()  pathconf()  pause()  pipe()
       poll()  posix_trace_event()  pselect() raise() read() readlink() recv()
       recvfrom()  recvmsg()  rename()  rmdir()  select()  sem_post()   send()
       sendmsg()  sendto()  setgid()  setpgid() setsid() setsockopt() setuid()
       shutdown()  sigaction()  sigaddset()  sigdelset()  sigemptyset()   sig-
       fillset()  sigismember() signal() sigpause() sigpending() sigprocmask()
       sigqueue() sigset() sigsuspend() sleep() socket()  socketpair()  stat()
       symlink()  sysconf()  tcdrain()  tcflow() tcflush() tcgetattr() tcgetp-
       grp() tcsendbreak() tcsetattr() tcsetpgrp()  time()  timer_getoverrun()
       timer_gettime()   timer_settime()   times()  umask()  uname()  unlink()
       utime() wait() waitpid() write().
    
       According to POSIX, the behaviour of a process is  undefined  after  it
       ignores  a  SIGFPE, SIGILL, or SIGSEGV signal that was not generated by
       the kill(2) or the raise(3) functions.  Integer division  by  zero  has
       undefined result.  On some architectures it will generate a SIGFPE sig-
       nal.  (Also dividing the most  negative  integer  by  -1  may  generate
       SIGFPE.)  Ignoring this signal might lead to an endless loop.
    
       See  sigaction(2)  for  details  on what happens when SIGCHLD is set to
       SIG_IGN.
    
       The use of sighandler_t is a GNU extension.  Various versions  of  libc
       predefine  this  type;  libc4  and  libc5  define  SignalHandler, glibc
       defines sig_t and, when _GNU_SOURCE is defined, also sighandler_t.
    
        2
  •  2
  •   vitaly.v.ch    7 年前

    最后是最新版本的 man 7 signal-safety 包含感兴趣的列表: signal-safety.7.html

        3
  •  1
  •   asveikau    15 年前

    这似乎很难确定,因为您不知道库例程可能决定调用什么随机不安全函数。不同版本的glibc之间的列表也可能不同,或者如果您将其带到另一个类似Unix的系统中,列表也可能不同。似乎您必须分析许多调用堆栈才能找到答案,甚至在版本之间、发行版与发行版之间,这些调用堆栈也可能有点不稳定。

    也许你不是在寻找替代的设计方法,但似乎更好的策略是:如果你的程序有一个事件循环,那么让信号处理程序变得非常愚蠢,只是设置一些事件循环将拾取的状态。这样,您就可以在信号处理程序之外完成有意义的工作。

    比如说,你有一个 poll() 在某处兜圈子。也许您可以包含一个信号处理程序可以写入的管道。然后 投票()

        4
  •  0
  •   Community datashaman    4 年前

    我要在撞车时放卷

    如果您试图捕获堆栈跟踪:

    • 典型的 abort

    • 或者,一种粗糙(但信号安全)的方法是 fork exec 执行官 -(之后) -您需要使用 getppid ; 在家长中,你需要 wait 中止

    另一方面,如果您试图在SigSeGV(例如确保C++析构函数被调用等)之后进行“干净”退出,那么您应该警告POSIX称:

    http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03_02 :

    忽略SIGFPE后,进程的行为未定义, 不是由kill()生成的SIGILL、SIGSEGV或SIGBUS信号, sigqueue()或raise()。

    http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03_03 :

    进程从正常状态返回后,其行为未定义 用于SIGBUS、SIGFPE、SIGILL或SIGSEGV的信号捕捉功能