{"action":"created","comment":{"url":"https://api.github.com/repos/rib/gputop/pulls/comments/59721309","id":59721309,"diff_hunk":"@@ -1623,6 +1630,9 @@ run_ncurses_ui(void *arg)\n     }\n #endif\n \n+    signal(SIGTSTP, &gputop_terminal_window_exit);\n+    signal(SIGINT, &gputop_terminal_window_exit);","path":"gputop/gputop-ncurses.c","position":26,"original_position":26,"commit_id":"4ae66013db603cc07d7c3239518b0b172a7a93d2","original_commit_id":"2cbbbda16ee0639abde84d437e1a7a91a0f4758f","user":{"login":"rib","id":235361,"avatar_url":"https://avatars.githubusercontent.com/u/235361?v=3","gravatar_id":"","url":"https://api.github.com/users/rib","html_url":"https://github.com/rib","followers_url":"https://api.github.com/users/rib/followers","following_url":"https://api.github.com/users/rib/following{/other_user}","gists_url":"https://api.github.com/users/rib/gists{/gist_id}","starred_url":"https://api.github.com/users/rib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rib/subscriptions","organizations_url":"https://api.github.com/users/rib/orgs","repos_url":"https://api.github.com/users/rib/repos","events_url":"https://api.github.com/users/rib/events{/privacy}","received_events_url":"https://api.github.com/users/rib/received_events","type":"User","site_admin":false},"body":"Being a little fussy about what's ok to call inside a signal handler, `perf_tab_leave()` encapsulates quite a bit of code which probably isn't all signal-safe.\r\n\r\nThere's a nifty system call on Linux called `signalfd()` which is good for this kind of case which lets us get an `fd` that we can poll on via the mainloop we have so we can have a callback which doesn't need to be signal-safe.\r\n\r\nIt needs a little more boilerplate, but can be used something like:\r\n```c\r\nsigset_t mask;\r\nsigemptyset (&mask);\r\nsigaddset (&mask, SIGTERM);\r\nsigaddset (&mask, SIGINT);\r\n\r\nif (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {\r\n    fprintf(stderr, \"failed to block default SIGINT handler: %m\");\r\n    return NULL;\r\n}\r\n\r\nint fd = signalfd(-1, &mask, SFD_CLOEXEC);\r\n\r\nuv_poll_init(gputop_mainloop, &signal_poll, fd);\r\nuv_poll_start(&signal_poll, POLLIN, signal_handler_cb);\r\n```\r\n(would need to move down after we initialize `gputop_mainloop` + would e.g. need a static global `uv_poll_t signal_poll;`)\r\n\r\nI don't think we should be responding to SIGSTOP here, just SIGINT and SIGTERM. Ctrl-Z sends a SIGSTOP but that's not supposed to cause a program to exit, it causes it to freeze until a SIGCONT is signaled.","created_at":"2016-04-14T13:58:34Z","updated_at":"2016-04-14T13:58:34Z","html_url":"https://github.com/rib/gputop/pull/152#discussion_r59721309","pull_request_url":"https://api.github.com/repos/rib/gputop/pulls/152","_links":{"self":{"href":"https://api.github.com/repos/rib/gputop/pulls/comments/59721309"},"html":{"href":"https://github.com/rib/gputop/pull/152#discussion_r59721309"},"pull_request":{"href":"https://api.github.com/repos/rib/gputop/pulls/152"}}},"pull_request":{"url":"https://api.github.com/repos/rib/gputop/pulls/152","id":66430791,"html_url":"https://github.com/rib/gputop/pull/152","diff_url":"https://github.com/rib/gputop/pull/152.diff","patch_url":"https://github.com/rib/gputop/pull/152.patch","issue_url":"https://api.github.com/repos/rib/gputop/issues/152","number":152,"state":"open","locked":false,"title":"Gputop fixes","user":{"login":"MidhunKodiyath","id":8572244,"avatar_url":"https://avatars.githubusercontent.com/u/8572244?v=3","gravatar_id":"","url":"https://api.github.com/users/MidhunKodiyath","html_url":"https://github.com/MidhunKodiyath","followers_url":"https://api.github.com/users/MidhunKodiyath/followers","following_url":"https://api.github.com/users/MidhunKodiyath/following{/other_user}","gists_url":"https://api.github.com/users/MidhunKodiyath/gists{/gist_id}","starred_url":"https://api.github.com/users/MidhunKodiyath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MidhunKodiyath/subscriptions","organizations_url":"https://api.github.com/users/MidhunKodiyath/orgs","repos_url":"https://api.github.com/users/MidhunKodiyath/repos","events_url":"https://api.github.com/users/MidhunKodiyath/events{/privacy}","received_events_url":"https://api.github.com/users/MidhunKodiyath/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-14T05:29:03Z","updated_at":"2016-04-14T13:58:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"370d5d6a744b7d859036a956e1c3bd7958fdcc8b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rib/gputop/pulls/152/commits","review_comments_url":"https://api.github.com/repos/rib/gputop/pulls/152/comments","review_comment_url":"https://api.github.com/repos/rib/gputop/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rib/gputop/issues/152/comments","statuses_url":"https://api.github.com/repos/rib/gputop/statuses/4ae66013db603cc07d7c3239518b0b172a7a93d2","head":{"label":"MidhunKodiyath:gputop_fixes","ref":"gputop_fixes","sha":"4ae66013db603cc07d7c3239518b0b172a7a93d2","user":{"login":"MidhunKodiyath","id":8572244,"avatar_url":"https://avatars.githubusercontent.com/u/8572244?v=3","gravatar_id":"","url":"https://api.github.com/users/MidhunKodiyath","html_url":"https://github.com/MidhunKodiyath","followers_url":"https://api.github.com/users/MidhunKodiyath/followers","following_url":"https://api.github.com/users/MidhunKodiyath/following{/other_user}","gists_url":"https://api.github.com/users/MidhunKodiyath/gists{/gist_id}","starred_url":"https://api.github.com/users/MidhunKodiyath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MidhunKodiyath/subscriptions","organizations_url":"https://api.github.com/users/MidhunKodiyath/orgs","repos_url":"https://api.github.com/users/MidhunKodiyath/repos","events_url":"https://api.github.com/users/MidhunKodiyath/events{/privacy}","received_events_url":"https://api.github.com/users/MidhunKodiyath/received_events","type":"User","site_admin":false},"repo":{"id":56103515,"name":"gputop","full_name":"MidhunKodiyath/gputop","owner":{"login":"MidhunKodiyath","id":8572244,"avatar_url":"https://avatars.githubusercontent.com/u/8572244?v=3","gravatar_id":"","url":"https://api.github.com/users/MidhunKodiyath","html_url":"https://github.com/MidhunKodiyath","followers_url":"https://api.github.com/users/MidhunKodiyath/followers","following_url":"https://api.github.com/users/MidhunKodiyath/following{/other_user}","gists_url":"https://api.github.com/users/MidhunKodiyath/gists{/gist_id}","starred_url":"https://api.github.com/users/MidhunKodiyath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MidhunKodiyath/subscriptions","organizations_url":"https://api.github.com/users/MidhunKodiyath/orgs","repos_url":"https://api.github.com/users/MidhunKodiyath/repos","events_url":"https://api.github.com/users/MidhunKodiyath/events{/privacy}","received_events_url":"https://api.github.com/users/MidhunKodiyath/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MidhunKodiyath/gputop","description":"A GPU profiling tool","fork":true,"url":"https://api.github.com/repos/MidhunKodiyath/gputop","forks_url":"https://api.github.com/repos/MidhunKodiyath/gputop/forks","keys_url":"https://api.github.com/repos/MidhunKodiyath/gputop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MidhunKodiyath/gputop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MidhunKodiyath/gputop/teams","hooks_url":"https://api.github.com/repos/MidhunKodiyath/gputop/hooks","issue_events_url":"https://api.github.com/repos/MidhunKodiyath/gputop/issues/events{/number}","events_url":"https://api.github.com/repos/MidhunKodiyath/gputop/events","assignees_url":"https://api.github.com/repos/MidhunKodiyath/gputop/assignees{/user}","branches_url":"https://api.github.com/repos/MidhunKodiyath/gputop/branches{/branch}","tags_url":"https://api.github.com/repos/MidhunKodiyath/gputop/tags","blobs_url":"https://api.github.com/repos/MidhunKodiyath/gputop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MidhunKodiyath/gputop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MidhunKodiyath/gputop/git/refs{/sha}","trees_url":"https://api.github.com/repos/MidhunKodiyath/gputop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MidhunKodiyath/gputop/statuses/{sha}","languages_url":"https://api.github.com/repos/MidhunKodiyath/gputop/languages","stargazers_url":"https://api.github.com/repos/MidhunKodiyath/gputop/stargazers","contributors_url":"https://api.github.com/repos/MidhunKodiyath/gputop/contributors","subscribers_url":"https://api.github.com/repos/MidhunKodiyath/gputop/subscribers","subscription_url":"https://api.github.com/repos/MidhunKodiyath/gputop/subscription","commits_url":"https://api.github.com/repos/MidhunKodiyath/gputop/commits{/sha}","git_commits_url":"https://api.github.com/repos/MidhunKodiyath/gputop/git/commits{/sha}","comments_url":"https://api.github.com/repos/MidhunKodiyath/gputop/comments{/number}","issue_comment_url":"https://api.github.com/repos/MidhunKodiyath/gputop/issues/comments{/number}","contents_url":"https://api.github.com/repos/MidhunKodiyath/gputop/contents/{+path}","compare_url":"https://api.github.com/repos/MidhunKodiyath/gputop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MidhunKodiyath/gputop/merges","archive_url":"https://api.github.com/repos/MidhunKodiyath/gputop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MidhunKodiyath/gputop/downloads","issues_url":"https://api.github.com/repos/MidhunKodiyath/gputop/issues{/number}","pulls_url":"https://api.github.com/repos/MidhunKodiyath/gputop/pulls{/number}","milestones_url":"https://api.github.com/repos/MidhunKodiyath/gputop/milestones{/number}","notifications_url":"https://api.github.com/repos/MidhunKodiyath/gputop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MidhunKodiyath/gputop/labels{/name}","releases_url":"https://api.github.com/repos/MidhunKodiyath/gputop/releases{/id}","deployments_url":"https://api.github.com/repos/MidhunKodiyath/gputop/deployments","created_at":"2016-04-12T22:55:40Z","updated_at":"2016-04-12T22:55:43Z","pushed_at":"2016-04-14T05:12:57Z","git_url":"git://github.com/MidhunKodiyath/gputop.git","ssh_url":"git@github.com:MidhunKodiyath/gputop.git","clone_url":"https://github.com/MidhunKodiyath/gputop.git","svn_url":"https://github.com/MidhunKodiyath/gputop","homepage":"","size":2622,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rib:master","ref":"master","sha":"54246c442c3185da9af56474e2ac7317a09b603e","user":{"login":"rib","id":235361,"avatar_url":"https://avatars.githubusercontent.com/u/235361?v=3","gravatar_id":"","url":"https://api.github.com/users/rib","html_url":"https://github.com/rib","followers_url":"https://api.github.com/users/rib/followers","following_url":"https://api.github.com/users/rib/following{/other_user}","gists_url":"https://api.github.com/users/rib/gists{/gist_id}","starred_url":"https://api.github.com/users/rib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rib/subscriptions","organizations_url":"https://api.github.com/users/rib/orgs","repos_url":"https://api.github.com/users/rib/repos","events_url":"https://api.github.com/users/rib/events{/privacy}","received_events_url":"https://api.github.com/users/rib/received_events","type":"User","site_admin":false},"repo":{"id":27882749,"name":"gputop","full_name":"rib/gputop","owner":{"login":"rib","id":235361,"avatar_url":"https://avatars.githubusercontent.com/u/235361?v=3","gravatar_id":"","url":"https://api.github.com/users/rib","html_url":"https://github.com/rib","followers_url":"https://api.github.com/users/rib/followers","following_url":"https://api.github.com/users/rib/following{/other_user}","gists_url":"https://api.github.com/users/rib/gists{/gist_id}","starred_url":"https://api.github.com/users/rib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rib/subscriptions","organizations_url":"https://api.github.com/users/rib/orgs","repos_url":"https://api.github.com/users/rib/repos","events_url":"https://api.github.com/users/rib/events{/privacy}","received_events_url":"https://api.github.com/users/rib/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rib/gputop","description":"A GPU profiling tool","fork":false,"url":"https://api.github.com/repos/rib/gputop","forks_url":"https://api.github.com/repos/rib/gputop/forks","keys_url":"https://api.github.com/repos/rib/gputop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rib/gputop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rib/gputop/teams","hooks_url":"https://api.github.com/repos/rib/gputop/hooks","issue_events_url":"https://api.github.com/repos/rib/gputop/issues/events{/number}","events_url":"https://api.github.com/repos/rib/gputop/events","assignees_url":"https://api.github.com/repos/rib/gputop/assignees{/user}","branches_url":"https://api.github.com/repos/rib/gputop/branches{/branch}","tags_url":"https://api.github.com/repos/rib/gputop/tags","blobs_url":"https://api.github.com/repos/rib/gputop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rib/gputop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rib/gputop/git/refs{/sha}","trees_url":"https://api.github.com/repos/rib/gputop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rib/gputop/statuses/{sha}","languages_url":"https://api.github.com/repos/rib/gputop/languages","stargazers_url":"https://api.github.com/repos/rib/gputop/stargazers","contributors_url":"https://api.github.com/repos/rib/gputop/contributors","subscribers_url":"https://api.github.com/repos/rib/gputop/subscribers","subscription_url":"https://api.github.com/repos/rib/gputop/subscription","commits_url":"https://api.github.com/repos/rib/gputop/commits{/sha}","git_commits_url":"https://api.github.com/repos/rib/gputop/git/commits{/sha}","comments_url":"https://api.github.com/repos/rib/gputop/comments{/number}","issue_comment_url":"https://api.github.com/repos/rib/gputop/issues/comments{/number}","contents_url":"https://api.github.com/repos/rib/gputop/contents/{+path}","compare_url":"https://api.github.com/repos/rib/gputop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rib/gputop/merges","archive_url":"https://api.github.com/repos/rib/gputop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rib/gputop/downloads","issues_url":"https://api.github.com/repos/rib/gputop/issues{/number}","pulls_url":"https://api.github.com/repos/rib/gputop/pulls{/number}","milestones_url":"https://api.github.com/repos/rib/gputop/milestones{/number}","notifications_url":"https://api.github.com/repos/rib/gputop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rib/gputop/labels{/name}","releases_url":"https://api.github.com/repos/rib/gputop/releases{/id}","deployments_url":"https://api.github.com/repos/rib/gputop/deployments","created_at":"2014-12-11T17:19:45Z","updated_at":"2016-03-28T11:22:21Z","pushed_at":"2016-04-14T05:29:03Z","git_url":"git://github.com/rib/gputop.git","ssh_url":"git@github.com:rib/gputop.git","clone_url":"https://github.com/rib/gputop.git","svn_url":"https://github.com/rib/gputop","homepage":"","size":2740,"stargazers_count":10,"watchers_count":10,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":24,"forks":8,"open_issues":24,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rib/gputop/pulls/152"},"html":{"href":"https://github.com/rib/gputop/pull/152"},"issue":{"href":"https://api.github.com/repos/rib/gputop/issues/152"},"comments":{"href":"https://api.github.com/repos/rib/gputop/issues/152/comments"},"review_comments":{"href":"https://api.github.com/repos/rib/gputop/pulls/152/comments"},"review_comment":{"href":"https://api.github.com/repos/rib/gputop/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rib/gputop/pulls/152/commits"},"statuses":{"href":"https://api.github.com/repos/rib/gputop/statuses/4ae66013db603cc07d7c3239518b0b172a7a93d2"}}}}