Bug 1454804
Summary: | ksh function (not posix) trap not receiving signals -HUP, -TERM but does receive -INT | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | Red Hat Enterprise Linux 6 | Reporter: | Paulo Andrade <pandrade> | ||||||||||
Component: | ksh | Assignee: | Siteshwar Vashisht <svashisht> | ||||||||||
Status: | CLOSED CURRENTRELEASE | QA Contact: | BaseOS QE - Apps <qe-baseos-apps> | ||||||||||
Severity: | high | Docs Contact: | |||||||||||
Priority: | urgent | ||||||||||||
Version: | 6.8 | CC: | cww, fkrska, jkejda, kdudka, mhernon, pandrade, qe-baseos-apps, svashisht, toneata | ||||||||||
Target Milestone: | rc | Keywords: | EasyFix, Patch, Regression, Reopened, ZStream | ||||||||||
Target Release: | --- | ||||||||||||
Hardware: | All | ||||||||||||
OS: | Linux | ||||||||||||
Whiteboard: | |||||||||||||
Fixed In Version: | Doc Type: | If docs needed, set a value | |||||||||||
Doc Text: | Story Points: | --- | |||||||||||
Clone Of: | |||||||||||||
: | 1484937 1507484 (view as bug list) | Environment: | |||||||||||
Last Closed: | 2018-06-21 08:46:27 UTC | Type: | Bug | ||||||||||
Regression: | --- | Mount Type: | --- | ||||||||||
Documentation: | --- | CRM: | |||||||||||
Verified Versions: | Category: | --- | |||||||||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||||||||
Cloudforms Team: | --- | Target Upstream Version: | |||||||||||
Embargoed: | |||||||||||||
Bug Depends On: | 1484937 | ||||||||||||
Bug Blocks: | 1374441, 1461138, 1507484 | ||||||||||||
Attachments: |
|
Created attachment 1317590 [details]
Enable signal bubbling in nested function calls
The patch from comment 9 is crashing when "_AST_KSH_SIGNAL_BUBBLE" is set due to a bug. I will modify it. Created attachment 1317641 [details]
Enable signal bubbling in nested function calls
Comment on attachment 1317641 [details]
Enable signal bubbling in nested function calls
I believe it would be better to just check if
_AST_KSH_SIGNAL_BUBBLE is set, for example, instead of:
+ if(r>SH_EXITSIG && ((r&SH_EXITMASK)==SIGINT || ((r&SH_EXITMASK)==SIGQUIT) || ((tmp=getenv("_AST_KSH_SIGNAL_BUBBLE")) && (*tmp!=0))))
have:
+ if(r>SH_EXITSIG && ((r&SH_EXITMASK)==SIGINT || ((r&SH_EXITMASK)==SIGQUIT) || (tmp=getenv("_AST_KSH_SIGNAL_BUBBLE"))))
otherwise, if it requires a value, to be correct it should also parse the
value, e.g. it would enable if one writes:
_AST_KSH_SIGNAL_BUBBLE=0
_AST_KSH_SIGNAL_BUBBLE=off
_AST_KSH_SIGNAL_BUBBLE=false
so, better to just require it to be set, like POSIXLY_CORRECT, that is off by default, and
enabled if the environment variable is set, regardless of value, if any.
(In reply to Paulo Andrade from comment #12) > + if(r>SH_EXITSIG && ((r&SH_EXITMASK)==SIGINT || ((r&SH_EXITMASK)==SIGQUIT) > || (tmp=getenv("_AST_KSH_SIGNAL_BUBBLE")))) That is exactly what Siteshwar has originally implemented. While reviewing the patch, I asked him to change it such that empty and unset variables are treated equally to avoid confusion :) I understand that you see it exactly oppositely. Given the fact that both of you prefer ignoring the value, I am stepping back on this. Sorry for the extra iteration! Created attachment 1317752 [details]
Enable signal bubbling in nested function calls
Comment on attachment 1317752 [details]
Enable signal bubbling in nested function calls
Looks good.
|
Created attachment 1281557 [details] sample.sh In previous ksh versions, when exiting the scope of a ksh (not posix) function, it would restore the trap table of the "calling context" and if the reason the function exited was a signal, it would call sh_fault() passing as argument the signal value. Newer ksh checks it, but calls kill(getpid(), signal_number) after restoring the trap table, but only calls for SIGINT and SIGQUIT. A quick & dirty way to revert to pre ksh-20120801 behaviour is: ---8<--- diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.orig ksh-20120801/src/cmd/ksh93/sh/xec.c --- ksh-20120801/src/cmd/ksh93/sh/xec.c.orig 2017-05-23 10:17:39.026021743 -0300 +++ ksh-20120801/src/cmd/ksh93/sh/xec.c 2017-05-23 10:17:40.876961791 -0300 @@ -3529,7 +3529,7 @@ int sh_funscope(int argn, char *argv[],i } if(jmpval) r=shp->exitval; - if(r>SH_EXITSIG && ((r&SH_EXITMASK)==SIGINT || ((r&SH_EXITMASK)==SIGQUIT))) + if(r>SH_EXITSIG) kill(getpid(),r&SH_EXITMASK); if(jmpval > SH_JMPFUN) { ---8<--- The old way appears to have been more appropriate, but there must be a reason to only pass SIGINT and SIGQUIT as it is an explicit patch. The test case terminates only on SIGINT, and other trapped signals are ignored, even tough the default action of some of them is to quit a script, e.g. HUP, SEGV, and TERM (ABRT kills the sample script).