Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tail +1c doesn't work when stdin is from terminal #499

Open
falsifian opened this issue May 4, 2021 · 4 comments · May be fixed by #658
Open

tail +1c doesn't work when stdin is from terminal #499

falsifian opened this issue May 4, 2021 · 4 comments · May be fixed by #658

Comments

@falsifian
Copy link
Contributor

Running in xterm:

falsifian moth ~ $ 9 tail +1c
hello
hello
falsifian moth ~ $ echo hello | 9 tail +1c
ello

For some reason, in the first case, it's not skipping the "h". The effect is similar with numbers other than 1.

This is plan9port-20210323 from OpenBSD ports, which should be at commit 88a87fa

@orthros
Copy link

orthros commented May 8, 2021

This seems to be an OpenBSD Issue, or has been resolved by a later commit. I tried it on Debian at commit 70cc6e5, and the behaviour seems consistent.

root@ae6a19674251:/src/plan9port# 9 tail +1c
hello
ello
^C
root@ae6a19674251:/src/plan9port# echo hello | 9 tail +1c
ello
root@ae6a19674251:/src/plan9port# 

I'll try on an OpenBSD machine later today and see if I can reproduce.

@orthros
Copy link

orthros commented May 8, 2021

Just installed OpenBSD from the amd64/install69.iso into a VM, ran pkg_add git, cloned this repository at 70cc6e5 and ran ./INSTALL

planport# 9 tail +1c
hello
hello
^C
planport# echo "hello" | 9 tail +1c
ello

So the issue is for sure not fixed after 88a87fa.

I suspect there is some issue with the way STDIN is being read by the utility on BSD systems (but not Linux). Will take a look at some point, but I'm not terribly familiar with BSD systems so I might not be a great help.

@falsifian
Copy link
Contributor Author

Thanks for taking the time to reproduce it.

I can also take a look, but it might be a few days before I get around to it. I'm not deeply familiar with the quirks of reading, writing and terminals but it could be a learning experience for me.

@jxy
Copy link
Contributor

jxy commented May 11, 2021

From truss(1) on FreeBSD,

[ ... omit ...]
getcontext(0x7fffffffd320)                       = 0 (0x0)
sysarch(AMD64_GET_XFPUSTATE,0x7fffffffd2e8)      = 0 (0x0)
mprotect(0x20f000,4096,PROT_READ)                = 0 (0x0)
getpid()                                         = 63815 (0xf947)
lseek(0,0x0,SEEK_SET)                            = 0 (0x0)
lseek(0,0x1,SEEK_SET)                            = 1 (0x1)
hello
read(0,"hello\n",8192)                           = 6 (0x6)
hello
write(1,"hello\n",6)                             = 6 (0x6)

comparing to using pipe,

[ ... omit ...]
getcontext(0x7fffffffd320)                       = 0 (0x0)
sysarch(AMD64_GET_XFPUSTATE,0x7fffffffd2e8)      = 0 (0x0)
mprotect(0x20f000,4096,PROT_READ)                = 0 (0x0)
getpid()                                         = 68480 (0x10b80)
lseek(0,0x0,SEEK_SET)                            ERR#29 'Illegal seek'
read(0,"h",1)                                    = 1 (0x1)
read(0,"ello\n",8192)                            = 5 (0x5)
ello
write(1,"ello\n",5)                              = 5 (0x5)

comparing to strace(1) on Linux,

[ ... omit ...]
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
getpid()                                = 126670
lseek(0, 0, SEEK_SET)                   = -1 ESPIPE (Illegal seek)
read(0, hello
"h", 1)                         = 1
read(0, "ello\n", 8192)                 = 5
write(1, "ello\n", 5ello
)                   = 5

which means the line seekable = seek(file,0L,0) == 0; makes seekable = 1 with file = 0 and is not a proper test on BSD when input is from tty.

@falsifian falsifian linked a pull request Jun 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants