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 - ksh function (not posix) trap not receiving signals -HUP, -TERM but does receive -INT
Summary: ksh function (not posix) trap not receiving signals -HUP, -TERM but does rece...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: ksh
Version: 6.8
Hardware: All
OS: Linux
urgent
high
Target Milestone: rc
: ---
Assignee: Siteshwar Vashisht
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On: 1484937
Blocks: 1374441 1461138 1507484
TreeView+ depends on / blocked
 
Reported: 2017-05-23 13:33 UTC by Paulo Andrade
Modified: 2021-09-09 12:19 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1484937 1507484 (view as bug list)
Environment:
Last Closed: 2018-06-21 08:46:27 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
sample.sh (550 bytes, application/x-shellscript)
2017-05-23 13:33 UTC, Paulo Andrade
no flags Details
Enable signal bubbling in nested function calls (1.19 KB, patch)
2017-08-24 10:40 UTC, Siteshwar Vashisht
no flags Details | Diff
Enable signal bubbling in nested function calls (1.19 KB, patch)
2017-08-24 11:12 UTC, Siteshwar Vashisht
no flags Details | Diff
Enable signal bubbling in nested function calls (949 bytes, patch)
2017-08-24 15:09 UTC, Siteshwar Vashisht
kdudka: review+
Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 3494321 0 None None None 2018-06-21 12:27:52 UTC

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.


Note You need to log in before you can comment on or make changes to this bug.