{"action":"created","comment":{"url":"https://api.github.com/repos/a2o/snoopy/pulls/comments/27227215","id":27227215,"diff_hunk":"@@ -0,0 +1,114 @@\n+/*\n+ * SNOOPY LOGGER\n+ *\n+ * File: snoopy/input/username.c\n+ *\n+ * Copyright (c) 2014 bostjan@a2o.si\n+ *\n+ * This program is free software; you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation; either version 2, or (at your option)\n+ * any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software Foundation,\n+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ */\n+\n+#define _GNU_SOURCE\n+#include \"snoopy.h\"\n+#include <stdio.h>\n+#include <unistd.h>\n+#include <sys/types.h>\n+#include <proc/readproc.h>\n+#include <string.h>\n+#include <ctype.h>\n+#include <stdlib.h>\n+\n+#define ROOT_PID\t\t1\n+#define EMPTY_PID\t\t0\n+\n+#define PROC_NAME\t\t\"Name\"\n+#define PROC_PPID\t\t\"PPid\"\n+#define UNKNOWN_STR\t\t\"(unknown)\"\n+\n+/* Remove white spaces on the property */\n+char* trim_whitespace(char *str) {\n+\tchar *end;\n+\n+\twhile (isspace(*str))\n+\t\tstr++;\n+\n+\tif (*str == 0)\n+\t\treturn str;\n+\n+\tend = str + strlen(str) - 1;\n+\twhile (end > str && isspace(*end))\n+\t\tend--;\n+\n+\t*(end + 1) = 0;\n+\n+\treturn str;\n+}\n+\n+/* Read /proc/{pid}/status file and extract the property */\n+char* read_proc_property(int pid, char* prop_name) {\n+\tFILE * fp;\n+\tchar * line = NULL;\n+\tsize_t len = 0;\n+\tchar* k;\n+\tchar* v;\n+\tchar pid_file[50];\n+\n+\tsprintf(pid_file, \"/proc/%d/status\", pid);\n+\tfp = fopen(pid_file, \"r\");\n+\tif (fp != NULL) {\n+\t\twhile (getline(&line, &len, fp) != -1) {\n+\t\t\tk = strtok(line, \":\");\n+\t\t\tv = strtok(NULL, \":\");\n+\t\t\tif (strcmp(prop_name, k) == 0) {\n+\t\t\t\tfclose(fp);\n+\t\t\t\treturn trim_whitespace(v);\n+\t\t\t}\n+\t\t}\n+\t\tfclose(fp);\n+\t}\n+\treturn NULL;\n+}\n+\n+/* Get parent pid */\n+int get_parent_pid(int pid) {\n+\tchar* ppid;\n+\tppid = read_proc_property(pid, PROC_PPID);\n+\tif (ppid != NULL)\n+\t\treturn atoi(ppid);\n+\treturn EMPTY_PID;\n+}\n+\n+/* Find root process name */\n+int get_rpname(int pid, char *input) {\n+\tint parent;\n+\tchar* name;\n+\n+\tparent = get_parent_pid(pid);\n+\tif (parent == ROOT_PID) {\n+\t\tname = read_proc_property(pid, PROC_NAME);\n+\t\tif (name != NULL)\n+\t\t\treturn snprintf(input, SNOOPY_INPUT_MESSAGE_MAX_SIZE, \"%s\", name);\n+\t\telse\n+\t\t\treturn snprintf(input, SNOOPY_INPUT_MESSAGE_MAX_SIZE, \"%s\",\tUNKNOWN_STR);\n+\t} else if (parent == EMPTY_PID)\n+\t\treturn snprintf(input, SNOOPY_INPUT_MESSAGE_MAX_SIZE, \"%s\", UNKNOWN_STR);\n+\telse {\n+\t\treturn get_rpname(get_parent_pid(pid), input);","path":"src/input/rpname.c","position":108,"original_position":108,"commit_id":"b05972a39bc07e0ec7825519e39624f76bd9053d","original_commit_id":"b05972a39bc07e0ec7825519e39624f76bd9053d","user":{"login":"bostjan","id":107080,"avatar_url":"https://avatars.githubusercontent.com/u/107080?v=3","gravatar_id":"","url":"https://api.github.com/users/bostjan","html_url":"https://github.com/bostjan","followers_url":"https://api.github.com/users/bostjan/followers","following_url":"https://api.github.com/users/bostjan/following{/other_user}","gists_url":"https://api.github.com/users/bostjan/gists{/gist_id}","starred_url":"https://api.github.com/users/bostjan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bostjan/subscriptions","organizations_url":"https://api.github.com/users/bostjan/orgs","repos_url":"https://api.github.com/users/bostjan/repos","events_url":"https://api.github.com/users/bostjan/events{/privacy}","received_events_url":"https://api.github.com/users/bostjan/received_events","type":"User","site_admin":false},"body":"You have \"parent\" variable which already contains parent pid, no need to call get_parent_pid() again, right?","created_at":"2015-03-26T16:05:20Z","updated_at":"2015-03-26T16:05:20Z","html_url":"https://github.com/a2o/snoopy/pull/35#discussion_r27227215","pull_request_url":"https://api.github.com/repos/a2o/snoopy/pulls/35","_links":{"self":{"href":"https://api.github.com/repos/a2o/snoopy/pulls/comments/27227215"},"html":{"href":"https://github.com/a2o/snoopy/pull/35#discussion_r27227215"},"pull_request":{"href":"https://api.github.com/repos/a2o/snoopy/pulls/35"}}},"pull_request":{"url":"https://api.github.com/repos/a2o/snoopy/pulls/35","id":32027235,"html_url":"https://github.com/a2o/snoopy/pull/35","diff_url":"https://github.com/a2o/snoopy/pull/35.diff","patch_url":"https://github.com/a2o/snoopy/pull/35.patch","issue_url":"https://api.github.com/repos/a2o/snoopy/issues/35","number":35,"state":"open","locked":false,"title":"Added input data provider: root process name","user":{"login":"ajzach","id":2071648,"avatar_url":"https://avatars.githubusercontent.com/u/2071648?v=3","gravatar_id":"","url":"https://api.github.com/users/ajzach","html_url":"https://github.com/ajzach","followers_url":"https://api.github.com/users/ajzach/followers","following_url":"https://api.github.com/users/ajzach/following{/other_user}","gists_url":"https://api.github.com/users/ajzach/gists{/gist_id}","starred_url":"https://api.github.com/users/ajzach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajzach/subscriptions","organizations_url":"https://api.github.com/users/ajzach/orgs","repos_url":"https://api.github.com/users/ajzach/repos","events_url":"https://api.github.com/users/ajzach/events{/privacy}","received_events_url":"https://api.github.com/users/ajzach/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-26T15:16:48Z","updated_at":"2015-03-26T16:05:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d56c78ba56ce7657513a1471618497639168820","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/a2o/snoopy/pulls/35/commits","review_comments_url":"https://api.github.com/repos/a2o/snoopy/pulls/35/comments","review_comment_url":"https://api.github.com/repos/a2o/snoopy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/a2o/snoopy/issues/35/comments","statuses_url":"https://api.github.com/repos/a2o/snoopy/statuses/b05972a39bc07e0ec7825519e39624f76bd9053d","head":{"label":"ajzach:master","ref":"master","sha":"b05972a39bc07e0ec7825519e39624f76bd9053d","user":{"login":"ajzach","id":2071648,"avatar_url":"https://avatars.githubusercontent.com/u/2071648?v=3","gravatar_id":"","url":"https://api.github.com/users/ajzach","html_url":"https://github.com/ajzach","followers_url":"https://api.github.com/users/ajzach/followers","following_url":"https://api.github.com/users/ajzach/following{/other_user}","gists_url":"https://api.github.com/users/ajzach/gists{/gist_id}","starred_url":"https://api.github.com/users/ajzach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajzach/subscriptions","organizations_url":"https://api.github.com/users/ajzach/orgs","repos_url":"https://api.github.com/users/ajzach/repos","events_url":"https://api.github.com/users/ajzach/events{/privacy}","received_events_url":"https://api.github.com/users/ajzach/received_events","type":"User","site_admin":false},"repo":{"id":32881774,"name":"snoopy","full_name":"ajzach/snoopy","owner":{"login":"ajzach","id":2071648,"avatar_url":"https://avatars.githubusercontent.com/u/2071648?v=3","gravatar_id":"","url":"https://api.github.com/users/ajzach","html_url":"https://github.com/ajzach","followers_url":"https://api.github.com/users/ajzach/followers","following_url":"https://api.github.com/users/ajzach/following{/other_user}","gists_url":"https://api.github.com/users/ajzach/gists{/gist_id}","starred_url":"https://api.github.com/users/ajzach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajzach/subscriptions","organizations_url":"https://api.github.com/users/ajzach/orgs","repos_url":"https://api.github.com/users/ajzach/repos","events_url":"https://api.github.com/users/ajzach/events{/privacy}","received_events_url":"https://api.github.com/users/ajzach/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ajzach/snoopy","description":"Log every executed command to syslog (a.k.a. Snoopy Logger).","fork":true,"url":"https://api.github.com/repos/ajzach/snoopy","forks_url":"https://api.github.com/repos/ajzach/snoopy/forks","keys_url":"https://api.github.com/repos/ajzach/snoopy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ajzach/snoopy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ajzach/snoopy/teams","hooks_url":"https://api.github.com/repos/ajzach/snoopy/hooks","issue_events_url":"https://api.github.com/repos/ajzach/snoopy/issues/events{/number}","events_url":"https://api.github.com/repos/ajzach/snoopy/events","assignees_url":"https://api.github.com/repos/ajzach/snoopy/assignees{/user}","branches_url":"https://api.github.com/repos/ajzach/snoopy/branches{/branch}","tags_url":"https://api.github.com/repos/ajzach/snoopy/tags","blobs_url":"https://api.github.com/repos/ajzach/snoopy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ajzach/snoopy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ajzach/snoopy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ajzach/snoopy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ajzach/snoopy/statuses/{sha}","languages_url":"https://api.github.com/repos/ajzach/snoopy/languages","stargazers_url":"https://api.github.com/repos/ajzach/snoopy/stargazers","contributors_url":"https://api.github.com/repos/ajzach/snoopy/contributors","subscribers_url":"https://api.github.com/repos/ajzach/snoopy/subscribers","subscription_url":"https://api.github.com/repos/ajzach/snoopy/subscription","commits_url":"https://api.github.com/repos/ajzach/snoopy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ajzach/snoopy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ajzach/snoopy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ajzach/snoopy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ajzach/snoopy/contents/{+path}","compare_url":"https://api.github.com/repos/ajzach/snoopy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ajzach/snoopy/merges","archive_url":"https://api.github.com/repos/ajzach/snoopy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ajzach/snoopy/downloads","issues_url":"https://api.github.com/repos/ajzach/snoopy/issues{/number}","pulls_url":"https://api.github.com/repos/ajzach/snoopy/pulls{/number}","milestones_url":"https://api.github.com/repos/ajzach/snoopy/milestones{/number}","notifications_url":"https://api.github.com/repos/ajzach/snoopy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ajzach/snoopy/labels{/name}","releases_url":"https://api.github.com/repos/ajzach/snoopy/releases{/id}","created_at":"2015-03-25T18:02:06Z","updated_at":"2015-03-26T15:10:01Z","pushed_at":"2015-03-26T15:10:01Z","git_url":"git://github.com/ajzach/snoopy.git","ssh_url":"git@github.com:ajzach/snoopy.git","clone_url":"https://github.com/ajzach/snoopy.git","svn_url":"https://github.com/ajzach/snoopy","homepage":"","size":1182,"stargazers_count":0,"watchers_count":0,"language":"Shell","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"a2o:master","ref":"master","sha":"b309551db8b519a6bb99bee3446a4d5bf1f2d247","user":{"login":"a2o","id":165580,"avatar_url":"https://avatars.githubusercontent.com/u/165580?v=3","gravatar_id":"","url":"https://api.github.com/users/a2o","html_url":"https://github.com/a2o","followers_url":"https://api.github.com/users/a2o/followers","following_url":"https://api.github.com/users/a2o/following{/other_user}","gists_url":"https://api.github.com/users/a2o/gists{/gist_id}","starred_url":"https://api.github.com/users/a2o/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a2o/subscriptions","organizations_url":"https://api.github.com/users/a2o/orgs","repos_url":"https://api.github.com/users/a2o/repos","events_url":"https://api.github.com/users/a2o/events{/privacy}","received_events_url":"https://api.github.com/users/a2o/received_events","type":"Organization","site_admin":false},"repo":{"id":7248772,"name":"snoopy","full_name":"a2o/snoopy","owner":{"login":"a2o","id":165580,"avatar_url":"https://avatars.githubusercontent.com/u/165580?v=3","gravatar_id":"","url":"https://api.github.com/users/a2o","html_url":"https://github.com/a2o","followers_url":"https://api.github.com/users/a2o/followers","following_url":"https://api.github.com/users/a2o/following{/other_user}","gists_url":"https://api.github.com/users/a2o/gists{/gist_id}","starred_url":"https://api.github.com/users/a2o/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a2o/subscriptions","organizations_url":"https://api.github.com/users/a2o/orgs","repos_url":"https://api.github.com/users/a2o/repos","events_url":"https://api.github.com/users/a2o/events{/privacy}","received_events_url":"https://api.github.com/users/a2o/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/a2o/snoopy","description":"Log every executed command to syslog (a.k.a. Snoopy Logger).","fork":false,"url":"https://api.github.com/repos/a2o/snoopy","forks_url":"https://api.github.com/repos/a2o/snoopy/forks","keys_url":"https://api.github.com/repos/a2o/snoopy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/a2o/snoopy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/a2o/snoopy/teams","hooks_url":"https://api.github.com/repos/a2o/snoopy/hooks","issue_events_url":"https://api.github.com/repos/a2o/snoopy/issues/events{/number}","events_url":"https://api.github.com/repos/a2o/snoopy/events","assignees_url":"https://api.github.com/repos/a2o/snoopy/assignees{/user}","branches_url":"https://api.github.com/repos/a2o/snoopy/branches{/branch}","tags_url":"https://api.github.com/repos/a2o/snoopy/tags","blobs_url":"https://api.github.com/repos/a2o/snoopy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/a2o/snoopy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/a2o/snoopy/git/refs{/sha}","trees_url":"https://api.github.com/repos/a2o/snoopy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/a2o/snoopy/statuses/{sha}","languages_url":"https://api.github.com/repos/a2o/snoopy/languages","stargazers_url":"https://api.github.com/repos/a2o/snoopy/stargazers","contributors_url":"https://api.github.com/repos/a2o/snoopy/contributors","subscribers_url":"https://api.github.com/repos/a2o/snoopy/subscribers","subscription_url":"https://api.github.com/repos/a2o/snoopy/subscription","commits_url":"https://api.github.com/repos/a2o/snoopy/commits{/sha}","git_commits_url":"https://api.github.com/repos/a2o/snoopy/git/commits{/sha}","comments_url":"https://api.github.com/repos/a2o/snoopy/comments{/number}","issue_comment_url":"https://api.github.com/repos/a2o/snoopy/issues/comments{/number}","contents_url":"https://api.github.com/repos/a2o/snoopy/contents/{+path}","compare_url":"https://api.github.com/repos/a2o/snoopy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/a2o/snoopy/merges","archive_url":"https://api.github.com/repos/a2o/snoopy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/a2o/snoopy/downloads","issues_url":"https://api.github.com/repos/a2o/snoopy/issues{/number}","pulls_url":"https://api.github.com/repos/a2o/snoopy/pulls{/number}","milestones_url":"https://api.github.com/repos/a2o/snoopy/milestones{/number}","notifications_url":"https://api.github.com/repos/a2o/snoopy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/a2o/snoopy/labels{/name}","releases_url":"https://api.github.com/repos/a2o/snoopy/releases{/id}","created_at":"2012-12-19T22:52:06Z","updated_at":"2015-03-23T04:41:26Z","pushed_at":"2015-03-26T15:16:48Z","git_url":"git://github.com/a2o/snoopy.git","ssh_url":"git@github.com:a2o/snoopy.git","clone_url":"https://github.com/a2o/snoopy.git","svn_url":"https://github.com/a2o/snoopy","homepage":"","size":1182,"stargazers_count":138,"watchers_count":138,"language":"Shell","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":3,"forks":18,"open_issues":3,"watchers":138,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/a2o/snoopy/pulls/35"},"html":{"href":"https://github.com/a2o/snoopy/pull/35"},"issue":{"href":"https://api.github.com/repos/a2o/snoopy/issues/35"},"comments":{"href":"https://api.github.com/repos/a2o/snoopy/issues/35/comments"},"review_comments":{"href":"https://api.github.com/repos/a2o/snoopy/pulls/35/comments"},"review_comment":{"href":"https://api.github.com/repos/a2o/snoopy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/a2o/snoopy/pulls/35/commits"},"statuses":{"href":"https://api.github.com/repos/a2o/snoopy/statuses/b05972a39bc07e0ec7825519e39624f76bd9053d"}}}}