Skip to content

Commit

Permalink
alarm: don't save sh.ifstable (re: 18b3f4a)
Browse files Browse the repository at this point in the history
It is not correct to save sh.ifstable (a.k.a. shp->ifstable) before
calling a function and then restore it after; this can cause field
splitting to malfunction. See 70368c5.

The change to init.c in the Red Hat patch applied in 18b3f4a
(shp->ifstable[0] = S_EOF) appears to be sufficient.

src/cmd/ksh93/bltins/alarm.c:
- Revert save/restore of sh.ifstable.

src/cmd/ksh93/tests/builtins.sh:
- Tweak the regression test to work correctly on a slower machine,
  i.e. a Raspberry Pi running FreeBSD 12.2 arm64 (thanks to hyenias
  for providing testing access).
  • Loading branch information
McDutchie committed Jan 26, 2021
1 parent e72543a commit f033bb0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
7 changes: 0 additions & 7 deletions src/cmd/ksh93/bltins/alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
* > happen is that the trap is marked for execution (sh_trapnote) and run after
* > the current command completes. The time trap should wake up the shell if
* > it is blocked and it should return and then handle the trap.
*
* When that is done, the save_ifstable workaround can probably be removed.
*/

#include "defs.h"
Expand Down Expand Up @@ -153,12 +151,7 @@ void sh_timetraps(Shell_t *shp)
{
tp->flags &= ~L_FLAG;
if(tp->action)
{
char save_ifstable[256];
memcpy(save_ifstable,shp->ifstable,sizeof(save_ifstable));
sh_fun(tp->action,tp->node,(char**)0);
memcpy(shp->ifstable,save_ifstable,sizeof(save_ifstable));
}
tp->flags &= ~L_FLAG;
if(!tp->flags)
{
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/tests/builtins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,11 @@ done 3< <(builtin)
if (builtin alarm) 2>/dev/null
then got=$( { "$SHELL" -c '
builtin alarm
alarm -r alarm_handler +.001
alarm -r alarm_handler +.005
i=0
function alarm_handler.alarm
{
let "(++i) > 100" && exit
let "(++i) > 20" && exit
}
while :; do
echo cargo,odds and ends,jetsam,junk,wreckage,castoffs,sea-drift
Expand Down

0 comments on commit f033bb0

Please sign in to comment.