* exec'ing $0 in traps
@ 2017-02-17 8:16 Andre Albsmeier
2017-02-17 20:02 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Andre Albsmeier @ 2017-02-17 8:16 UTC (permalink / raw)
To: zsh-users; +Cc: Andre.Albsmeier
When sending SIGHUP to this script:
#!/bin/zsh
echo started
trap 'echo trapped; exec "$0"' 1
echo $$ > /tmp/blafasel
while read line; do
echo line $line
done
restarting works exactly one time and then no more. With
FreeBSD's native /bin/sh or even the lousy /bin/bash it
works as expected.
What am I doing wrong?
-Andre
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: exec'ing $0 in traps
2017-02-17 8:16 exec'ing $0 in traps Andre Albsmeier
@ 2017-02-17 20:02 ` Bart Schaefer
2017-02-18 10:24 ` Andre Albsmeier
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2017-02-17 20:02 UTC (permalink / raw)
To: Andre Albsmeier, zsh-users
On Feb 17, 9:16am, Andre Albsmeier wrote:
}
} #!/bin/zsh
}
} echo started
} trap 'echo trapped; exec "$0"' 1
}
} echo $$ > /tmp/blafasel
}
} while read line; do
} echo line $line
} done
Some combination of the "read" builtin plus calling "exec" from inside
the signal handler is causing the HUP signal to remain blocked across
the "exec" -- and re-installing the trap doesn't unblock it.
If I replace the read-loop with
sleep 3
kill -1 $$
then the process restarts itself every 3 seconds as expected.
So, you aren't doing anything explicitly wrong.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: exec'ing $0 in traps
2017-02-17 20:02 ` Bart Schaefer
@ 2017-02-18 10:24 ` Andre Albsmeier
0 siblings, 0 replies; 3+ messages in thread
From: Andre Albsmeier @ 2017-02-18 10:24 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Andre Albsmeier, zsh-users
On Fri, 17-Feb-2017 at 12:02:19 -0800, Bart Schaefer wrote:
> On Feb 17, 9:16am, Andre Albsmeier wrote:
> }
> } #!/bin/zsh
> }
> } echo started
> } trap 'echo trapped; exec "$0"' 1
> }
> } echo $$ > /tmp/blafasel
> }
> } while read line; do
> } echo line $line
> } done
>
> Some combination of the "read" builtin plus calling "exec" from inside
> the signal handler is causing the HUP signal to remain blocked across
> the "exec" -- and re-installing the trap doesn't unblock it.
Too bad. Maybe this gets fixed one day. Meanwhile I use this:
#!/bin/zsh
restart=""
echo started
trap 'restart=1' 1
echo $$ > /tmp/blafasel
while :; do
[ $restart ] && exec $0
read line || exit 0
echo line $line
done
and it seems to do what I need...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-18 10:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-17 8:16 exec'ing $0 in traps Andre Albsmeier
2017-02-17 20:02 ` Bart Schaefer
2017-02-18 10:24 ` Andre Albsmeier
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).