{"action":"created","issue":{"url":"https://api.github.com/repos/linuxkit/linuxkit/issues/2233","repository_url":"https://api.github.com/repos/linuxkit/linuxkit","labels_url":"https://api.github.com/repos/linuxkit/linuxkit/issues/2233/labels{/name}","comments_url":"https://api.github.com/repos/linuxkit/linuxkit/issues/2233/comments","events_url":"https://api.github.com/repos/linuxkit/linuxkit/issues/2233/events","html_url":"https://github.com/linuxkit/linuxkit/pull/2233","id":243439131,"number":2233,"title":"getty: Detect if you are in a namespace","user":{"login":"dave-tucker","id":3781777,"avatar_url":"https://avatars3.githubusercontent.com/u/3781777?v=4","gravatar_id":"","url":"https://api.github.com/users/dave-tucker","html_url":"https://github.com/dave-tucker","followers_url":"https://api.github.com/users/dave-tucker/followers","following_url":"https://api.github.com/users/dave-tucker/following{/other_user}","gists_url":"https://api.github.com/users/dave-tucker/gists{/gist_id}","starred_url":"https://api.github.com/users/dave-tucker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dave-tucker/subscriptions","organizations_url":"https://api.github.com/users/dave-tucker/orgs","repos_url":"https://api.github.com/users/dave-tucker/repos","events_url":"https://api.github.com/users/dave-tucker/events{/privacy}","received_events_url":"https://api.github.com/users/dave-tucker/received_events","type":"User","site_admin":false},"labels":[{"id":572728714,"url":"https://api.github.com/repos/linuxkit/linuxkit/labels/status/0-triage","name":"status/0-triage","color":"eeeeee","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2017-07-17T15:43:56Z","updated_at":"2017-07-27T10:22:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/linuxkit/linuxkit/pulls/2233","html_url":"https://github.com/linuxkit/linuxkit/pull/2233","diff_url":"https://github.com/linuxkit/linuxkit/pull/2233.diff","patch_url":"https://github.com/linuxkit/linuxkit/pull/2233.patch"},"body":"This is an attempt at fixing #2213\n\nIf pid 1 isn't /sbin/init we're in a container\nIf we can see `containerd|runc` in the `pstree` then we're in the host\npid namespace but still in a container.\nOtherwise, we're not in a namespace.\n\nI\"ve tested this with getty on `init`, in `services` with both a `host`\nand `new` pid namespace and it seems to work as expected.\n\n![](http://static.fjcdn.com/pictures/I+m+a+detective_3f6516_5349963.jpg)"},"comment":{"url":"https://api.github.com/repos/linuxkit/linuxkit/issues/comments/318322609","html_url":"https://github.com/linuxkit/linuxkit/pull/2233#issuecomment-318322609","issue_url":"https://api.github.com/repos/linuxkit/linuxkit/issues/2233","id":318322609,"user":{"login":"deitch","id":282526,"avatar_url":"https://avatars3.githubusercontent.com/u/282526?v=4","gravatar_id":"","url":"https://api.github.com/users/deitch","html_url":"https://github.com/deitch","followers_url":"https://api.github.com/users/deitch/followers","following_url":"https://api.github.com/users/deitch/following{/other_user}","gists_url":"https://api.github.com/users/deitch/gists{/gist_id}","starred_url":"https://api.github.com/users/deitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deitch/subscriptions","organizations_url":"https://api.github.com/users/deitch/orgs","repos_url":"https://api.github.com/users/deitch/repos","events_url":"https://api.github.com/users/deitch/events{/privacy}","received_events_url":"https://api.github.com/users/deitch/received_events","type":"User","site_admin":false},"created_at":"2017-07-27T10:22:50Z","updated_at":"2017-07-27T10:22:50Z","body":"And... it doesn't work. The problem is that `INITGETTY` is set at the `init` level, so `rungetty` (which is executed directly by it) sees it, but the `sh` itself (which runs `profile.d` does not, since it is launched by `login`, which explicitly destroys the root environment that is passed to the shell (except for `TERM`). You can disable it with `login -p`, but that is a **bad** idea.\r\n\r\nHere is an alternate. Since we know the setting of `INITGETTY` when `rungetty.sh` runs, how about instead of creating `namespace.sh` at _image_ creation time, we change `rungetty.sh` (which knows if `INITGETTY` is set) to (pseudo-code):\r\n\r\n```\r\nif [ -n \"$INITGETTY\" -a ! -f namespace.sh]; then\r\n  # create /etc/profile.d/namespace.sh\r\nfi\r\n```\r\n\r\nThis should work since it will only run if we are in a container and it is safe.\r\n\r\nThoughts?\r\n"}}
{"actor":{"display_login":"deitch"}}