Branch: refs/heads/blead Home: https://github.com/Perl/perl5 Commit: 37f34a4f18f0b069e5274462e3cd5d5c19a78086 https://github.com/Perl/perl5/commit/37f34a4f18f0b069e5274462e3cd5d5c19a78086 Author: Štěpán Němec <step...@smrk.net> Date: 2024-08-01 (Thu, 01 Aug 2024)
Changed paths: M pod/perlipc.pod Log Message: ----------- perlipc.pod: fix the "exec from signal handler" example This is a partial revert of de7ba5179657 ("Doc patch to perlipc", 2011-09-11). I tested both the pre-de7ba5179657 and current version of the example program (section "Handling the SIGHUP Signal in Daemons") on Arch Linux (perl v5.38.2 built for x86_64-linux-thread-multi) and OpenBSD -current (perl v5.36.3 built for amd64-openbsd). On both systems, the handler is called only once with the current (broken) version of the example program. With the pre-de7ba5179657 version the handler is called on every delivery of the signal, as expected. POSIX shell test script (perlipc-sighandler.sh): ================================================ -->8-- #!/bin/sh check() { printf '\nTesting %s\n' "$*" "$@" & sleep 1 kill -HUP $! sleep 1 kill -HUP $! sleep 1 kill $! } bad=./perlipc-sighandler-bad.perl good=./perlipc-sighandler-good.perl # from current perlipc.pod (perl5 commit e78caca8144e v5.39.9-35-ge78caca8144e) cat <<\EOF >"$bad" #!/usr/bin/perl use v5.36; use POSIX (); use FindBin (); use File::Basename (); use File::Spec::Functions qw(catfile); $| = 1; # make the daemon cross-platform, so exec always calls the script # itself with the right path, no matter how the script was invoked. my $script = File::Basename::basename($0); my $SELF = catfile( $FindBin::Bin, $script ); # POSIX unmasks the sigprocmask properly $SIG{HUP} = sub { print "got SIGHUP\n"; exec( $SELF, @ARGV ) || die "$0: couldn't restart: $!"; }; code(); sub code { print "PID: $$\n"; print "ARGV: @ARGV\n"; my $count = 0; while (1) { sleep 2; print ++$count, "\n"; } } EOF # from perlipc.pod before perl5 commit de7ba5179657 v5.15.2-343-gde7ba5179657 cat <<\EOF >"$good" #!/usr/bin/perl use v5.36; use POSIX (); use FindBin (); use File::Basename (); use File::Spec::Functions qw(catfile); $| = 1; # make the daemon cross-platform, so exec always calls the script # itself with the right path, no matter how the script was invoked. my $script = File::Basename::basename($0); my $SELF = catfile( $FindBin::Bin, $script ); # POSIX unmasks the sigprocmask properly my $sigset = POSIX::SigSet->new(); my $action = POSIX::SigAction->new("sigHUP_handler", $sigset, &POSIX::SA_NODEFER); POSIX::sigaction(&POSIX::SIGHUP, $action); sub sigHUP_handler { print "got SIGHUP\n"; exec( $SELF, @ARGV ) || die "$0: couldn't restart: $!"; } code(); sub code { print "PID: $$\n"; print "ARGV: @ARGV\n"; my $count = 0; while (1) { sleep 2; print ++$count, "\n"; } } EOF chmod +x "$bad" "$good" check "$bad" check "$good" -->8-- Example observed output: ======================== ; ./perlipc-sighandler.sh Testing ./perlipc-sighandler-bad.perl PID: 19120 ARGV: got SIGHUP PID: 19120 ARGV: Testing ./perlipc-sighandler-good.perl PID: 19980 ARGV: got SIGHUP PID: 19980 ARGV: got SIGHUP PID: 19980 ARGV: Cc: Leon Timmermans <faw...@gmail.com> Fixes: de7ba5179657 ("Doc patch to perlipc") Commit: 37d9b9c0bb48b00900b977532e86fdd99e577df0 https://github.com/Perl/perl5/commit/37d9b9c0bb48b00900b977532e86fdd99e577df0 Author: Štěpán Němec <step...@smrk.net> Date: 2024-08-01 (Thu, 01 Aug 2024) Changed paths: M pod/perlipc.pod Log Message: ----------- perlipc.pod: improve "exec from signal handler" signal mask comment "POSIX unmasks the sigprocmask properly" seems rather opaque. Instead, explain the SA_NODEFER motivation directly. Commit: 6cc5fbb9234d1f71fc32008ff15b82b4c7e80822 https://github.com/Perl/perl5/commit/6cc5fbb9234d1f71fc32008ff15b82b4c7e80822 Author: Štěpán Němec <step...@smrk.net> Date: 2024-08-01 (Thu, 01 Aug 2024) Changed paths: M AUTHORS Log Message: ----------- Update AUTHORS (add stepnem) Commit: 9b9c0391a41918597cf73b1318bbec469b46aaa5 https://github.com/Perl/perl5/commit/9b9c0391a41918597cf73b1318bbec469b46aaa5 Author: Štěpán Němec <step...@smrk.net> Date: 2024-08-01 (Thu, 01 Aug 2024) Changed paths: M pod/perlipc.pod Log Message: ----------- perlipc.pod: avoid race in "exec from signal handler" example Instead of using SA_NODEFER, which makes the handler function itself interruptible by another SIGHUP, use a plain $SIG{HUP} handler and unblock SIGHUP using sigprocmask from the main program. Compare: https://github.com/Perl/perl5/compare/9cca022465b6...9b9c0391a419 To unsubscribe from these emails, change your notification settings at https://github.com/Perl/perl5/settings/notifications