{"action":"created","comment":{"url":"https://api.github.com/repos/systemd/systemd/pulls/comments/91829269","pull_request_review_id":12342387,"id":91829269,"diff_hunk":"@@ -408,59 +408,66 @@ int detect_container(void) {\n         if (cached_found >= 0)\n                 return cached_found;\n \n-        /* /proc/vz exists in container and outside of the container,\n-         * /proc/bc only outside of the container. */\n+        /* /proc/vz exists in container and outside of the container, /proc/bc only outside of the container. */\n         if (access(\"/proc/vz\", F_OK) >= 0 &&\n             access(\"/proc/bc\", F_OK) < 0) {\n                 r = VIRTUALIZATION_OPENVZ;\n                 goto finish;\n         }\n \n         if (getpid() == 1) {\n-                /* If we are PID 1 we can just check our own\n-                 * environment variable */\n+                /* If we are PID 1 we can just check our own environment variable, and that's authoritative. */\n \n                 e = getenv(\"container\");\n                 if (isempty(e)) {\n                         r = VIRTUALIZATION_NONE;\n                         goto finish;\n                 }\n-        } else {\n-\n-                /* Otherwise, PID 1 dropped this information into a\n-                 * file in /run. This is better than accessing\n-                 * /proc/1/environ, since we don't need CAP_SYS_PTRACE\n-                 * for that. */\n-\n-                r = read_one_line_file(\"/run/systemd/container\", &m);\n-                if (r == -ENOENT) {\n-\n-                        /* Fallback for cases where PID 1 was not\n-                         * systemd (for example, cases where\n-                         * init=/bin/sh is used. */\n-\n-                        r = getenv_for_pid(1, \"container\", &m);\n-                        if (r <= 0) {\n-\n-                                /* If that didn't work, give up,\n-                                 * assume no container manager.\n-                                 *\n-                                 * Note: This means we still cannot\n-                                 * detect containers if init=/bin/sh\n-                                 * is passed but privileges dropped,\n-                                 * as /proc/1/environ is only readable\n-                                 * with privileges. */\n-\n-                                r = VIRTUALIZATION_NONE;\n-                                goto finish;\n-                        }\n-                }\n-                if (r < 0)\n-                        return r;\n \n+                goto translate_name;\n+        }\n+\n+        /* Otherwise, PID 1 might have dropped this information into a file in /run. This is better than accessing\n+         * /proc/1/environ, since we don't need CAP_SYS_PTRACE for that. */\n+        r = read_one_line_file(\"/run/systemd/container\", &m);\n+        if (r >= 0) {\n+                e = m;\n+                goto translate_name;\n+        }\n+        if (r != -ENOENT)\n+                return log_debug_errno(r, \"Failed to read /run/systemd/container: %m\");\n+\n+        /* Fallback for cases where PID 1 was not systemd (for example, cases where init=/bin/sh is used. */\n+        r = getenv_for_pid(1, \"container\", &m);\n+        if (r > 0) {\n                 e = m;\n+                goto translate_name;\n         }\n+        if (r < 0) /* This only works if we have CAP_SYS_PTRACE, hence let's better ignore failures here */\n+                log_debug_errno(r, \"Failed to read $container of PID 1, ignoring: %m\");\n+\n+        /* Interestingly /proc/1/sched actually shows the host's PID for what we see as PID 1. Hence, if the PID shown\n+         * there is not 1, we know we are in a PID namespace. and hence a container. */","path":"src/basic/virt.c","position":79,"original_position":79,"commit_id":"a195a39565f884e80830c62632427d25537052d4","original_commit_id":"4ea47ba822a7543f3dace6539746179a832dd535","user":{"login":"evverx","id":10195800,"avatar_url":"https://avatars.githubusercontent.com/u/10195800?v=3","gravatar_id":"","url":"https://api.github.com/users/evverx","html_url":"https://github.com/evverx","followers_url":"https://api.github.com/users/evverx/followers","following_url":"https://api.github.com/users/evverx/following{/other_user}","gists_url":"https://api.github.com/users/evverx/gists{/gist_id}","starred_url":"https://api.github.com/users/evverx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evverx/subscriptions","organizations_url":"https://api.github.com/users/evverx/orgs","repos_url":"https://api.github.com/users/evverx/repos","events_url":"https://api.github.com/users/evverx/events{/privacy}","received_events_url":"https://api.github.com/users/evverx/received_events","type":"User","site_admin":false},"body":"BTW `/proc/sched_debug` shows all PIDs\r\n```\r\n$ sudo unshare -m -r -p --fork\r\nroot# mount -t proc proc /proc/\r\nroot# ls -ld /proc/[0-9]*\r\ndr-xr-xr-x. 9 root root 0 Dec  9 20:33 /proc/1\r\n\r\nroot# cat /proc/sched_debug\r\n...\r\nrunnable tasks:\r\n            task   PID         tree-key  switches  prio     wait-time             sum-exec        sum-sleep\r\n----------------------------------------------------------------------------------------------------------\r\n         systemd     1      1686.381119     12834   120         0.000000      3615.212379         0.000000 0 0 /autogroup-1\r\n        kthreadd     2   8782239.071408       229   120         0.000000         8.430006         0.000000 0 0 /\r\n       rcu_sched     7   8836876.912550   1646755   120         0.000000     17015.113005         0.000000 0 0 /\r\n         rcuos/0     9   8836876.908468    771400   120         0.000000     14528.329564         0.000000 0 0 /\r\n         cpuhp/1    15      1849.308648         5   120         0.000000         0.070217         0.000000 0 0 /\r\n      watchdog/1    16        -2.995507     10052     0         0.000000        26.655114         0.000000 0 0 /\r\n     migration/1    17         0.000000     61890     0         0.000000       628.149950         0.000000 0 0 /\r\n...\r\n```\r\nHm...","created_at":"2016-12-10T05:13:43Z","updated_at":"2016-12-10T05:13:43Z","html_url":"https://github.com/systemd/systemd/pull/4845#discussion_r91829269","pull_request_url":"https://api.github.com/repos/systemd/systemd/pulls/4845","_links":{"self":{"href":"https://api.github.com/repos/systemd/systemd/pulls/comments/91829269"},"html":{"href":"https://github.com/systemd/systemd/pull/4845#discussion_r91829269"},"pull_request":{"href":"https://api.github.com/repos/systemd/systemd/pulls/4845"}}},"pull_request":{"url":"https://api.github.com/repos/systemd/systemd/pulls/4845","id":96818603,"html_url":"https://github.com/systemd/systemd/pull/4845","diff_url":"https://github.com/systemd/systemd/pull/4845.diff","patch_url":"https://github.com/systemd/systemd/pull/4845.patch","issue_url":"https://api.github.com/repos/systemd/systemd/issues/4845","number":4845,"state":"open","locked":false,"title":"Various smaller fixes","user":{"login":"poettering","id":2130732,"avatar_url":"https://avatars.githubusercontent.com/u/2130732?v=3","gravatar_id":"","url":"https://api.github.com/users/poettering","html_url":"https://github.com/poettering","followers_url":"https://api.github.com/users/poettering/followers","following_url":"https://api.github.com/users/poettering/following{/other_user}","gists_url":"https://api.github.com/users/poettering/gists{/gist_id}","starred_url":"https://api.github.com/users/poettering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poettering/subscriptions","organizations_url":"https://api.github.com/users/poettering/orgs","repos_url":"https://api.github.com/users/poettering/repos","events_url":"https://api.github.com/users/poettering/events{/privacy}","received_events_url":"https://api.github.com/users/poettering/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-12-06T22:21:12Z","updated_at":"2016-12-10T05:13:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2600bca4a92645385ae00899b8a07d34797d0d02","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/systemd/systemd/pulls/4845/commits","review_comments_url":"https://api.github.com/repos/systemd/systemd/pulls/4845/comments","review_comment_url":"https://api.github.com/repos/systemd/systemd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/systemd/systemd/issues/4845/comments","statuses_url":"https://api.github.com/repos/systemd/systemd/statuses/a195a39565f884e80830c62632427d25537052d4","head":{"label":"poettering:various-smaller-fixes","ref":"various-smaller-fixes","sha":"a195a39565f884e80830c62632427d25537052d4","user":{"login":"poettering","id":2130732,"avatar_url":"https://avatars.githubusercontent.com/u/2130732?v=3","gravatar_id":"","url":"https://api.github.com/users/poettering","html_url":"https://github.com/poettering","followers_url":"https://api.github.com/users/poettering/followers","following_url":"https://api.github.com/users/poettering/following{/other_user}","gists_url":"https://api.github.com/users/poettering/gists{/gist_id}","starred_url":"https://api.github.com/users/poettering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poettering/subscriptions","organizations_url":"https://api.github.com/users/poettering/orgs","repos_url":"https://api.github.com/users/poettering/repos","events_url":"https://api.github.com/users/poettering/events{/privacy}","received_events_url":"https://api.github.com/users/poettering/received_events","type":"User","site_admin":false},"repo":{"id":37097921,"name":"systemd","full_name":"poettering/systemd","owner":{"login":"poettering","id":2130732,"avatar_url":"https://avatars.githubusercontent.com/u/2130732?v=3","gravatar_id":"","url":"https://api.github.com/users/poettering","html_url":"https://github.com/poettering","followers_url":"https://api.github.com/users/poettering/followers","following_url":"https://api.github.com/users/poettering/following{/other_user}","gists_url":"https://api.github.com/users/poettering/gists{/gist_id}","starred_url":"https://api.github.com/users/poettering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poettering/subscriptions","organizations_url":"https://api.github.com/users/poettering/orgs","repos_url":"https://api.github.com/users/poettering/repos","events_url":"https://api.github.com/users/poettering/events{/privacy}","received_events_url":"https://api.github.com/users/poettering/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/poettering/systemd","description":"systemd upstream","fork":true,"url":"https://api.github.com/repos/poettering/systemd","forks_url":"https://api.github.com/repos/poettering/systemd/forks","keys_url":"https://api.github.com/repos/poettering/systemd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/poettering/systemd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/poettering/systemd/teams","hooks_url":"https://api.github.com/repos/poettering/systemd/hooks","issue_events_url":"https://api.github.com/repos/poettering/systemd/issues/events{/number}","events_url":"https://api.github.com/repos/poettering/systemd/events","assignees_url":"https://api.github.com/repos/poettering/systemd/assignees{/user}","branches_url":"https://api.github.com/repos/poettering/systemd/branches{/branch}","tags_url":"https://api.github.com/repos/poettering/systemd/tags","blobs_url":"https://api.github.com/repos/poettering/systemd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/poettering/systemd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/poettering/systemd/git/refs{/sha}","trees_url":"https://api.github.com/repos/poettering/systemd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/poettering/systemd/statuses/{sha}","languages_url":"https://api.github.com/repos/poettering/systemd/languages","stargazers_url":"https://api.github.com/repos/poettering/systemd/stargazers","contributors_url":"https://api.github.com/repos/poettering/systemd/contributors","subscribers_url":"https://api.github.com/repos/poettering/systemd/subscribers","subscription_url":"https://api.github.com/repos/poettering/systemd/subscription","commits_url":"https://api.github.com/repos/poettering/systemd/commits{/sha}","git_commits_url":"https://api.github.com/repos/poettering/systemd/git/commits{/sha}","comments_url":"https://api.github.com/repos/poettering/systemd/comments{/number}","issue_comment_url":"https://api.github.com/repos/poettering/systemd/issues/comments{/number}","contents_url":"https://api.github.com/repos/poettering/systemd/contents/{+path}","compare_url":"https://api.github.com/repos/poettering/systemd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/poettering/systemd/merges","archive_url":"https://api.github.com/repos/poettering/systemd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/poettering/systemd/downloads","issues_url":"https://api.github.com/repos/poettering/systemd/issues{/number}","pulls_url":"https://api.github.com/repos/poettering/systemd/pulls{/number}","milestones_url":"https://api.github.com/repos/poettering/systemd/milestones{/number}","notifications_url":"https://api.github.com/repos/poettering/systemd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/poettering/systemd/labels{/name}","releases_url":"https://api.github.com/repos/poettering/systemd/releases{/id}","deployments_url":"https://api.github.com/repos/poettering/systemd/deployments","created_at":"2015-06-08T23:07:59Z","updated_at":"2016-10-21T11:39:31Z","pushed_at":"2016-12-07T20:28:41Z","git_url":"git://github.com/poettering/systemd.git","ssh_url":"git@github.com:poettering/systemd.git","clone_url":"https://github.com/poettering/systemd.git","svn_url":"https://github.com/poettering/systemd","homepage":"http://www.freedesktop.org/wiki/Software/systemd/","size":64168,"stargazers_count":3,"watchers_count":3,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":3,"default_branch":"master"}},"base":{"label":"systemd:master","ref":"master","sha":"73e383cc62c57aedbac26b969a6194c0841a7c99","user":{"login":"systemd","id":1918868,"avatar_url":"https://avatars.githubusercontent.com/u/1918868?v=3","gravatar_id":"","url":"https://api.github.com/users/systemd","html_url":"https://github.com/systemd","followers_url":"https://api.github.com/users/systemd/followers","following_url":"https://api.github.com/users/systemd/following{/other_user}","gists_url":"https://api.github.com/users/systemd/gists{/gist_id}","starred_url":"https://api.github.com/users/systemd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/systemd/subscriptions","organizations_url":"https://api.github.com/users/systemd/orgs","repos_url":"https://api.github.com/users/systemd/repos","events_url":"https://api.github.com/users/systemd/events{/privacy}","received_events_url":"https://api.github.com/users/systemd/received_events","type":"Organization","site_admin":false},"repo":{"id":32873313,"name":"systemd","full_name":"systemd/systemd","owner":{"login":"systemd","id":1918868,"avatar_url":"https://avatars.githubusercontent.com/u/1918868?v=3","gravatar_id":"","url":"https://api.github.com/users/systemd","html_url":"https://github.com/systemd","followers_url":"https://api.github.com/users/systemd/followers","following_url":"https://api.github.com/users/systemd/following{/other_user}","gists_url":"https://api.github.com/users/systemd/gists{/gist_id}","starred_url":"https://api.github.com/users/systemd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/systemd/subscriptions","organizations_url":"https://api.github.com/users/systemd/orgs","repos_url":"https://api.github.com/users/systemd/repos","events_url":"https://api.github.com/users/systemd/events{/privacy}","received_events_url":"https://api.github.com/users/systemd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/systemd/systemd","description":"systemd upstream","fork":false,"url":"https://api.github.com/repos/systemd/systemd","forks_url":"https://api.github.com/repos/systemd/systemd/forks","keys_url":"https://api.github.com/repos/systemd/systemd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/systemd/systemd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/systemd/systemd/teams","hooks_url":"https://api.github.com/repos/systemd/systemd/hooks","issue_events_url":"https://api.github.com/repos/systemd/systemd/issues/events{/number}","events_url":"https://api.github.com/repos/systemd/systemd/events","assignees_url":"https://api.github.com/repos/systemd/systemd/assignees{/user}","branches_url":"https://api.github.com/repos/systemd/systemd/branches{/branch}","tags_url":"https://api.github.com/repos/systemd/systemd/tags","blobs_url":"https://api.github.com/repos/systemd/systemd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/systemd/systemd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/systemd/systemd/git/refs{/sha}","trees_url":"https://api.github.com/repos/systemd/systemd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/systemd/systemd/statuses/{sha}","languages_url":"https://api.github.com/repos/systemd/systemd/languages","stargazers_url":"https://api.github.com/repos/systemd/systemd/stargazers","contributors_url":"https://api.github.com/repos/systemd/systemd/contributors","subscribers_url":"https://api.github.com/repos/systemd/systemd/subscribers","subscription_url":"https://api.github.com/repos/systemd/systemd/subscription","commits_url":"https://api.github.com/repos/systemd/systemd/commits{/sha}","git_commits_url":"https://api.github.com/repos/systemd/systemd/git/commits{/sha}","comments_url":"https://api.github.com/repos/systemd/systemd/comments{/number}","issue_comment_url":"https://api.github.com/repos/systemd/systemd/issues/comments{/number}","contents_url":"https://api.github.com/repos/systemd/systemd/contents/{+path}","compare_url":"https://api.github.com/repos/systemd/systemd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/systemd/systemd/merges","archive_url":"https://api.github.com/repos/systemd/systemd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/systemd/systemd/downloads","issues_url":"https://api.github.com/repos/systemd/systemd/issues{/number}","pulls_url":"https://api.github.com/repos/systemd/systemd/pulls{/number}","milestones_url":"https://api.github.com/repos/systemd/systemd/milestones{/number}","notifications_url":"https://api.github.com/repos/systemd/systemd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/systemd/systemd/labels{/name}","releases_url":"https://api.github.com/repos/systemd/systemd/releases{/id}","deployments_url":"https://api.github.com/repos/systemd/systemd/deployments","created_at":"2015-03-25T15:27:27Z","updated_at":"2016-12-09T19:21:41Z","pushed_at":"2016-12-10T04:33:58Z","git_url":"git://github.com/systemd/systemd.git","ssh_url":"git@github.com:systemd/systemd.git","clone_url":"https://github.com/systemd/systemd.git","svn_url":"https://github.com/systemd/systemd","homepage":"http://www.freedesktop.org/wiki/Software/systemd/","size":79269,"stargazers_count":1506,"watchers_count":1506,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":645,"mirror_url":null,"open_issues_count":538,"forks":645,"open_issues":538,"watchers":1506,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/systemd/systemd/pulls/4845"},"html":{"href":"https://github.com/systemd/systemd/pull/4845"},"issue":{"href":"https://api.github.com/repos/systemd/systemd/issues/4845"},"comments":{"href":"https://api.github.com/repos/systemd/systemd/issues/4845/comments"},"review_comments":{"href":"https://api.github.com/repos/systemd/systemd/pulls/4845/comments"},"review_comment":{"href":"https://api.github.com/repos/systemd/systemd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/systemd/systemd/pulls/4845/commits"},"statuses":{"href":"https://api.github.com/repos/systemd/systemd/statuses/a195a39565f884e80830c62632427d25537052d4"}}}}
{"actor":{"display_login":"evverx"}}