-
Notifications
You must be signed in to change notification settings - Fork 31
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
open file descriptors of the shell aren't inherited by processes launched by the shell, unlike bash or zsh #747
Comments
This is historic ksh93 behaviour. File descriptors > 2 opened with On ksh 93u+m, the easiest way to work around this is to enable the Another way to work around this (if you don't want to enable posix mode) is to explicitly redirect the file descriptor to itself as part of the external command invocation, which overrides the close-on-exec flag. But that only works with constant file descriptor numbers < 10, e.g.: exec 4<.profile
flock 4 4<&4 Perhaps we need a separate shell option to control this behaviour… |
I assume the extent of
What exactly does "that only works with constant file descriptor numbers < 10" mean? It doesn't work with the |
You can also simply use Also most shells with a |
In my testing, file descriptors opened with I'm not sure how this is happening, BTW--I don't see |
Actually it's just broken. It opens the file and closes it immediately for some reason. Weirdly opens on one FD, DUP's it somewhere else, and closes both. (cmd)ormaaj 114 (675660) 0 ~ $ strace -DDYYyqqfb execve -e t=%desc -P /dev/null -- ksh -xo posix -c 'if [[ ! -v .sh.pid ]]; then builtin pids; function .sh.pid.get { .sh.value=$(pids -f "%(pid)d") ; }; fi; : {fd}</dev/null; lsfd -p "${.sh.pid}" -Q "FD == ${fd}" -o +flags'
newfstatat(AT_FDCWD</home/ormaaj>, "/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(0x1, 0x3), ...}, 0) = 0
newfstatat(AT_FDCWD</home/ormaaj>, "/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(0x1, 0x3), ...}, 0) = 0
+ [[ ! -v .sh.pid ]]
+ :
openat(AT_FDCWD</home/ormaaj>, "/dev/null", O_RDONLY) = 3</dev/null>
+ {fd}< /dev/null
fcntl(3</dev/null>, F_DUPFD, 10) = 10</dev/null>
close(3</dev/null>) = 0
ioctl(10</dev/null>, TCGETS, 0x7ffca4363f80) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(10</dev/null>, 0, SEEK_CUR) = 0
fstat(10</dev/null>, {st_mode=S_IFCHR|0666, st_rdev=makedev(0x1, 0x3), ...}) = 0
close(10</dev/null>) = 0
+ lsfd -p 3203860 -Q 'FD == 10' -o +flags
ksh -xc 'exec {fd}<<<foo'
+ exec }<<< foo
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
compare ksh:
and bash:
zsh behaves like bash
this breaks patterns like
since
flock(1)
doesn't see that file descriptor as openstrace
shows ksh launches processes withvfork(2)
, while bash usesclone(2)
; maybe this is the cause of the difference?The text was updated successfully, but these errors were encountered: