Repository navigation
Aliasing "exec" and "builtin" causes various problems. Can you turn it off by default? - #235
akinomyoga wants to merge 1 commit into
Conversation
|
Thanks for sending the PR. I agree that redefining If In zsh I solve this problem by applying |
Option 1. Detect
|
Good idea! This will still cause a leak in case of |
|
Oh, I was actually thinking of another approach. I think currently the cleanest way is to use Option 4 below. (Edit: I think it is better to combine it with the above-mentioned startup check for Option 3. Set FD_CLOEXEC using
|
Huh! I've actually implemented this within gitstatusd at some point. It was using syscall injection via ptrace to invoke I really don't want a dependency on gdb of a C compiler. |
Implemented here: 815301f |
Oh, OK. Yeah, I understand that's too hacky.
Actually, I just thought about it as one option in case there is really no other way to solve the issue. In that case, maybe we could combine different ways and choose one available in that system if any. But now, it's fine to forget about this approach because it seems like you have found a satisfactory way for you.
OK. Thank you for your quick work! If it works fine within your environment, it is fine for me to close the PR now. Thank you very much! |
Thanks for filing the PR and suggesting viable fixes.
Yeah, feel free to close the PR. It works fine in my tests. I don't use bash myself, so there might be corner cases that I've missed. I'll wait for a week or two for possible fallout from bash users who follow master. If no bugs get reported I'll cut a new release. |
|
OK. I'll close the issue. Thank you again! |
|
FYI: This change has been released in v1.5.0. |
I initially received a related issue at akinomyoga/ble.sh#93. This finally turned out to be related to the following settings in
gitstatus.plugin.sh:These cause every kind of problem. In particular, the builtin
builtinis intended to protect the scripts from such modified builtin behavior so isn't expected to be replaced by an alias or a function.exec 3> file, don't work anymore because it is replaced by_gitstatus_exec_wrapper 3> fileand the realexecis executed inside_gitstatus_exec_wrapper. In this case, the redirection3> filewill not be treated by the special rule forexec, so the effect of the redirection is not persistent after the execution of the command.builtin unset -v varbecomes to remove the local variables instead of changing the variable states tounset. In Bash, the behavior ofunsetchanges depending on the way howunsetcould find the variable: Whenunsetfinds the variable in local scope,unsetsets the variable state tounset. Whenunsetfinds the variable by dynamic scoping,unsetremoves the variable placeholder in the function call chain. As a result, the upper level of the variable placeholder becomes visible. If one replacesbuiltinwith a shell function, the variables become always found through the dynamic scoping, so the behavior becomes different.builtin eval 'echo $1'will change. The positional parameters$1,$2, ... in eval arguments are supposed to reference the values in the context ofbuiltin eval 'echo $1'. However, if one replacesbuiltinwith a function, these parameters start to reference the arguments specified to_gitstatus_builtin_wrapper.sourcei.e.,builtin source file.shis also affected. Inside the sourced filefile.sh, the parameters$1, etc. of the caller context should be able to be referenced. Ifbuiltinis replaced, the parameters$1, etc. are changed to the arguments specified to the wrapper function.builtin printf -v 'a[$1]',builtin unset -v 'a[$1]',builtin test -v 'a[$1]',v='x=a[$1]'; builtin let v,declare 'a=([$1]=1)',read 'a[$1]', etc.As real problems:
ble.shwas completely broken by the replacedbuiltin[gitstatus]stty: invalid argumentonsource ble.sh, patch 0.3.3 akinomyoga/ble.sh#93 (Now I have added a workaround to protectble.shfrom aliasedbuiltin, so now it doesn't break)gitstatus.plugin.sh:sudo docker execfails.To borrow @romkatv's words, "It's generally not a good idea to redefine builtins." In particular, redefining the
builtinbuiltin is the most one that we want to avoid. Isn't there any other way to detectexec other_program?kill -0 $$. In this way, one cannot detect if the parent process is replaced by another program usingexec, but better than doing nothing.procfs, we could check/proc/$$/cmdlineto see if the process is replaced or not.Anyway, I believe we should by default turn off
GITSTATUS_STOP_ON_EXEC.