{"action":"created","issue":{"url":"https://api.github.com/repos/systemd/systemd/issues/210","labels_url":"https://api.github.com/repos/systemd/systemd/issues/210/labels{/name}","comments_url":"https://api.github.com/repos/systemd/systemd/issues/210/comments","events_url":"https://api.github.com/repos/systemd/systemd/issues/210/events","html_url":"https://github.com/systemd/systemd/pull/210","id":88479214,"number":210,"title":"nspawn: flush out the tty before exiting","user":{"login":"alban","id":27575,"avatar_url":"https://avatars.githubusercontent.com/u/27575?v=3","gravatar_id":"","url":"https://api.github.com/users/alban","html_url":"https://github.com/alban","followers_url":"https://api.github.com/users/alban/followers","following_url":"https://api.github.com/users/alban/following{/other_user}","gists_url":"https://api.github.com/users/alban/gists{/gist_id}","starred_url":"https://api.github.com/users/alban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alban/subscriptions","organizations_url":"https://api.github.com/users/alban/orgs","repos_url":"https://api.github.com/users/alban/repos","events_url":"https://api.github.com/users/alban/events{/privacy}","received_events_url":"https://api.github.com/users/alban/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-15T16:45:21Z","updated_at":"2015-06-16T11:15:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/systemd/systemd/pulls/210","html_url":"https://github.com/systemd/systemd/pull/210","diff_url":"https://github.com/systemd/systemd/pull/210.diff","patch_url":"https://github.com/systemd/systemd/pull/210.patch"},"body":"Fix: #207 \r\n\r\nThis fixes the issue for me, so @poettering's analysis in https://github.com/systemd/systemd/issues/207#issuecomment-112120149 is correct.\r\n\r\nI don't know what is the best way to add this in `pty_forward_*()`'s API.\r\n\r\n/cc @iaguis "},"comment":{"url":"https://api.github.com/repos/systemd/systemd/issues/comments/112387582","html_url":"https://github.com/systemd/systemd/pull/210#issuecomment-112387582","issue_url":"https://api.github.com/repos/systemd/systemd/issues/210","id":112387582,"user":{"login":"alban","id":27575,"avatar_url":"https://avatars.githubusercontent.com/u/27575?v=3","gravatar_id":"","url":"https://api.github.com/users/alban","html_url":"https://github.com/alban","followers_url":"https://api.github.com/users/alban/followers","following_url":"https://api.github.com/users/alban/following{/other_user}","gists_url":"https://api.github.com/users/alban/gists{/gist_id}","starred_url":"https://api.github.com/users/alban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alban/subscriptions","organizations_url":"https://api.github.com/users/alban/orgs","repos_url":"https://api.github.com/users/alban/repos","events_url":"https://api.github.com/users/alban/events{/privacy}","received_events_url":"https://api.github.com/users/alban/received_events","type":"User","site_admin":false},"created_at":"2015-06-16T11:15:05Z","updated_at":"2015-06-16T11:15:05Z","body":"> Can't we just introduce pty_forward_finalize() or so, which internally just calls wait_for_event(STDOUT_FILENO, POLLOUT) and shovel() in a loop, until there's nothing more?\r\n\r\nWhen testing with a non existent directory (`systemd-nspawn--bind /NA`), the parent fails pretty soon, before the `PTYForward` has been created:\r\n```\r\n                /* Wait for the outer child. */\r\n                r = wait_for_terminate_and_warn(\"namespace helper\", pid, NULL);\r\n```\r\n\r\nSo I cannot directly use `pty_forward_finalize()` here. The `forward` variable is also not in the scope of the `finish:` label.\r\n\r\nShould I create the `PTYForward` sooner? It complicate the error management...\r\n\r\nIn the loop you suggested, I need to exit from the loop when `f->master` is no longer readable. shovel() relies on flags such as `f->master_readable` and they are not updated outside of the event loop. I wrote the following code:\r\n\r\n```\r\nint pty_forward_finalize(PTYForward *f)\r\n{\r\n        int r;\r\n\r\n        for (;;) {\r\n                r = fd_wait_for_event(f->master, POLLIN, 0);\r\n                if (r < 0)\r\n                        return log_error_errno(r, \"Failed to wait for event: %m\");\r\n                if (!(r & POLLIN))\r\n                        return 0;\r\n\r\n                r = fd_wait_for_event(STDOUT_FILENO, POLLOUT, USEC_INFINITY);\r\n                if (r < 0)\r\n                        return log_error_errno(r, \"Failed to wait for event: %m\");\r\n\r\n                r = shovel(f);\r\n                if (r < 0)\r\n                        return r;\r\n        }\r\n\r\n        return 0;\r\n}\r\n```\r\n\r\nIs it what you had in mind?"}}