{"action":"created","comment":{"url":"https://api.github.com/repos/puppetlabs/cfacter/pulls/comments/26538639","id":26538639,"diff_hunk":"@@ -117,46 +130,122 @@ namespace facter { namespace execution {\n             stdout_write.release();\n             stdin_write.release();\n \n-            string result = process_stream([&](string &buffer) {\n+            // Define a reaper that is invoked when we exit this scope\n+            // This ensures that the child get\n+            bool kill_child = true;\n+            bool success = false;\n+            bool signaled = false;\n+            int status = 0;\n+            scope_exit reaper([&]() {\n+                if (kill_child) {\n+                    kill(child, SIGKILL);\n+                }\n+                // Wait for the child to exit\n+                if (waitpid(child, &status, 0) == -1) {\n+                    LOG_DEBUG(\"waitpid failed: %1% (%2%).\", strerror(errno), errno);\n+                    return;\n+                }\n+                if (WIFEXITED(status)) {\n+                    status = static_cast<char>(WEXITSTATUS(status));\n+                    success = status == 0;\n+                    return;\n+                }\n+                if (WIFSIGNALED(status)) {\n+                    signaled = true;\n+                    status = static_cast<char>(WTERMSIG(status));\n+                    return;\n+                }\n+            });\n+\n+            // Set up an interval timer for timeouts\n+            // Note: OSX doesn't implement POSIX per-process timers, so we're stuck with the obsolete POSIX timers API\n+            scope_exit timer_reset;\n+            if (timeout != static_cast<uint32_t>(-1)) {","path":"lib/src/execution/posix/execution.cc","position":87,"original_position":87,"commit_id":"9abeb2629ff65762491d69993a001036f3978473","original_commit_id":"9abeb2629ff65762491d69993a001036f3978473","user":{"login":"MikaelSmith","id":8162496,"avatar_url":"https://avatars.githubusercontent.com/u/8162496?v=3","gravatar_id":"","url":"https://api.github.com/users/MikaelSmith","html_url":"https://github.com/MikaelSmith","followers_url":"https://api.github.com/users/MikaelSmith/followers","following_url":"https://api.github.com/users/MikaelSmith/following{/other_user}","gists_url":"https://api.github.com/users/MikaelSmith/gists{/gist_id}","starred_url":"https://api.github.com/users/MikaelSmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MikaelSmith/subscriptions","organizations_url":"https://api.github.com/users/MikaelSmith/orgs","repos_url":"https://api.github.com/users/MikaelSmith/repos","events_url":"https://api.github.com/users/MikaelSmith/events{/privacy}","received_events_url":"https://api.github.com/users/MikaelSmith/received_events","type":"User","site_admin":false},"body":"So you decided to allow a timeout of 0?","created_at":"2015-03-16T23:47:23Z","updated_at":"2015-03-16T23:47:23Z","html_url":"https://github.com/puppetlabs/cfacter/pull/335#discussion_r26538639","pull_request_url":"https://api.github.com/repos/puppetlabs/cfacter/pulls/335","_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/cfacter/pulls/comments/26538639"},"html":{"href":"https://github.com/puppetlabs/cfacter/pull/335#discussion_r26538639"},"pull_request":{"href":"https://api.github.com/repos/puppetlabs/cfacter/pulls/335"}}},"pull_request":{"url":"https://api.github.com/repos/puppetlabs/cfacter/pulls/335","id":31272094,"html_url":"https://github.com/puppetlabs/cfacter/pull/335","diff_url":"https://github.com/puppetlabs/cfacter/pull/335.diff","patch_url":"https://github.com/puppetlabs/cfacter/pull/335.patch","issue_url":"https://api.github.com/repos/puppetlabs/cfacter/issues/335","number":335,"state":"open","locked":false,"title":"(CFACT-253) Implement timeout option for command execution.","user":{"login":"peterhuene","id":509666,"avatar_url":"https://avatars.githubusercontent.com/u/509666?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhuene","html_url":"https://github.com/peterhuene","followers_url":"https://api.github.com/users/peterhuene/followers","following_url":"https://api.github.com/users/peterhuene/following{/other_user}","gists_url":"https://api.github.com/users/peterhuene/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhuene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhuene/subscriptions","organizations_url":"https://api.github.com/users/peterhuene/orgs","repos_url":"https://api.github.com/users/peterhuene/repos","events_url":"https://api.github.com/users/peterhuene/events{/privacy}","received_events_url":"https://api.github.com/users/peterhuene/received_events","type":"User","site_admin":false},"body":"Implementing a timeout for command execution on Windows and POSIX operating systems.\r\n\r\nThis feature will enable us to timeout command executions that are known to hang Facter (such as `prtdiag` on Solaris).","created_at":"2015-03-16T18:43:08Z","updated_at":"2015-03-16T23:47:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"93ee107f5c3e6f646b4ba6d57f3e079426792b2a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/puppetlabs/cfacter/pulls/335/commits","review_comments_url":"https://api.github.com/repos/puppetlabs/cfacter/pulls/335/comments","review_comment_url":"https://api.github.com/repos/puppetlabs/cfacter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/puppetlabs/cfacter/issues/335/comments","statuses_url":"https://api.github.com/repos/puppetlabs/cfacter/statuses/9abeb2629ff65762491d69993a001036f3978473","head":{"label":"peterhuene:feature/timeout","ref":"feature/timeout","sha":"9abeb2629ff65762491d69993a001036f3978473","user":{"login":"peterhuene","id":509666,"avatar_url":"https://avatars.githubusercontent.com/u/509666?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhuene","html_url":"https://github.com/peterhuene","followers_url":"https://api.github.com/users/peterhuene/followers","following_url":"https://api.github.com/users/peterhuene/following{/other_user}","gists_url":"https://api.github.com/users/peterhuene/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhuene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhuene/subscriptions","organizations_url":"https://api.github.com/users/peterhuene/orgs","repos_url":"https://api.github.com/users/peterhuene/repos","events_url":"https://api.github.com/users/peterhuene/events{/privacy}","received_events_url":"https://api.github.com/users/peterhuene/received_events","type":"User","site_admin":false},"repo":{"id":19052426,"name":"cfacter","full_name":"peterhuene/cfacter","owner":{"login":"peterhuene","id":509666,"avatar_url":"https://avatars.githubusercontent.com/u/509666?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhuene","html_url":"https://github.com/peterhuene","followers_url":"https://api.github.com/users/peterhuene/followers","following_url":"https://api.github.com/users/peterhuene/following{/other_user}","gists_url":"https://api.github.com/users/peterhuene/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhuene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhuene/subscriptions","organizations_url":"https://api.github.com/users/peterhuene/orgs","repos_url":"https://api.github.com/users/peterhuene/repos","events_url":"https://api.github.com/users/peterhuene/events{/privacy}","received_events_url":"https://api.github.com/users/peterhuene/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/peterhuene/cfacter","description":"","fork":true,"url":"https://api.github.com/repos/peterhuene/cfacter","forks_url":"https://api.github.com/repos/peterhuene/cfacter/forks","keys_url":"https://api.github.com/repos/peterhuene/cfacter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/peterhuene/cfacter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/peterhuene/cfacter/teams","hooks_url":"https://api.github.com/repos/peterhuene/cfacter/hooks","issue_events_url":"https://api.github.com/repos/peterhuene/cfacter/issues/events{/number}","events_url":"https://api.github.com/repos/peterhuene/cfacter/events","assignees_url":"https://api.github.com/repos/peterhuene/cfacter/assignees{/user}","branches_url":"https://api.github.com/repos/peterhuene/cfacter/branches{/branch}","tags_url":"https://api.github.com/repos/peterhuene/cfacter/tags","blobs_url":"https://api.github.com/repos/peterhuene/cfacter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/peterhuene/cfacter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/peterhuene/cfacter/git/refs{/sha}","trees_url":"https://api.github.com/repos/peterhuene/cfacter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/peterhuene/cfacter/statuses/{sha}","languages_url":"https://api.github.com/repos/peterhuene/cfacter/languages","stargazers_url":"https://api.github.com/repos/peterhuene/cfacter/stargazers","contributors_url":"https://api.github.com/repos/peterhuene/cfacter/contributors","subscribers_url":"https://api.github.com/repos/peterhuene/cfacter/subscribers","subscription_url":"https://api.github.com/repos/peterhuene/cfacter/subscription","commits_url":"https://api.github.com/repos/peterhuene/cfacter/commits{/sha}","git_commits_url":"https://api.github.com/repos/peterhuene/cfacter/git/commits{/sha}","comments_url":"https://api.github.com/repos/peterhuene/cfacter/comments{/number}","issue_comment_url":"https://api.github.com/repos/peterhuene/cfacter/issues/comments{/number}","contents_url":"https://api.github.com/repos/peterhuene/cfacter/contents/{+path}","compare_url":"https://api.github.com/repos/peterhuene/cfacter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/peterhuene/cfacter/merges","archive_url":"https://api.github.com/repos/peterhuene/cfacter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/peterhuene/cfacter/downloads","issues_url":"https://api.github.com/repos/peterhuene/cfacter/issues{/number}","pulls_url":"https://api.github.com/repos/peterhuene/cfacter/pulls{/number}","milestones_url":"https://api.github.com/repos/peterhuene/cfacter/milestones{/number}","notifications_url":"https://api.github.com/repos/peterhuene/cfacter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/peterhuene/cfacter/labels{/name}","releases_url":"https://api.github.com/repos/peterhuene/cfacter/releases{/id}","created_at":"2014-04-23T01:16:12Z","updated_at":"2015-03-10T20:13:08Z","pushed_at":"2015-03-16T18:39:52Z","git_url":"git://github.com/peterhuene/cfacter.git","ssh_url":"git@github.com:peterhuene/cfacter.git","clone_url":"https://github.com/peterhuene/cfacter.git","svn_url":"https://github.com/peterhuene/cfacter","homepage":null,"size":7214,"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":"puppetlabs:master","ref":"master","sha":"771ae7be73da6b3bfca31d0608fc1b437b490dc6","user":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":17602228,"name":"cfacter","full_name":"puppetlabs/cfacter","owner":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/puppetlabs/cfacter","description":"Collect and display system facts from a C++ library.","fork":false,"url":"https://api.github.com/repos/puppetlabs/cfacter","forks_url":"https://api.github.com/repos/puppetlabs/cfacter/forks","keys_url":"https://api.github.com/repos/puppetlabs/cfacter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/puppetlabs/cfacter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/puppetlabs/cfacter/teams","hooks_url":"https://api.github.com/repos/puppetlabs/cfacter/hooks","issue_events_url":"https://api.github.com/repos/puppetlabs/cfacter/issues/events{/number}","events_url":"https://api.github.com/repos/puppetlabs/cfacter/events","assignees_url":"https://api.github.com/repos/puppetlabs/cfacter/assignees{/user}","branches_url":"https://api.github.com/repos/puppetlabs/cfacter/branches{/branch}","tags_url":"https://api.github.com/repos/puppetlabs/cfacter/tags","blobs_url":"https://api.github.com/repos/puppetlabs/cfacter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/puppetlabs/cfacter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/puppetlabs/cfacter/git/refs{/sha}","trees_url":"https://api.github.com/repos/puppetlabs/cfacter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/puppetlabs/cfacter/statuses/{sha}","languages_url":"https://api.github.com/repos/puppetlabs/cfacter/languages","stargazers_url":"https://api.github.com/repos/puppetlabs/cfacter/stargazers","contributors_url":"https://api.github.com/repos/puppetlabs/cfacter/contributors","subscribers_url":"https://api.github.com/repos/puppetlabs/cfacter/subscribers","subscription_url":"https://api.github.com/repos/puppetlabs/cfacter/subscription","commits_url":"https://api.github.com/repos/puppetlabs/cfacter/commits{/sha}","git_commits_url":"https://api.github.com/repos/puppetlabs/cfacter/git/commits{/sha}","comments_url":"https://api.github.com/repos/puppetlabs/cfacter/comments{/number}","issue_comment_url":"https://api.github.com/repos/puppetlabs/cfacter/issues/comments{/number}","contents_url":"https://api.github.com/repos/puppetlabs/cfacter/contents/{+path}","compare_url":"https://api.github.com/repos/puppetlabs/cfacter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/puppetlabs/cfacter/merges","archive_url":"https://api.github.com/repos/puppetlabs/cfacter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/puppetlabs/cfacter/downloads","issues_url":"https://api.github.com/repos/puppetlabs/cfacter/issues{/number}","pulls_url":"https://api.github.com/repos/puppetlabs/cfacter/pulls{/number}","milestones_url":"https://api.github.com/repos/puppetlabs/cfacter/milestones{/number}","notifications_url":"https://api.github.com/repos/puppetlabs/cfacter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/puppetlabs/cfacter/labels{/name}","releases_url":"https://api.github.com/repos/puppetlabs/cfacter/releases{/id}","created_at":"2014-03-10T17:48:17Z","updated_at":"2015-03-16T23:04:50Z","pushed_at":"2015-03-16T23:04:49Z","git_url":"git://github.com/puppetlabs/cfacter.git","ssh_url":"git@github.com:puppetlabs/cfacter.git","clone_url":"https://github.com/puppetlabs/cfacter.git","svn_url":"https://github.com/puppetlabs/cfacter","homepage":"https://tickets.puppetlabs.com/browse/CFACT","size":81122,"stargazers_count":27,"watchers_count":27,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":2,"forks":32,"open_issues":2,"watchers":27,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/cfacter/pulls/335"},"html":{"href":"https://github.com/puppetlabs/cfacter/pull/335"},"issue":{"href":"https://api.github.com/repos/puppetlabs/cfacter/issues/335"},"comments":{"href":"https://api.github.com/repos/puppetlabs/cfacter/issues/335/comments"},"review_comments":{"href":"https://api.github.com/repos/puppetlabs/cfacter/pulls/335/comments"},"review_comment":{"href":"https://api.github.com/repos/puppetlabs/cfacter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/puppetlabs/cfacter/pulls/335/commits"},"statuses":{"href":"https://api.github.com/repos/puppetlabs/cfacter/statuses/9abeb2629ff65762491d69993a001036f3978473"}}}}