summaryrefslogtreecommitdiffstats
path: root/debian/vendor-h2o/share/h2o/kill-on-close
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 21:12:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 21:12:02 +0000
commit77e50caaf2ef81cd91075cf836fed0e75718ffb4 (patch)
tree53b7b411290b63192fc9e924a3b6b65cdf67e9d0 /debian/vendor-h2o/share/h2o/kill-on-close
parentAdding upstream version 1.8.3. (diff)
downloaddnsdist-77e50caaf2ef81cd91075cf836fed0e75718ffb4.tar.xz
dnsdist-77e50caaf2ef81cd91075cf836fed0e75718ffb4.zip
Adding debian version 1.8.3-2.debian/1.8.3-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/vendor-h2o/share/h2o/kill-on-close')
-rwxr-xr-xdebian/vendor-h2o/share/h2o/kill-on-close63
1 files changed, 63 insertions, 0 deletions
diff --git a/debian/vendor-h2o/share/h2o/kill-on-close b/debian/vendor-h2o/share/h2o/kill-on-close
new file mode 100755
index 0000000..4890abd
--- /dev/null
+++ b/debian/vendor-h2o/share/h2o/kill-on-close
@@ -0,0 +1,63 @@
+#! /bin/sh
+exec ${H2O_PERL:-perl} -x $0 "$@"
+#! perl
+
+use strict;
+use warnings;
+use Errno qw(EINTR);
+use POSIX qw(WNOHANG);
+
+my $rmpath;
+
+while (@ARGV) {
+ if ($ARGV[0] eq '--') {
+ shift @ARGV;
+ last;
+ } elsif ($ARGV[0] !~ /^--/) {
+ last;
+ } elsif ($ARGV[0] =~ /^--rm(?:=(.*)|)$/) {
+ shift @ARGV;
+ if (defined $1) {
+ $rmpath = $1;
+ } else {
+ die "option `--rm` requires an argument\n"
+ unless @ARGV;
+ $rmpath = shift @ARGV;
+ }
+ } else {
+ die "unknown argument: $ARGV[0]";
+ }
+}
+
+shift @ARGV
+ if @ARGV && $ARGV[0] eq '--';
+
+die "Usage: $0 [--rm=path] -- cmd args...\n"
+ unless @ARGV;
+
+open my $wait_fh, '<&', 5
+ or die "failed to open wait file descriptor (fd=5):$!";
+
+my $pid = fork;
+die "fork failed:$!"
+ if $pid == -1;
+if ($pid == 0) {
+ exec @ARGV;
+ die "failed to exec $ARGV[0]:$!";
+}
+
+$SIG{INT} = sub {};
+
+while (1) {
+ my $r = sysread $wait_fh, my $buf, 1;
+ last if !defined($r) || $r == 0 || ($r == -1 && $! != EINTR);
+}
+
+kill 'TERM', $pid;
+while (waitpid($pid, 0) != $pid) {
+}
+
+if (defined $rmpath) {
+ exec '/bin/rm', '-rf', $rmpath;
+ die "failed to exec /bin/rm:$!";
+}