Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-08-18
01:23
Merge [b8a61a0657b7f284], "For now, disable posix_spawnp, until we have a better solution for [407b7... check-in: c3525223e0 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE
2024-05-22
20:28 • Ticket [407b70361c] New test failures. Maybe unix pipe troubles? status sti... artifact: ce8f76d61d user: chw
17:24 • Ticket [407b70361c]: 5 changes artifact: 13a9e117f9 user: gustafn3
14:14 • Ticket [407b70361c]: 5 changes artifact: 82233f7175 user: chw
11:38 • Ticket [407b70361c]: 5 changes artifact: af9e0ba784 user: jan.nijtmans
11:29
Christian's proposal for [407b70361c]: New test failures. Maybe unix pipe troubles? Not sure if this... closed check-in: 039305c274 user: jan.nijtmans tags: bug-407b70361c
06:33 • Ticket [407b70361c] New test failures. Maybe unix pipe troubles? status sti... artifact: d4e5a3d94c user: oehhar
2024-05-21
15:00 • Ticket [407b70361c]: 5 changes artifact: 08ed9b0ea0 user: chw
2023-07-26
07:17 • Closed ticket [407b70361c]. artifact: b8c152a35f user: jan.nijtmans
2023-07-25
09:38 • Ticket [407b70361c]: 3 changes artifact: f73965a624 user: gustafn3
2023-07-24
21:08 • Ticket [407b70361c]: 3 changes artifact: 81c814ac97 user: chw
20:38 • Ticket [407b70361c]: 3 changes artifact: 94ce84934f user: jan.nijtmans
18:17 • Ticket [407b70361c]: 3 changes artifact: 86e561e7cf user: gustafn3
17:31 • Ticket [407b70361c]: 3 changes artifact: 16d2a048af user: gustafn3
15:25 • Pending ticket [407b70361c]. artifact: c5c21efcb1 user: dgp
15:16 • Ticket [407b70361c]: 3 changes artifact: 4d439b47a3 user: jan.nijtmans
15:12
For now, disable posix_spawnp, until we have a better solution for [407b70361c148773] check-in: 0343f0babb user: jan.nijtmans tags: core-8-6-branch
14:26 • New ticket [407b70361c] New test failures. Maybe unix pipe troubles?. artifact: 701b2d2e57 user: dgp

New test failures. Maybe unix pipe troubles?

Closed / Fixed407b70361c1487732ef3e1fff67d61e60903431aCreated 3 years agoUpdated 3 years ago
Descriptionplain2023-07-24 14:26:54
On a CentOS 7.9 system there are new test failures on the tip of 8.6 branch:

==== exec-9.1 commands returning errors FAILED
==== Contents of test case:

    set x [catch {exec gorp456} msg]
    list $x [string tolower $msg] [string tolower $errorCode]

---- Result was:
1 {child process exited abnormally} {childstatus 30357 127}
---- Result should have been (exact matching):
1 {couldn't execute "gorp456": no such file or directory} {posix enoent {no such file or directory}}
==== exec-9.1 FAILED



==== exec-9.2 commands returning errors FAILED
==== Contents of test case:

    string tolower [list [catch {exec [interpreter] echo foo | foo123} msg] $msg $errorCode]

---- Result was:
1 {error writing "stdout": broken pipe
    while executing
"puts {}"
    (file "echo" line 6)} {childstatus 30359 127}
---- Result should have been (exact matching):
1 {couldn't execute "foo123": no such file or directory} {posix enoent {no such file or directory}}
==== exec-9.2 FAILED



==== exec-9.5 commands returning errors FAILED
==== Contents of test case:

    exec gorp456 | [interpreter] echo a b c

---- Result was:
a b c
child process exited abnormally
---- Result should have been (exact matching):
couldn't execute "gorp456": no such file or directory
==== exec-9.5 FAILED



==== exec-13.3 setting errorCode variable FAILED
==== Contents of test case:

    set x [catch {exec _weird_cmd_} msg]
    list $x [string tolower $msg] [lindex $errorCode 0]  [string tolower [lrange $errorCode 2 end]]

---- Result was:
1 {child process exited abnormally} CHILDSTATUS 127
---- Result should have been (exact matching):
1 {couldn't execute "_weird_cmd_": no such file or directory} POSIX {{no such file or directory}}
==== exec-13.3 FAILED



==== exec-14.4 -- switch FAILED
==== Contents of test case:

    exec -- -gorp

---- Result was:
child process exited abnormally
---- Result should have been (exact matching):
couldn't execute "-gorp": no such file or directory
==== exec-14.4 FAILED



==== exec-17.1 inheriting standard I/O FAILED
==== Contents of test case:

    catch {exec [interpreter] $path(script)} result
    list $result [readfile $path(gorp.file)]

---- Result was:
{} {}
---- Result should have been (exact matching):
{} foobar
==== exec-17.1 FAILED


==== iocmd-11.4 I/O to command pipelines FAILED
==== Contents of test case:

    list [catch {open "| no_such_command_exists" rb} msg] $msg $::errorCode

---- Result was:
0 file3 {TCL OPERATION EXEC BADREDIRECT}
---- Result should have been (exact matching):
1 {couldn't execute "no_such_command_exists": no such file or directory} {POSIX ENOENT {no such file or directory}}
==== iocmd-11.4 FAILED
Referenced by1
  • 039305c274Christian's proposal for [407b70361c]: New test failures. Maybe unix pipe troubles? Not sure if this is really needed. check-in2024-05-22 11:29:26
jan.nijtmanswiki2023-07-24 15:16:37

Thanks! I disabled the usage of posix_spawnp now, until this is sorted out.

Ideas welcome!

dgpplain2023-07-24 15:25:06

Back to clean `make test-tcl` again on the branch tip.
gustafn3plain2023-07-24 17:31:46
I can confirm the problem. It looks to me like a bug in the version of libc that is used in CentOS 7. The spawn call on CentOS returns a valid PID and a status code of 0, indicating success, while on other systems, the proper error code is returned.

CentOS 7 ships with GNU libc 2.17, which was released 2012-12-25 (more than 10 years old). For example, Ubuntu 20.04 (not a forefront version, either) ships with GLIBC 2.31. The changelog of GNU libc shows various fixes for posix_spawn after 2.17.

I will add a fix to the posix-spawn branch this evening or tomorrow.
gustafn3plain2023-07-24 18:17:33
When I try to commit the patch to the original posix_spawn branch, fossil tells me, that I "cannot commit against a closed leaf". What is the right policy in such cases? Create a new branch for this ticket?
jan.nijtmanswiki2023-07-24 20:38:35

I created the "bug-c54e4a1aeb" for doing experiments on this problem, so feel free to commit it there. But any other (new) branch is OK too.

The orginal posix_spawn branch is already merged to core-8-6-branch, that's why it's closed

chwplain2023-07-24 21:08:12
I believe it was fixed in GLIBC 2.24 and later, see work around in

  https://www.androwish.org/home/info/a0fe363cc68e5e24
gustafn3plain2023-07-25 09:38:40
The patch in this branch (bug-c54e4a1aeb) fixes the problem and was 
tested with CentOS 7.9 and also with macOS 13.4, Ubuntu 20.04, 
and OpenBSD 7.2. 

The patch uses vfork(), which has in essence the same memory 
characteristics but has broader support (just deprecated under 
macOS, where it will not be used). If there is interest, I can 
collect the performance characteristics for Linux similar to 
https://core.tcl-lang.org/tcl/tktview/c54e4a1aeb
jan.nijtmans Closed ticket [407b70361c]. [History diff]2023-07-26 07:17:28
chwplain2024-05-21 15:00:43
I've observed exec-17.1 failing on Debian 9 exactly as in the
ticket's description. My remedy was to mimic the FD_CLOEXEC
semantics as close as possible before the posix_spawnp() and
cleaning up right after, see

  https://www.androwish.org/home/info/929b393ec4e7f0a4

for a patch.
oehharwiki2024-05-22 06:33:45

Hi magic Christian! Thanks for the patch, I appreciate. I will try to find a wizard able to handle it.

Take care, Harald

jan.nijtmanswiki2024-05-22 11:38:03

Christian's proposal committed to a [branch]

However, I'm not convinced this is still needed. This ticket is already closed (with help from Gustaf Neumann), by switching from fork to posix_spawnp.

Christian, did you observe exec-17.1 failing in androwish or in Tcl 8.6? That's quite a difference ..... Androwish didn't take over all changes from Tcl 8.6.

So, for now, keeping closed ;-)

chwplain2024-05-22 14:14:20
Let me explain what the change is for in regard to exec-17.1:
The test constructs a scenario where

 posix_spawn_file_actions_adddup2(&actions, 1, 1)

is set where the file descriptor 1 has the FD_CLOEXEC set due
to stdout being closed and a plain file opened. When this
call does nothing or fails (since we're dup'ing 1 to 1)
the exec does not get passed file descriptor 1 anymore
(remember FD_CLOEXEC still set) and the test fails.

Are there any guarantees in p_s_f_a_a() regarding this case?
I think not, and this potentially varies between C lib versions.
So it is not a bad idea to catch these special cases for the
file descriptors 0, 1, and 2.

BTW: I observed it in my AndroWish branch on Debian 9 which
is quite old indeed. Did the patch break things in different
ways on other (newer) systems?
gustafn3plain2024-05-22 17:24:26
Debian 9 is quite old (initially released on June 17th, 2017, 
security updates have been discontinued as of July 6th, 2020).

The implementation of TclpCreateProcess() uses now vfork() on most systems 
(recent Linux versions, macOS). Part of the "fix" of the problem was to make
sure, that configure picks up the "USE_VFORK" preprocessor flag. 
Isn't this also an option for AndroWish?

I do not think that the fix of chw breaks other systems, but I am not fully
convinced, that it helps as it is under all conditions (dirty reads?)
chwplain2024-05-22 20:28:12
Gustaf,

yep, Debian 9 is dead. But I still insist on the semantic of

posix_spawn_file_actions_adddup2(&actions, 1, 1)

If it does not really dup, then the FD_CLOEXEC is not cleared.
Since dup() seems to do this by POSIX definition (but see below).

If you analyze the olden forkery, the trick is that the child
before exec fixes the three nasty 0/1/2 file descriptors 
to be not FD_CLOEXEC.

And then there's specially hackery for the ultra dead Ultrix
in SetupStdFile(). Since Ultrix does not clear FD_CLOEXEC on
the dup'ed fd (see above).

IMO too much variables and no certainty and no proper definition
of p_s_f_a_a in POSIX so better make things safe.

If you don't like that patch, no problem, I will live with it.
Log in (anonymous is fine) to add a comment.