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

Use fork()/exec() instead of posix_spawn() by default #470

Merged
merged 2 commits into from
Apr 13, 2018
Merged

Use fork()/exec() instead of posix_spawn() by default #470

merged 2 commits into from
Apr 13, 2018

Conversation

siteshwar
Copy link
Contributor

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

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
@siteshwar
Copy link
Contributor Author

Test cases have started failing with this change. They are not failing if I build with -D_AST_no_spawnveg=1 flag in last stable release. I suspect these failures are related to spawnvex family of functions that were introduced after the last stable release.

spawnvex family of function were introduced after the last stable
release as an improvement over spawnveg. They were being compiled even
when _AST_no_spawnveg macro was defined. This was causing test cases to
fail if ksh is compiled with '-D_AST_no_spawnveg=1' flag. This commit
makes compilation of these functions conditional.

Related: #468
@siteshwar
Copy link
Contributor Author

It should be fixed now.

@krader1961
Copy link
Contributor

LGTM

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 this pull request may close these issues.

2 participants