containers/conmon

There will be extra characters when podman run with `--tty`

zhangguanzhang opened this issue · 5 comments

containers/podman#7196 (comment)

[root@sz-test ~]# podman run --rm  alpine echo 1 | cat -A
1$
[root@sz-test ~]# podman run --rm --tty alpine echo 1 | cat -A
1^M$
    [root@sz-test ~]# 

The problem seems to be here
https://github.com/containers/conmon/blob/master/src/ctr_logging.c#L355-L360
@rhatdan PTAL

thanks for opening the issue @zhangguanzhang! I am not so sure it's that line in particular. if you look at the log line:

[root@sz-test overlay-containers]# cat -A 62189eb5a343e7d14e90df0f5a6d03a00fae3120fccc097ac4a5f3d47cbb9689/userdata/ctr.log
2020-08-05T13:34:22.891045849+08:00 stdout F hello^M$

we see it's a full log line (signified by the F after stdout). if it was a partial line, it would be P

If you look at that line, it checks if (partial) which means we only append the newline if it's a partial line.

I believe this line is from interpreting the terminal pipe as one. I do not think conmon can or should drop these characters. instead, could podman drop these characters if printing the logs @mheon ?

It happens only for one liner, it is gone in case two lines are printed

[psakar@localhost podman]$ podman run --rm --tty busybox echo 1 | cat -A
1^M$
    [psakar@localhost podman]$ podman run --rm --tty busybox echo 1 ; echo 2 | cat -A
1
2$
[psakar@localhost podman]$ 

podman run --rm --tty busybox echo -n 1 | cat -A also works as expected. Seems only the case when output is single line (can be empty) with new line at the end is wrong

mheon commented

Hm. Tend to agree this is Podman reading the log line incorrectly.

I think it works as expected. It is the same behavior I get with docker:

$ podman run --rm --tty busybox echo  1 | cat -A 
1^M$
# docker run --rm --tty alpine echo 1 | cat -A
1^M$

# docker run --rm --tty alpine echo -n 1 | cat -A
1
$ podman run --rm --tty busybox echo  -n 1 | cat -A 
1