-
Notifications
You must be signed in to change notification settings - Fork 126
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
Trying to use exec to replace a not-interactive process with an interactive one doesn't work inside su #461
Comments
It's a regression caused by 074ebfc. If you need this to work the previous prerelease (PRE-5462) is still available. |
It was noted this command didn't work properly: su -t -c 'exec sh -s -c "echo 123"' The child shell performed the 'echo' but then exited, despite the '-s' flag. This is a regression introduced by commit 074ebfc (ash: code shrink). This simpler command also failed the same way: sh -c "exec sh -s" This regression dates back even further, to commit da7c8cd (ash: run ash_main() directly from a FS_SHELLEXEC shell). The issue can be avoided if shells invoked by the 'exec' builtin aren't run by calling ash_main() directly. Adds 80-96 bytes. GitHub issue #461.
The similar command Try the latest prerelease (PRE-5487 or above). |
Thanks but unfortunately it doesn't fix all cases. This is the behavior of the old PRE-5462 version: CASE 1 CASE 2 CASE 3 CASE 4 On the latest version the case 3 broke but strangely the case 4 is working. |
I noticed another issue, this: |
- Change the 'flags' argument to shellexec()/tryexec() so it only indicates that it's permissible to run ash_main() directly. The flag is only set TRUE in forkshell_shellexec(). - The check for a script with an interpreter which is an applet is now performed for all calls to tryexec(), not just those that originate from evalcommand(). Saves 64-80 bytes. GitHub issue #461.
In case 2, Case 4 works because the shell being forced to run in a separate process when the The other issues might be fixed in the latest prerelease (PRE-5488 or above). I'm sure you'll let me know if they aren't. |
Thanks, now the interactive/non-interactive mode works fine in all cases. Now I tried to check exec. First I open busybox ash (total busybox processes: 1) then:
|
Windows doesn't have an |
It is good to reuse processes but what I was asking is different. |
That wouldn't work. The parent of the old process is waiting for it to exit (assuming it's running in foreground):
On Unix if the old process
On Windows the
If the old process were to close itself the parent would get its exit status, not that of the |
If the |
Process 2 doesn't know whether or not its parent is waiting for it. Yes, we could pass that information to it. And yes, we could have process 2 close itself if it then But I doubt it's worth the effort of implementing this - just to allow one process to be closed early in what seems to be a very, very, very rare situation. |
If I'm not wrong we already know it, when
|
Yes, that seems to work, and at a very modest cost. I'll need to think about it some more, though... |
What other cases did you have in mind? |
I haven't thought too much about other cases but I can think of one example. For example if a script (near its the end) execute code in background (with &), then the script end and since the command in background no longer have a parent it can be safely replaced when needed. |
If a process performing an exec is an orphan there's no reason for it to wait for its child's exit code. Let it exit immediately. Adds 16 bytes. (GitHub issue #461)
I'm still a bit uneasy about this. But, for what it's worth, the latest prerelease (PRE-5511 or above) allows certain intermediate processes to exit early. Be careful out there! |
I tried in various ways in a new window created with |
I also tried this:
An it seems to behave properly even when the main process is terminated. |
Trying to use exec to replace a not-interactive process with an interactive one doesn't work inside su.
Example:
busybox su -c 'exec sh -s -c "echo 123"'
It should remain open but it didn't (even after adding -N).
The text was updated successfully, but these errors were encountered: