{"action":"created","comment":{"url":"https://api.github.com/repos/meetecho/janus-gateway/pulls/comments/46424543","id":46424543,"diff_hunk":"@@ -305,3 +307,59 @@ char *janus_address_to_ip(struct sockaddr *address) {\n \t}\n \treturn addr ? g_strdup(addr) : NULL;\n }\n+\n+/* PID file management */\n+static char *pidfile = NULL;\n+static int pidfd = -1;\n+static FILE *pidf = NULL;\n+int janus_pidfile_create(const char *file) {\n+\tif(file == NULL)\n+\t\treturn 0;\n+\tpidfile = g_strdup(file);\n+\t/* Try creating a PID file (or opening an existing one) */\n+\tpidfd = open(pidfile, O_RDWR|O_CREAT, 0644);\n+\tif(pidfd < 0) {\n+\t\tJANUS_LOG(LOG_FATAL, \"Error opening/creating PID file %s, does Janus have enough permissions?\\n\", pidfile);\n+\t\treturn -1;\n+\t}\n+\tpidf = fdopen(pidfd, \"r+\");\n+\tif(pidf == NULL) {\n+\t\tJANUS_LOG(LOG_FATAL, \"Error opening/creating PID file %s, does Janus have enough permissions?\\n\", pidfile);\n+\t\tclose(pidfd);\n+\t\treturn -1;\n+\t}\n+\t/* Try locking the PID file */\n+\tint pid = 0;\n+\tif(flock(pidfd, LOCK_EX|LOCK_NB) < 0) {\n+\t\tfscanf(pidf, \"%d\", &pid);","path":"utils.c","position":39,"original_position":39,"commit_id":"d0f9f19eb68f4b0a1f646f88253736d6c5d4e344","original_commit_id":"d0f9f19eb68f4b0a1f646f88253736d6c5d4e344","user":{"login":"saghul","id":317464,"avatar_url":"https://avatars.githubusercontent.com/u/317464?v=3","gravatar_id":"","url":"https://api.github.com/users/saghul","html_url":"https://github.com/saghul","followers_url":"https://api.github.com/users/saghul/followers","following_url":"https://api.github.com/users/saghul/following{/other_user}","gists_url":"https://api.github.com/users/saghul/gists{/gist_id}","starred_url":"https://api.github.com/users/saghul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saghul/subscriptions","organizations_url":"https://api.github.com/users/saghul/orgs","repos_url":"https://api.github.com/users/saghul/repos","events_url":"https://api.github.com/users/saghul/events{/privacy}","received_events_url":"https://api.github.com/users/saghul/received_events","type":"User","site_admin":false},"body":"fscanf could fail here","created_at":"2015-12-02T15:06:43Z","updated_at":"2015-12-02T15:06:43Z","html_url":"https://github.com/meetecho/janus-gateway/pull/399#discussion_r46424543","pull_request_url":"https://api.github.com/repos/meetecho/janus-gateway/pulls/399","_links":{"self":{"href":"https://api.github.com/repos/meetecho/janus-gateway/pulls/comments/46424543"},"html":{"href":"https://github.com/meetecho/janus-gateway/pull/399#discussion_r46424543"},"pull_request":{"href":"https://api.github.com/repos/meetecho/janus-gateway/pulls/399"}}},"pull_request":{"url":"https://api.github.com/repos/meetecho/janus-gateway/pulls/399","id":52401859,"html_url":"https://github.com/meetecho/janus-gateway/pull/399","diff_url":"https://github.com/meetecho/janus-gateway/pull/399.diff","patch_url":"https://github.com/meetecho/janus-gateway/pull/399.patch","issue_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/399","number":399,"state":"open","locked":false,"title":"Added option to create/destroy/check PID file","user":{"login":"lminiero","id":3684796,"avatar_url":"https://avatars.githubusercontent.com/u/3684796?v=3","gravatar_id":"","url":"https://api.github.com/users/lminiero","html_url":"https://github.com/lminiero","followers_url":"https://api.github.com/users/lminiero/followers","following_url":"https://api.github.com/users/lminiero/following{/other_user}","gists_url":"https://api.github.com/users/lminiero/gists{/gist_id}","starred_url":"https://api.github.com/users/lminiero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lminiero/subscriptions","organizations_url":"https://api.github.com/users/lminiero/orgs","repos_url":"https://api.github.com/users/lminiero/repos","events_url":"https://api.github.com/users/lminiero/events{/privacy}","received_events_url":"https://api.github.com/users/lminiero/received_events","type":"User","site_admin":false},"body":"This patch introduces a way to make Janus create (at startup) and remove (at shutdown) a PID file. If a PID file exists and is locked (flock), or the PID file cannot be created/updated/locked, Janus failes to start. Homemade implementation as ```pidfile_*``` methods are only available using [libbsd](http://libbsd.freedesktop.org/wiki/), and I'd rather avoid adding yet another dependency for something apparently so trivial.\r\n\r\nCan be enabled in configuration file (```pid_file``` in ```[general]```) and via command line (```--pid-file``` or ```-p```).","created_at":"2015-12-02T14:27:42Z","updated_at":"2015-12-02T15:06:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"62c25ccf9e98f42eda57d89668aa1ecb5bec8718","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/meetecho/janus-gateway/pulls/399/commits","review_comments_url":"https://api.github.com/repos/meetecho/janus-gateway/pulls/399/comments","review_comment_url":"https://api.github.com/repos/meetecho/janus-gateway/pulls/comments{/number}","comments_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/399/comments","statuses_url":"https://api.github.com/repos/meetecho/janus-gateway/statuses/d0f9f19eb68f4b0a1f646f88253736d6c5d4e344","head":{"label":"meetecho:pidfile","ref":"pidfile","sha":"d0f9f19eb68f4b0a1f646f88253736d6c5d4e344","user":{"login":"meetecho","id":4520545,"avatar_url":"https://avatars.githubusercontent.com/u/4520545?v=3","gravatar_id":"","url":"https://api.github.com/users/meetecho","html_url":"https://github.com/meetecho","followers_url":"https://api.github.com/users/meetecho/followers","following_url":"https://api.github.com/users/meetecho/following{/other_user}","gists_url":"https://api.github.com/users/meetecho/gists{/gist_id}","starred_url":"https://api.github.com/users/meetecho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meetecho/subscriptions","organizations_url":"https://api.github.com/users/meetecho/orgs","repos_url":"https://api.github.com/users/meetecho/repos","events_url":"https://api.github.com/users/meetecho/events{/privacy}","received_events_url":"https://api.github.com/users/meetecho/received_events","type":"Organization","site_admin":false},"repo":{"id":16734696,"name":"janus-gateway","full_name":"meetecho/janus-gateway","owner":{"login":"meetecho","id":4520545,"avatar_url":"https://avatars.githubusercontent.com/u/4520545?v=3","gravatar_id":"","url":"https://api.github.com/users/meetecho","html_url":"https://github.com/meetecho","followers_url":"https://api.github.com/users/meetecho/followers","following_url":"https://api.github.com/users/meetecho/following{/other_user}","gists_url":"https://api.github.com/users/meetecho/gists{/gist_id}","starred_url":"https://api.github.com/users/meetecho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meetecho/subscriptions","organizations_url":"https://api.github.com/users/meetecho/orgs","repos_url":"https://api.github.com/users/meetecho/repos","events_url":"https://api.github.com/users/meetecho/events{/privacy}","received_events_url":"https://api.github.com/users/meetecho/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/meetecho/janus-gateway","description":"Janus WebRTC Gateway","fork":false,"url":"https://api.github.com/repos/meetecho/janus-gateway","forks_url":"https://api.github.com/repos/meetecho/janus-gateway/forks","keys_url":"https://api.github.com/repos/meetecho/janus-gateway/keys{/key_id}","collaborators_url":"https://api.github.com/repos/meetecho/janus-gateway/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/meetecho/janus-gateway/teams","hooks_url":"https://api.github.com/repos/meetecho/janus-gateway/hooks","issue_events_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/events{/number}","events_url":"https://api.github.com/repos/meetecho/janus-gateway/events","assignees_url":"https://api.github.com/repos/meetecho/janus-gateway/assignees{/user}","branches_url":"https://api.github.com/repos/meetecho/janus-gateway/branches{/branch}","tags_url":"https://api.github.com/repos/meetecho/janus-gateway/tags","blobs_url":"https://api.github.com/repos/meetecho/janus-gateway/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/meetecho/janus-gateway/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/meetecho/janus-gateway/git/refs{/sha}","trees_url":"https://api.github.com/repos/meetecho/janus-gateway/git/trees{/sha}","statuses_url":"https://api.github.com/repos/meetecho/janus-gateway/statuses/{sha}","languages_url":"https://api.github.com/repos/meetecho/janus-gateway/languages","stargazers_url":"https://api.github.com/repos/meetecho/janus-gateway/stargazers","contributors_url":"https://api.github.com/repos/meetecho/janus-gateway/contributors","subscribers_url":"https://api.github.com/repos/meetecho/janus-gateway/subscribers","subscription_url":"https://api.github.com/repos/meetecho/janus-gateway/subscription","commits_url":"https://api.github.com/repos/meetecho/janus-gateway/commits{/sha}","git_commits_url":"https://api.github.com/repos/meetecho/janus-gateway/git/commits{/sha}","comments_url":"https://api.github.com/repos/meetecho/janus-gateway/comments{/number}","issue_comment_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/comments{/number}","contents_url":"https://api.github.com/repos/meetecho/janus-gateway/contents/{+path}","compare_url":"https://api.github.com/repos/meetecho/janus-gateway/compare/{base}...{head}","merges_url":"https://api.github.com/repos/meetecho/janus-gateway/merges","archive_url":"https://api.github.com/repos/meetecho/janus-gateway/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/meetecho/janus-gateway/downloads","issues_url":"https://api.github.com/repos/meetecho/janus-gateway/issues{/number}","pulls_url":"https://api.github.com/repos/meetecho/janus-gateway/pulls{/number}","milestones_url":"https://api.github.com/repos/meetecho/janus-gateway/milestones{/number}","notifications_url":"https://api.github.com/repos/meetecho/janus-gateway/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/meetecho/janus-gateway/labels{/name}","releases_url":"https://api.github.com/repos/meetecho/janus-gateway/releases{/id}","created_at":"2014-02-11T15:14:39Z","updated_at":"2015-12-02T12:02:38Z","pushed_at":"2015-12-02T14:54:08Z","git_url":"git://github.com/meetecho/janus-gateway.git","ssh_url":"git@github.com:meetecho/janus-gateway.git","clone_url":"https://github.com/meetecho/janus-gateway.git","svn_url":"https://github.com/meetecho/janus-gateway","homepage":null,"size":11696,"stargazers_count":395,"watchers_count":395,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":179,"mirror_url":null,"open_issues_count":16,"forks":179,"open_issues":16,"watchers":395,"default_branch":"master"}},"base":{"label":"meetecho:master","ref":"master","sha":"c8ea6fcbc4cb67e80fd3fe1e762cf9b7eb0c7785","user":{"login":"meetecho","id":4520545,"avatar_url":"https://avatars.githubusercontent.com/u/4520545?v=3","gravatar_id":"","url":"https://api.github.com/users/meetecho","html_url":"https://github.com/meetecho","followers_url":"https://api.github.com/users/meetecho/followers","following_url":"https://api.github.com/users/meetecho/following{/other_user}","gists_url":"https://api.github.com/users/meetecho/gists{/gist_id}","starred_url":"https://api.github.com/users/meetecho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meetecho/subscriptions","organizations_url":"https://api.github.com/users/meetecho/orgs","repos_url":"https://api.github.com/users/meetecho/repos","events_url":"https://api.github.com/users/meetecho/events{/privacy}","received_events_url":"https://api.github.com/users/meetecho/received_events","type":"Organization","site_admin":false},"repo":{"id":16734696,"name":"janus-gateway","full_name":"meetecho/janus-gateway","owner":{"login":"meetecho","id":4520545,"avatar_url":"https://avatars.githubusercontent.com/u/4520545?v=3","gravatar_id":"","url":"https://api.github.com/users/meetecho","html_url":"https://github.com/meetecho","followers_url":"https://api.github.com/users/meetecho/followers","following_url":"https://api.github.com/users/meetecho/following{/other_user}","gists_url":"https://api.github.com/users/meetecho/gists{/gist_id}","starred_url":"https://api.github.com/users/meetecho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meetecho/subscriptions","organizations_url":"https://api.github.com/users/meetecho/orgs","repos_url":"https://api.github.com/users/meetecho/repos","events_url":"https://api.github.com/users/meetecho/events{/privacy}","received_events_url":"https://api.github.com/users/meetecho/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/meetecho/janus-gateway","description":"Janus WebRTC Gateway","fork":false,"url":"https://api.github.com/repos/meetecho/janus-gateway","forks_url":"https://api.github.com/repos/meetecho/janus-gateway/forks","keys_url":"https://api.github.com/repos/meetecho/janus-gateway/keys{/key_id}","collaborators_url":"https://api.github.com/repos/meetecho/janus-gateway/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/meetecho/janus-gateway/teams","hooks_url":"https://api.github.com/repos/meetecho/janus-gateway/hooks","issue_events_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/events{/number}","events_url":"https://api.github.com/repos/meetecho/janus-gateway/events","assignees_url":"https://api.github.com/repos/meetecho/janus-gateway/assignees{/user}","branches_url":"https://api.github.com/repos/meetecho/janus-gateway/branches{/branch}","tags_url":"https://api.github.com/repos/meetecho/janus-gateway/tags","blobs_url":"https://api.github.com/repos/meetecho/janus-gateway/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/meetecho/janus-gateway/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/meetecho/janus-gateway/git/refs{/sha}","trees_url":"https://api.github.com/repos/meetecho/janus-gateway/git/trees{/sha}","statuses_url":"https://api.github.com/repos/meetecho/janus-gateway/statuses/{sha}","languages_url":"https://api.github.com/repos/meetecho/janus-gateway/languages","stargazers_url":"https://api.github.com/repos/meetecho/janus-gateway/stargazers","contributors_url":"https://api.github.com/repos/meetecho/janus-gateway/contributors","subscribers_url":"https://api.github.com/repos/meetecho/janus-gateway/subscribers","subscription_url":"https://api.github.com/repos/meetecho/janus-gateway/subscription","commits_url":"https://api.github.com/repos/meetecho/janus-gateway/commits{/sha}","git_commits_url":"https://api.github.com/repos/meetecho/janus-gateway/git/commits{/sha}","comments_url":"https://api.github.com/repos/meetecho/janus-gateway/comments{/number}","issue_comment_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/comments{/number}","contents_url":"https://api.github.com/repos/meetecho/janus-gateway/contents/{+path}","compare_url":"https://api.github.com/repos/meetecho/janus-gateway/compare/{base}...{head}","merges_url":"https://api.github.com/repos/meetecho/janus-gateway/merges","archive_url":"https://api.github.com/repos/meetecho/janus-gateway/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/meetecho/janus-gateway/downloads","issues_url":"https://api.github.com/repos/meetecho/janus-gateway/issues{/number}","pulls_url":"https://api.github.com/repos/meetecho/janus-gateway/pulls{/number}","milestones_url":"https://api.github.com/repos/meetecho/janus-gateway/milestones{/number}","notifications_url":"https://api.github.com/repos/meetecho/janus-gateway/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/meetecho/janus-gateway/labels{/name}","releases_url":"https://api.github.com/repos/meetecho/janus-gateway/releases{/id}","created_at":"2014-02-11T15:14:39Z","updated_at":"2015-12-02T12:02:38Z","pushed_at":"2015-12-02T14:54:08Z","git_url":"git://github.com/meetecho/janus-gateway.git","ssh_url":"git@github.com:meetecho/janus-gateway.git","clone_url":"https://github.com/meetecho/janus-gateway.git","svn_url":"https://github.com/meetecho/janus-gateway","homepage":null,"size":11696,"stargazers_count":395,"watchers_count":395,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":179,"mirror_url":null,"open_issues_count":16,"forks":179,"open_issues":16,"watchers":395,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/meetecho/janus-gateway/pulls/399"},"html":{"href":"https://github.com/meetecho/janus-gateway/pull/399"},"issue":{"href":"https://api.github.com/repos/meetecho/janus-gateway/issues/399"},"comments":{"href":"https://api.github.com/repos/meetecho/janus-gateway/issues/399/comments"},"review_comments":{"href":"https://api.github.com/repos/meetecho/janus-gateway/pulls/399/comments"},"review_comment":{"href":"https://api.github.com/repos/meetecho/janus-gateway/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/meetecho/janus-gateway/pulls/399/commits"},"statuses":{"href":"https://api.github.com/repos/meetecho/janus-gateway/statuses/d0f9f19eb68f4b0a1f646f88253736d6c5d4e344"}}}}