Replies: 5 comments 1 reply
-
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… |
Beta Was this translation helpful? Give feedback.
-
I assume the extent of
What exactly does "that only works with constant file descriptor numbers < 10" mean? It doesn't work with the |
Beta Was this translation helpful? Give feedback.
-
You can also simply use Also most shells with a |
Beta Was this translation helpful? Give feedback.
-
In my testing, file descriptors opened with I'm not sure how this is happening, BTW--I don't see |
Beta Was this translation helpful? Give feedback.
-
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
|
Beta Was this translation helpful? Give feedback.
-
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?Beta Was this translation helpful? Give feedback.
All reactions