{"action":"created","issue":{"url":"https://api.github.com/repos/justincormack/ljsyscall/issues/187","labels_url":"https://api.github.com/repos/justincormack/ljsyscall/issues/187/labels{/name}","comments_url":"https://api.github.com/repos/justincormack/ljsyscall/issues/187/comments","events_url":"https://api.github.com/repos/justincormack/ljsyscall/issues/187/events","html_url":"https://github.com/justincormack/ljsyscall/issues/187","id":113150881,"number":187,"title":"Signal masked with custom handler ignored","user":{"login":"dpino","id":11567,"avatar_url":"https://avatars.githubusercontent.com/u/11567?v=3","gravatar_id":"","url":"https://api.github.com/users/dpino","html_url":"https://github.com/dpino","followers_url":"https://api.github.com/users/dpino/followers","following_url":"https://api.github.com/users/dpino/following{/other_user}","gists_url":"https://api.github.com/users/dpino/gists{/gist_id}","starred_url":"https://api.github.com/users/dpino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpino/subscriptions","organizations_url":"https://api.github.com/users/dpino/orgs","repos_url":"https://api.github.com/users/dpino/repos","events_url":"https://api.github.com/users/dpino/events{/privacy}","received_events_url":"https://api.github.com/users/dpino/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-24T10:56:08Z","updated_at":"2015-10-25T22:13:24Z","closed_at":null,"body":"I'm try to mask a signal with my own handler. Here is my code:\r\n\r\n```lua\r\nlocal S = require(\"syscall\")\r\n\r\nlocal SIGINT = 1\r\n\r\nlocal function handler(signo)\r\n   if signo == SIGINT then\r\n      print(\"Catched SIGINT\")\r\n   end\r\nend\r\n\r\nS.signal(SIGINT, handler)\r\nwhile 1 do S.sleep(1) end\r\n```\r\n\r\nI run it and press Ctrl+C to emit a SIGINT signal. Here's the result:\r\n\r\n```bash\r\n $ luajit test-signal.lua\r\n^Cluajit: ./syscall/linux/c.lua:71: interrupted!\r\nstack traceback:\r\n\t./syscall/linux/c.lua:71: in function 'nanosleep'\r\n\t./syscall/syscalls.lua:849: in function 'nanosleep'\r\n\t./syscall/compat.lua:139: in function 'sleep'\r\n\ttest-signal.lua:12: in main chunk\r\n\t[C]: at 0x004042a0\r\n```\r\n\r\nThe handler is not triggered. I coded a similar test in C. It looks like this:\r\n\r\n```C\r\n#include <stdio.h>\r\n#include <unistd.h>\r\n#include <signal.h>\r\n\r\nvoid handler(int signo)\r\n{\r\n    if (signo == SIGINT) {\r\n        printf(\"Catched SIGINT\\n\");\r\n    }\r\n}\r\n\r\nint main(void)\r\n{\r\n    if (signal(SIGINT, handler) == SIG_ERR) {\r\n        printf(\"Couldn't initialize signal\");\r\n    }\r\n    while (1) sleep(1);\r\n    return 0;\r\n}\r\n```\r\n\r\nThis is the result:\r\n\r\n```bash\r\n$ ./test-signal \r\n^CCatched SIGINT\r\n```\r\n\r\nI expected the Lua test case to work similarly to the C test case. I'm doing anything wrong? Maybe I'm not using the ```signal``` function correctly. My system is Ubuntu 15.04 x86_64 LuaJIT 2.0.4."},"comment":{"url":"https://api.github.com/repos/justincormack/ljsyscall/issues/comments/150979609","html_url":"https://github.com/justincormack/ljsyscall/issues/187#issuecomment-150979609","issue_url":"https://api.github.com/repos/justincormack/ljsyscall/issues/187","id":150979609,"user":{"login":"dpino","id":11567,"avatar_url":"https://avatars.githubusercontent.com/u/11567?v=3","gravatar_id":"","url":"https://api.github.com/users/dpino","html_url":"https://github.com/dpino","followers_url":"https://api.github.com/users/dpino/followers","following_url":"https://api.github.com/users/dpino/following{/other_user}","gists_url":"https://api.github.com/users/dpino/gists{/gist_id}","starred_url":"https://api.github.com/users/dpino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpino/subscriptions","organizations_url":"https://api.github.com/users/dpino/orgs","repos_url":"https://api.github.com/users/dpino/repos","events_url":"https://api.github.com/users/dpino/events{/privacy}","received_events_url":"https://api.github.com/users/dpino/received_events","type":"User","site_admin":false},"created_at":"2015-10-25T22:13:24Z","updated_at":"2015-10-25T22:13:24Z","body":"Thanks, I followed your advice. I coded the example above using `signalfd`. I leave it here for reference:\r\n\r\n```lua\r\nlocal S = require(\"syscall\")\r\nlocal util = S.util\r\n\r\nlocal function empty(sig)\r\n   return type(sig) == \"table\" and #sig == 0\r\nend\r\n\r\nlocal ss = \"int\"\r\nlocal fd = assert(S.signalfd(ss, \"nonblock\"))\r\nassert(S.sigprocmask(\"block\", ss))\r\n\r\nwhile 1 do\r\n   local sig = assert(util.signalfd_read(fd))\r\n   if not empty(sig) then\r\n      if sig[1].int then\r\n         print(\"Cought SIGINT\")\r\n      end\r\n   end\r\nend\r\n```"}}