{"id":196,"date":"2012-11-26T15:43:52","date_gmt":"2012-11-26T15:43:52","guid":{"rendered":"http:\/\/www.selinuxplus.com\/?p=196"},"modified":"2012-11-26T15:43:52","modified_gmt":"2012-11-26T15:43:52","slug":"signal-by-epoll-etc","status":"publish","type":"post","link":"http:\/\/www.selinuxplus.com\/?p=196","title":{"rendered":"signal  by epoll .etc"},"content":{"rendered":"<p>Interruption of System Calls and Library Functions by Signal Handlers<\/p>\n<p>If a signal handler is invoked while a system call or library function call is blocked, then either:<br \/>\n*<br \/>\nthe call is automatically restarted after the signal handler returns; or<br \/>\n*<br \/>\nthe call fails with the error EINTR.<br \/>\nWhich of these two behaviors occurs depends on the interface and whether or not the signal handler was established using the SA_RESTART flag (see sigaction(2)). The details vary across UNIX systems; below, the details for Linux.<\/p>\n<p>If a blocked call to one of the following interfaces is interrupted by a signal handler, then the call will be automatically restarted after the signal handler returns if the SA_RESTART flag was used; otherwise the call will fail with the error EINTR:<\/p>\n<p>*<br \/>\nread(2), readv(2), write(2), writev(2), and ioctl(2) calls on &#8220;slow&#8221; devices. A &#8220;slow&#8221; device is one where the I\/O call may block for an indefinite time, for example, a terminal, pipe, or socket. (A disk is not a slow device according to this definition.) If an I\/O call on a slow device has already transferred some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred).<br \/>\n*<br \/>\nopen(2), if it can block (e.g., when opening a FIFO; see fifo(7)).<br \/>\n*<br \/>\nwait(2), wait3(2), wait4(2), waitid(2), and waitpid(2).<br \/>\n*<br \/>\nSocket interfaces: accept(2), connect(2), recv(2), recvfrom(2), recvmsg(2), send(2), sendto(2), and sendmsg(2), unless a timeout has been set on the socket (see below).<br \/>\n*<br \/>\nFile locking interfaces: flock(2) and fcntl(2) F_SETLKW.<br \/>\n*<br \/>\nPOSIX message queue interfaces: mq_receive(3), mq_timedreceive(3), mq_send(3), and mq_timedsend(3).<br \/>\n*<br \/>\nfutex(2) FUTEX_WAIT (since Linux 2.6.22; beforehand, always failed with EINTR).<br \/>\n*<br \/>\nPOSIX semaphore interfaces: sem_wait(3) and sem_timedwait(3) (since Linux 2.6.22; beforehand, always failed with EINTR).<br \/>\nThe following interfaces are never restarted after being interrupted by a signal handler, regardless of the use of SA_RESTART; they always fail with the error EINTR when interrupted by a signal handler:<\/p>\n<p>*<br \/>\nSocket interfaces, when a timeout has been set on the socket using setsockopt(2): accept(2), recv(2), recvfrom(2), and recvmsg(2), if a receive timeout (SO_RCVTIMEO) has been set; connect(2), send(2), sendto(2), and sendmsg(2), if a send timeout (SO_SNDTIMEO) has been set.<br \/>\n*<br \/>\nInterfaces used to wait for signals: pause(2), sigsuspend(2), sigtimedwait(2), and sigwaitinfo(2).<br \/>\n*<br \/>\nFile descriptor multiplexing interfaces: epoll_wait(2), epoll_pwait(2), poll(2), ppoll(2), select(2), and pselect(2).<br \/>\n*<br \/>\nSystem V IPC interfaces: msgrcv(2), msgsnd(2), semop(2), and semtimedop(2).<br \/>\n*<br \/>\nSleep interfaces: clock_nanosleep(2), nanosleep(2), and usleep(3).<br \/>\n*<br \/>\nread(2) from an inotify(7) file descriptor.<br \/>\n*<br \/>\nio_getevents(2).<br \/>\nThe sleep(3) function is also never restarted if interrupted by a handler, but gives a success return: the number of seconds remaining to sleep.  <\/p>\n<p>Interruption of System Calls and Library Functions by Stop Signals<\/p>\n<p>On Linux, even in the absence of signal handlers, certain blocking interfaces can fail with the error EINTR after the process is stopped by one of the stop signals and then resumed via SIGCONT. This behavior is not sanctioned by POSIX.1, and doesn&#8217;t occur on other systems.<br \/>\nThe Linux interfaces that display this behavior are:<\/p>\n<p>*<br \/>\nSocket interfaces, when a timeout has been set on the socket using setsockopt(2): accept(2), recv(2), recvfrom(2), and recvmsg(2), if a receive timeout (SO_RCVTIMEO) has been set; connect(2), send(2), sendto(2), and sendmsg(2), if a send timeout (SO_SNDTIMEO) has been set.<br \/>\n*<br \/>\nepoll_wait(2), epoll_pwait(2).<br \/>\n*<br \/>\nsemop(2), semtimedop(2).<br \/>\n*<br \/>\nsigtimedwait(2), sigwaitinfo(2).<br \/>\n*<br \/>\nread(2) from an inotify(7) file descriptor.<br \/>\n*<br \/>\nLinux 2.6.21 and earlier: futex(2) FUTEX_WAIT, sem_timedwait(3), sem_wait(3).<br \/>\n*<br \/>\nLinux 2.6.8 and earlier: msgrcv(2), msgsnd(2).<br \/>\n*<br \/>\nLinux 2.4 and earlier: nanosleep(2).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interruption of System Ca&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[30,31,29],"_links":{"self":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/196"}],"collection":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=196"}],"version-history":[{"count":1,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":197,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions\/197"}],"wp:attachment":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}