Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

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: kshAssignee: Siteshwar Vashisht <svashisht>
Status: CLOSED CURRENTRELEASE QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: high Docs Contact:
Priority: urgent    
Version: 6.8CC: cww, fkrska, jkejda, kdudka, mhernon, pandrade, qe-baseos-apps, svashisht, toneata
Target Milestone: rcKeywords: 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:
Description Flags
sample.sh
none
Enable signal bubbling in nested function calls
none
Enable signal bubbling in nested function calls
none
Enable signal bubbling in nested function calls kdudka: review+

Description Paulo Andrade 2017-05-23 13:33:25 UTC
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).

Comment 9 Siteshwar Vashisht 2017-08-24 10:40:14 UTC
Created attachment 1317590 [details]
Enable signal bubbling in nested function calls

Comment 10 Siteshwar Vashisht 2017-08-24 11:11:34 UTC
The patch from comment 9 is crashing when "_AST_KSH_SIGNAL_BUBBLE" is set due to a bug. I will modify it.

Comment 11 Siteshwar Vashisht 2017-08-24 11:12:19 UTC
Created attachment 1317641 [details]
Enable signal bubbling in nested function calls

Comment 12 Paulo Andrade 2017-08-24 13:46:08 UTC
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.

Comment 14 Kamil Dudka 2017-08-24 14:26:43 UTC
(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!

Comment 16 Siteshwar Vashisht 2017-08-24 15:09:29 UTC
Created attachment 1317752 [details]
Enable signal bubbling in nested function calls

Comment 19 Kamil Dudka 2017-08-25 11:21:41 UTC
Comment on attachment 1317752 [details]
Enable signal bubbling in nested function calls

Looks good.