[lxc-devel] [PATCH] only re-open fds if stdin is a tty
Stéphane Graber
stgraber at ubuntu.com
Fri Nov 6 18:15:10 UTC 2015
On Fri, Oct 30, 2015 at 05:14:12AM +0000, Serge Hallyn wrote:
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/lxc_usernsexec.c | 30 ++++++++++++++++--------------
> 1 file changed, 16 insertions(+), 14 deletions(-)
>
> diff --git a/src/lxc/lxc_usernsexec.c b/src/lxc/lxc_usernsexec.c
> index 26608d6..37d92fb 100644
> --- a/src/lxc/lxc_usernsexec.c
> +++ b/src/lxc/lxc_usernsexec.c
> @@ -278,20 +278,22 @@ int main(int argc, char *argv[])
> memset(ttyname0, '\0', sizeof(ttyname0));
> memset(ttyname1, '\0', sizeof(ttyname1));
> memset(ttyname2, '\0', sizeof(ttyname2));
> - ret = readlink("/proc/self/fd/0", ttyname0, sizeof(ttyname0));
> - if (ret < 0) {
> - perror("unable to open stdin.");
> - exit(1);
> - }
> - ret = readlink("/proc/self/fd/1", ttyname1, sizeof(ttyname1));
> - if (ret < 0) {
> - printf("Warning: unable to open stdout, continuing.");
> - memset(ttyname1, '\0', sizeof(ttyname1));
> - }
> - ret = readlink("/proc/self/fd/2", ttyname2, sizeof(ttyname2));
> - if (ret < 0) {
> - printf("Warning: unable to open stderr, continueing.");
> - memset(ttyname2, '\0', sizeof(ttyname2));
> + if (isatty(0)) {
> + ret = readlink("/proc/self/fd/0", ttyname0, sizeof(ttyname0));
> + if (ret < 0) {
> + perror("unable to open stdin.");
> + exit(1);
> + }
> + ret = readlink("/proc/self/fd/1", ttyname1, sizeof(ttyname1));
> + if (ret < 0) {
> + printf("Warning: unable to open stdout, continuing.");
> + memset(ttyname1, '\0', sizeof(ttyname1));
> + }
> + ret = readlink("/proc/self/fd/2", ttyname2, sizeof(ttyname2));
> + if (ret < 0) {
> + printf("Warning: unable to open stderr, continueing.");
> + memset(ttyname2, '\0', sizeof(ttyname2));
> + }
> }
>
> lxc_list_init(&active_map);
> --
> 2.5.0
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20151106/bcff48e9/attachment.sig>
More information about the lxc-devel
mailing list