From: charles.fisher@arconic.com
To: dash@vger.kernel.org
Subject: EXIT trap does not fire
Date: 31 May 2022 16:39:47 -0400 [thread overview]
Message-ID: <NOATDC-APPGTW91Teip00015ab2@NOATDC-APPGTW91.arconic.com> (raw)
I think that I have found a bug in dash that impacts EXIT trap handling. The behavior is different (and appears correct) in bash, ksh93 and mksh. I am using the EPEL dash package, version 0.5.10.2 for CentOS 7 (full package info included).
I didn't see this already reported on the mailing list; hopefully I am not reporting a duplicate bug, sorry if so.
The ssh-agent used in the context immediately below seems to prevent an EXIT trap from firing upon abnormal termination:
# cat dashbug_trivial
#!/bin/dash
eval $(ssh-agent)
trap 'eval $(ssh-agent -k)' EXIT
if ssh-add
then echo testing
read junk
fi
The EXIT does not fire if the user aborts (it fires properly if the user does not abort):
# ./dashbug_trivial
Agent pid 59714
Enter passphrase for /root/.ssh/id_ed25519:
Identity added: /root/.ssh/id_ed25519 (root@bastion.mycompany.com)
testing
^C
# ps ax | grep agent | grep -v grep
59714 ? Ss 0:00 ssh-agent
I am actually iterating over a set of hosts inside the conditional:
# cat dashbug
#!/bin/dash
eval $(ssh-agent)
trap 'eval $(ssh-agent -k)' EXIT
if ssh-add
then while read -r host port user <&9
do printf '=%s=%d=%s=\n' "$host" "$port" "$user"
ssh -p "$port" "$user@$host" "$@" 2>&1
done 9<<-''EndOfHosts
limsprd.amppcs.noa.alcoa.com 22 root
darkstar.dpw.alcoa.com 24 root
EndOfHosts
fi
The iterative script executes perfectly in dash; the problem is abnormal termination:
# ./dashbug uptime
Agent pid 10809
Enter passphrase for /root/.ssh/id_ed25519:
Identity added: /root/.ssh/id_ed25519 (root@bastion.mycompany.com)
=host1.mycompany.com=22=root=
13:12:52 up 233 days, 1:58, 0 users, load average: 0.66, 0.63, 0.54
=host2.mycompany.com=24=root=
13:12:52 up 2 days, 1:59, 0 users, load average: 0.00, 0.00, 0.00
Agent pid 10809 killed
Oddly, when I left off the trailing "fi" the trap killed the agent:
# ./dashbug uptime
Agent pid 9953
./dashbug: 15: ./dashbug: Syntax error: end of file unexpected (expecting "fi")
Agent pid 9953 killed
When I break the password prompt with a control-c, dash does not terminate the agent:
# ./dashbug uptime
Agent pid 10072
Enter passphrase for /root/.ssh/id_ed25519: ^C
#
I confirmed this with a check of the process list:
# ps ax | grep agent | grep -v grep
10072 ? Ss 0:00 ssh-agent
If I switch this to mksh (or other previously mentioned shells), a control-c does what I expect:
# head -1 dashbug
#!/bin/mksh
# ./dashbug uptime
Agent pid 10193
Enter passphrase for /root/.ssh/id_ed25519: ^C
Agent pid 10193 killed
#
Is this a problem with dash, or a lack in my understanding?
These are the full details on the CentOS 7 EPEL package for dash:
# rpm -qi dash
Name : dash
Version : 0.5.10.2
Release : 1.el7
Architecture: x86_64
Install Date: Wed 11 Aug 2021 01:45:26 PM CDT
Group : System Environment/Shells
Size : 159742
License : BSD and GPLv2+ and Public Domain and Copyright only
Signature : RSA/SHA256, Mon 05 Nov 2018 06:00:50 AM CST, Key ID 72f97b74ec551f03
Source RPM : dash-0.5.10.2-1.el7.src.rpm
Build Date : Mon 05 Nov 2018 06:00:48 AM CST
Build Host : x86-ol7-builder-01.us.oracle.com
Relocations : (not relocatable)
Vendor : Oracle America
URL : http://gondor.apana.org.au/~herbert/dash/
Summary : Small and fast POSIX-compliant shell
Description :
DASH is a POSIX-compliant implementation of /bin/sh that aims to be as small as
possible. It does this without sacrificing speed where possible. In fact, it is
significantly faster than bash (the GNU Bourne-Again SHell) for most tasks.
next reply other threads:[~2022-05-31 20:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 20:39 charles.fisher [this message]
2022-05-31 21:57 ` EXIT trap does not fire Paul Smith
2022-06-01 12:47 ` Steffen Nurpmeso
-- strict thread matches above, loose matches on Subject: below --
2022-11-12 11:02 Akbarkhon Variskhanov
2022-11-12 12:02 ` Harald van Dijk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=NOATDC-APPGTW91Teip00015ab2@NOATDC-APPGTW91.arconic.com \
--to=charles.fisher@arconic.com \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).