Skip to content

Commit

Permalink
Use fork()/exec() instead of posix_spawn() by default
Browse files Browse the repository at this point in the history
Using posix_spawn() may result in a race condition while setting
terminal foreground process group. Copying dgk's response from related
discussion in ast-developers mailing list:

"
ksh93 uses posix_spawn() rather than fork/exec to run a simple command
for performance reasons.  However, posix_spawnv() doesn't have a way to
set the terminal group before the exec().  The parent process sets the
terminal group which leads to the race.

There is a simple change you can make to a program to guarentee that
the terminal will get set at the beginning of the program.
You can add two lines.  One line is
        #include        <termios.h>

and for the other line
        tcsetpgrp(2,getpgrp());

Alternatively, you can write a program that does these two lines and then
execs the original program.
"

Only way to reliably fix this problem in ksh is to switch back to fork()/
exec().

If there are any performance regressions or bugs caused by this change,
you can switch to posix_spawn() by setting '-D_AST_no_spawnveg=0'.

Related: #468
Related: rhbz#1160482
  • Loading branch information
siteshwar committed Apr 13, 2018
1 parent 6815d6c commit 566ec82
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ endif

shared_c_args = [
'-DUSAGE_LICENSE=""',
'-D_AST_no_spawnveg=1',
]

# Compiler arguments used when building `ksh93`, `shcomp`, and related AST
Expand Down

0 comments on commit 566ec82

Please sign in to comment.