{"action":"created","comment":{"url":"https://api.github.com/repos/joyent/smartos-live/pulls/comments/59660029","id":59660029,"diff_hunk":"@@ -0,0 +1,988 @@\n+/*\n+ * CDDL HEADER START\n+ *\n+ * The contents of this file are subject to the terms of the\n+ * Common Development and Distribution License, Version 1.0 only\n+ * (the \"License\").  You may not use this file except in compliance\n+ * with the License.\n+ *\n+ * You can obtain a copy of the license at http://smartos.org/CDDL\n+ *\n+ * See the License for the specific language governing permissions\n+ * and limitations under the License.\n+ *\n+ * When distributing Covered Code, include this CDDL HEADER in each\n+ * file.\n+ *\n+ * If applicable, add the following below this CDDL HEADER, with the\n+ * fields enclosed by brackets \"[]\" replaced with your own identifying\n+ * information: Portions Copyright [yyyy] [name of copyright owner]\n+ *\n+ * CDDL HEADER END\n+ *\n+ * Copyright 2016, Joyent, Inc.\n+ *\n+ * gcc -Wall -Wextra fswatcher.c -o fswatcher -lthread\n+ *\n+ */\n+\n+// #define DEBUG\n+\n+#define _REENTRANT\n+#include <assert.h>\n+#include <ctype.h>\n+#include <stdarg.h>\n+#include <stdlib.h>\n+#include <sys/types.h>\n+#include <sys/stat.h>\n+#include <unistd.h>\n+#include <limits.h>\n+#include <fcntl.h>\n+#include <strings.h>\n+#include <port.h>\n+#include <errno.h>\n+#include <pthread.h>\n+#include <stdio.h>\n+#include <thread.h>\n+#include <time.h>\n+\n+/*\n+ * On STDIN you can send:\n+ *\n+ * <KEY> WATCH <pathname> [timestamp]\\n\n+ * <KEY> UNWATCH <pathname>\\n\n+ *\n+ * The first will cause <pathname> to be added to the watch list. The second\n+ * will cause the watch for the specified path to be removed. The <KEY> must\n+ * be an integer in the range 1-4294967295 (inclusive). Leading 0's will be\n+ * removed. NOTE: 0 is a special key in that it will be used in output for\n+ * errors which were not directly the result of a command.\n+ *\n+ * When using a WATCH command with a <timestamp> argument, the timestamp must\n+ * be an integer number of nanoseconds since Jan 1, 1970 00:00:00 UTC. This\n+ * usually will be the time that the last event or modification was seen for\n+ * this file and the data can be pulled from stat(2)'s st_mtim structure.\n+ *\n+ * On STDOUT you will see JSON messages that look like the following but are\n+ * on a single line:\n+ *\n+ *  {\n+ *     \"changes\": [array],\n+ *     \"code\": <number>,\n+ *     \"is_final\": true|false,\n+ *     \"key\": <number>,\n+ *     \"message\": \"human readable string\",\n+ *     \"pathname\": \"/path/which/had/event\",\n+ *     \"result\": \"SUCCESS|FAIL\",\n+ *     \"timestamp\": <number>,\n+ *     \"type\": <type>\n+ *  }\n+ *\n+ * Where:\n+ *\n+ *   changes   is an array of strings indicating which changes occurred\n+ *   code      is a positive integer code for an error\n+ *   is_final  true when the event being printed is the last without re-watch\n+ *   key       is the <KEY> for which a response corresponds\n+ *   message   is a human-readable string describing response\n+ *   pathname  is the path to which an event applies\n+ *   result    indicates whether a command was a SUCCESS or FAILURE\n+ *   timestamp timestamp in ns since 1970-01-01 00:00:00 UTC\n+ *   type      is one of: event, response, error\n+ *\n+ * And:\n+ *\n+ *   \"changes\" is included only when (type == event)\n+ *   \"code\" is included only when (type == error)\n+ *   \"is_final\" is included when (type == event)\n+ *   \"key\" is included whenever (type == response)\n+ *   \"message\" is included whenever (type == error)\n+ *   \"pathname\" is included whenever (type == event)\n+ *   \"result\" is included when (type == response) value: \"SUCCESS\" or \"FAILURE\"\n+ *   \"timestamp\" is included when (type == event)\n+ *   \"type\" is always included\n+ *\n+ * Current values for \"code\" are in the ErrorCodes enum below.\n+ *\n+ * EXIT STATUS\n+ *\n+ *   Under normal operation, fswatcher will run until STDIN is closed or a fatal\n+ *   error occurs. STDIN closing will result in exit code 0. Any other exit code","path":"src/fswatcher.c","position":110,"original_position":110,"commit_id":"91d8bd57e4236eb0eae79448562ff844824cb223","original_commit_id":"91d8bd57e4236eb0eae79448562ff844824cb223","user":{"login":"joshwilsdon","id":78194,"avatar_url":"https://avatars.githubusercontent.com/u/78194?v=3","gravatar_id":"","url":"https://api.github.com/users/joshwilsdon","html_url":"https://github.com/joshwilsdon","followers_url":"https://api.github.com/users/joshwilsdon/followers","following_url":"https://api.github.com/users/joshwilsdon/following{/other_user}","gists_url":"https://api.github.com/users/joshwilsdon/gists{/gist_id}","starred_url":"https://api.github.com/users/joshwilsdon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshwilsdon/subscriptions","organizations_url":"https://api.github.com/users/joshwilsdon/orgs","repos_url":"https://api.github.com/users/joshwilsdon/repos","events_url":"https://api.github.com/users/joshwilsdon/events{/privacy}","received_events_url":"https://api.github.com/users/joshwilsdon/received_events","type":"User","site_admin":false},"body":"The wording here's a bit strange. Maybe something like:\r\n\r\n```If a fatal error occurs, this will result in a message of type \"error\" ...```\r\n\r\ninstead of:\r\n\r\n```Any other exit code...``` ?","created_at":"2016-04-14T03:43:48Z","updated_at":"2016-04-14T03:43:48Z","html_url":"https://github.com/joyent/smartos-live/pull/601#discussion_r59660029","pull_request_url":"https://api.github.com/repos/joyent/smartos-live/pulls/601","_links":{"self":{"href":"https://api.github.com/repos/joyent/smartos-live/pulls/comments/59660029"},"html":{"href":"https://github.com/joyent/smartos-live/pull/601#discussion_r59660029"},"pull_request":{"href":"https://api.github.com/repos/joyent/smartos-live/pulls/601"}}},"pull_request":{"url":"https://api.github.com/repos/joyent/smartos-live/pulls/601","id":66424986,"html_url":"https://github.com/joyent/smartos-live/pull/601","diff_url":"https://github.com/joyent/smartos-live/pull/601.diff","patch_url":"https://github.com/joyent/smartos-live/pull/601.patch","issue_url":"https://api.github.com/repos/joyent/smartos-live/issues/601","number":601,"state":"open","locked":false,"title":"OS-3069 need fs watcher to watch zones' files","user":{"login":"joshwilsdon","id":78194,"avatar_url":"https://avatars.githubusercontent.com/u/78194?v=3","gravatar_id":"","url":"https://api.github.com/users/joshwilsdon","html_url":"https://github.com/joshwilsdon","followers_url":"https://api.github.com/users/joshwilsdon/followers","following_url":"https://api.github.com/users/joshwilsdon/following{/other_user}","gists_url":"https://api.github.com/users/joshwilsdon/gists{/gist_id}","starred_url":"https://api.github.com/users/joshwilsdon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshwilsdon/subscriptions","organizations_url":"https://api.github.com/users/joshwilsdon/orgs","repos_url":"https://api.github.com/users/joshwilsdon/repos","events_url":"https://api.github.com/users/joshwilsdon/events{/privacy}","received_events_url":"https://api.github.com/users/joshwilsdon/received_events","type":"User","site_admin":false},"body":"Importing here in order to do review.","created_at":"2016-04-14T03:39:34Z","updated_at":"2016-04-14T03:43:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f21a555a1507992ac56c258e6940aeb6369ff40","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/joyent/smartos-live/pulls/601/commits","review_comments_url":"https://api.github.com/repos/joyent/smartos-live/pulls/601/comments","review_comment_url":"https://api.github.com/repos/joyent/smartos-live/pulls/comments{/number}","comments_url":"https://api.github.com/repos/joyent/smartos-live/issues/601/comments","statuses_url":"https://api.github.com/repos/joyent/smartos-live/statuses/91d8bd57e4236eb0eae79448562ff844824cb223","head":{"label":"joyent:OS-3069","ref":"OS-3069","sha":"91d8bd57e4236eb0eae79448562ff844824cb223","user":{"login":"joyent","id":10161,"avatar_url":"https://avatars.githubusercontent.com/u/10161?v=3","gravatar_id":"","url":"https://api.github.com/users/joyent","html_url":"https://github.com/joyent","followers_url":"https://api.github.com/users/joyent/followers","following_url":"https://api.github.com/users/joyent/following{/other_user}","gists_url":"https://api.github.com/users/joyent/gists{/gist_id}","starred_url":"https://api.github.com/users/joyent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joyent/subscriptions","organizations_url":"https://api.github.com/users/joyent/orgs","repos_url":"https://api.github.com/users/joyent/repos","events_url":"https://api.github.com/users/joyent/events{/privacy}","received_events_url":"https://api.github.com/users/joyent/received_events","type":"Organization","site_admin":false},"repo":{"id":2203782,"name":"smartos-live","full_name":"joyent/smartos-live","owner":{"login":"joyent","id":10161,"avatar_url":"https://avatars.githubusercontent.com/u/10161?v=3","gravatar_id":"","url":"https://api.github.com/users/joyent","html_url":"https://github.com/joyent","followers_url":"https://api.github.com/users/joyent/followers","following_url":"https://api.github.com/users/joyent/following{/other_user}","gists_url":"https://api.github.com/users/joyent/gists{/gist_id}","starred_url":"https://api.github.com/users/joyent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joyent/subscriptions","organizations_url":"https://api.github.com/users/joyent/orgs","repos_url":"https://api.github.com/users/joyent/repos","events_url":"https://api.github.com/users/joyent/events{/privacy}","received_events_url":"https://api.github.com/users/joyent/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/joyent/smartos-live","description":"For more information, please see http://smartos.org/  For any questions that aren't answered there, please join the SmartOS discussion list: http://smartos.org/smartos-mailing-list/","fork":false,"url":"https://api.github.com/repos/joyent/smartos-live","forks_url":"https://api.github.com/repos/joyent/smartos-live/forks","keys_url":"https://api.github.com/repos/joyent/smartos-live/keys{/key_id}","collaborators_url":"https://api.github.com/repos/joyent/smartos-live/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/joyent/smartos-live/teams","hooks_url":"https://api.github.com/repos/joyent/smartos-live/hooks","issue_events_url":"https://api.github.com/repos/joyent/smartos-live/issues/events{/number}","events_url":"https://api.github.com/repos/joyent/smartos-live/events","assignees_url":"https://api.github.com/repos/joyent/smartos-live/assignees{/user}","branches_url":"https://api.github.com/repos/joyent/smartos-live/branches{/branch}","tags_url":"https://api.github.com/repos/joyent/smartos-live/tags","blobs_url":"https://api.github.com/repos/joyent/smartos-live/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/joyent/smartos-live/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/joyent/smartos-live/git/refs{/sha}","trees_url":"https://api.github.com/repos/joyent/smartos-live/git/trees{/sha}","statuses_url":"https://api.github.com/repos/joyent/smartos-live/statuses/{sha}","languages_url":"https://api.github.com/repos/joyent/smartos-live/languages","stargazers_url":"https://api.github.com/repos/joyent/smartos-live/stargazers","contributors_url":"https://api.github.com/repos/joyent/smartos-live/contributors","subscribers_url":"https://api.github.com/repos/joyent/smartos-live/subscribers","subscription_url":"https://api.github.com/repos/joyent/smartos-live/subscription","commits_url":"https://api.github.com/repos/joyent/smartos-live/commits{/sha}","git_commits_url":"https://api.github.com/repos/joyent/smartos-live/git/commits{/sha}","comments_url":"https://api.github.com/repos/joyent/smartos-live/comments{/number}","issue_comment_url":"https://api.github.com/repos/joyent/smartos-live/issues/comments{/number}","contents_url":"https://api.github.com/repos/joyent/smartos-live/contents/{+path}","compare_url":"https://api.github.com/repos/joyent/smartos-live/compare/{base}...{head}","merges_url":"https://api.github.com/repos/joyent/smartos-live/merges","archive_url":"https://api.github.com/repos/joyent/smartos-live/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/joyent/smartos-live/downloads","issues_url":"https://api.github.com/repos/joyent/smartos-live/issues{/number}","pulls_url":"https://api.github.com/repos/joyent/smartos-live/pulls{/number}","milestones_url":"https://api.github.com/repos/joyent/smartos-live/milestones{/number}","notifications_url":"https://api.github.com/repos/joyent/smartos-live/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/joyent/smartos-live/labels{/name}","releases_url":"https://api.github.com/repos/joyent/smartos-live/releases{/id}","deployments_url":"https://api.github.com/repos/joyent/smartos-live/deployments","created_at":"2011-08-14T01:08:28Z","updated_at":"2016-04-12T14:41:14Z","pushed_at":"2016-04-14T03:39:34Z","git_url":"git://github.com/joyent/smartos-live.git","ssh_url":"git@github.com:joyent/smartos-live.git","clone_url":"https://github.com/joyent/smartos-live.git","svn_url":"https://github.com/joyent/smartos-live","homepage":"","size":38748,"stargazers_count":1022,"watchers_count":1022,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":156,"mirror_url":null,"open_issues_count":242,"forks":156,"open_issues":242,"watchers":1022,"default_branch":"master"}},"base":{"label":"joyent:master","ref":"master","sha":"128f51dbd504953097e08cc1c7de6e9a9f75c38f","user":{"login":"joyent","id":10161,"avatar_url":"https://avatars.githubusercontent.com/u/10161?v=3","gravatar_id":"","url":"https://api.github.com/users/joyent","html_url":"https://github.com/joyent","followers_url":"https://api.github.com/users/joyent/followers","following_url":"https://api.github.com/users/joyent/following{/other_user}","gists_url":"https://api.github.com/users/joyent/gists{/gist_id}","starred_url":"https://api.github.com/users/joyent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joyent/subscriptions","organizations_url":"https://api.github.com/users/joyent/orgs","repos_url":"https://api.github.com/users/joyent/repos","events_url":"https://api.github.com/users/joyent/events{/privacy}","received_events_url":"https://api.github.com/users/joyent/received_events","type":"Organization","site_admin":false},"repo":{"id":2203782,"name":"smartos-live","full_name":"joyent/smartos-live","owner":{"login":"joyent","id":10161,"avatar_url":"https://avatars.githubusercontent.com/u/10161?v=3","gravatar_id":"","url":"https://api.github.com/users/joyent","html_url":"https://github.com/joyent","followers_url":"https://api.github.com/users/joyent/followers","following_url":"https://api.github.com/users/joyent/following{/other_user}","gists_url":"https://api.github.com/users/joyent/gists{/gist_id}","starred_url":"https://api.github.com/users/joyent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joyent/subscriptions","organizations_url":"https://api.github.com/users/joyent/orgs","repos_url":"https://api.github.com/users/joyent/repos","events_url":"https://api.github.com/users/joyent/events{/privacy}","received_events_url":"https://api.github.com/users/joyent/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/joyent/smartos-live","description":"For more information, please see http://smartos.org/  For any questions that aren't answered there, please join the SmartOS discussion list: http://smartos.org/smartos-mailing-list/","fork":false,"url":"https://api.github.com/repos/joyent/smartos-live","forks_url":"https://api.github.com/repos/joyent/smartos-live/forks","keys_url":"https://api.github.com/repos/joyent/smartos-live/keys{/key_id}","collaborators_url":"https://api.github.com/repos/joyent/smartos-live/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/joyent/smartos-live/teams","hooks_url":"https://api.github.com/repos/joyent/smartos-live/hooks","issue_events_url":"https://api.github.com/repos/joyent/smartos-live/issues/events{/number}","events_url":"https://api.github.com/repos/joyent/smartos-live/events","assignees_url":"https://api.github.com/repos/joyent/smartos-live/assignees{/user}","branches_url":"https://api.github.com/repos/joyent/smartos-live/branches{/branch}","tags_url":"https://api.github.com/repos/joyent/smartos-live/tags","blobs_url":"https://api.github.com/repos/joyent/smartos-live/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/joyent/smartos-live/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/joyent/smartos-live/git/refs{/sha}","trees_url":"https://api.github.com/repos/joyent/smartos-live/git/trees{/sha}","statuses_url":"https://api.github.com/repos/joyent/smartos-live/statuses/{sha}","languages_url":"https://api.github.com/repos/joyent/smartos-live/languages","stargazers_url":"https://api.github.com/repos/joyent/smartos-live/stargazers","contributors_url":"https://api.github.com/repos/joyent/smartos-live/contributors","subscribers_url":"https://api.github.com/repos/joyent/smartos-live/subscribers","subscription_url":"https://api.github.com/repos/joyent/smartos-live/subscription","commits_url":"https://api.github.com/repos/joyent/smartos-live/commits{/sha}","git_commits_url":"https://api.github.com/repos/joyent/smartos-live/git/commits{/sha}","comments_url":"https://api.github.com/repos/joyent/smartos-live/comments{/number}","issue_comment_url":"https://api.github.com/repos/joyent/smartos-live/issues/comments{/number}","contents_url":"https://api.github.com/repos/joyent/smartos-live/contents/{+path}","compare_url":"https://api.github.com/repos/joyent/smartos-live/compare/{base}...{head}","merges_url":"https://api.github.com/repos/joyent/smartos-live/merges","archive_url":"https://api.github.com/repos/joyent/smartos-live/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/joyent/smartos-live/downloads","issues_url":"https://api.github.com/repos/joyent/smartos-live/issues{/number}","pulls_url":"https://api.github.com/repos/joyent/smartos-live/pulls{/number}","milestones_url":"https://api.github.com/repos/joyent/smartos-live/milestones{/number}","notifications_url":"https://api.github.com/repos/joyent/smartos-live/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/joyent/smartos-live/labels{/name}","releases_url":"https://api.github.com/repos/joyent/smartos-live/releases{/id}","deployments_url":"https://api.github.com/repos/joyent/smartos-live/deployments","created_at":"2011-08-14T01:08:28Z","updated_at":"2016-04-12T14:41:14Z","pushed_at":"2016-04-14T03:39:34Z","git_url":"git://github.com/joyent/smartos-live.git","ssh_url":"git@github.com:joyent/smartos-live.git","clone_url":"https://github.com/joyent/smartos-live.git","svn_url":"https://github.com/joyent/smartos-live","homepage":"","size":38748,"stargazers_count":1022,"watchers_count":1022,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":156,"mirror_url":null,"open_issues_count":242,"forks":156,"open_issues":242,"watchers":1022,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/joyent/smartos-live/pulls/601"},"html":{"href":"https://github.com/joyent/smartos-live/pull/601"},"issue":{"href":"https://api.github.com/repos/joyent/smartos-live/issues/601"},"comments":{"href":"https://api.github.com/repos/joyent/smartos-live/issues/601/comments"},"review_comments":{"href":"https://api.github.com/repos/joyent/smartos-live/pulls/601/comments"},"review_comment":{"href":"https://api.github.com/repos/joyent/smartos-live/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/joyent/smartos-live/pulls/601/commits"},"statuses":{"href":"https://api.github.com/repos/joyent/smartos-live/statuses/91d8bd57e4236eb0eae79448562ff844824cb223"}}}}