 +
 +    if (0==$pid) { # CHILD
 +        $pipe->writer;
++
++        # scripts might exit(), and there is no way to prevent that without changing the script behavior
++        # so instead, let it exit, but first send the data back to the parent
++        # (note: this might now work with END {} blocks)
++        local $out = '';
++        local $headers = {};
++        local $err;
++        no warnings;
++        local *CORE::GLOBAL::exit = sub {
++            eval {
++                $pipe->print($JSON->encode([$out, $headers, $err]));
++                $pipe->close;
++                1;
++            } or warn $@;
++            CORE::exit($_[0]//0);
++        };
++        use warnings;
++
 +        eval {
-+            my ($out, $headers, $err);
-+            eval {
-+                ($out, $headers) =
-+                    $self->cgi_subprocess($env, $file);
-+                1;
-+            } or $err = "$@";
-+
-+            $pipe->print($JSON->encode([$out, $headers, $err]));
-+
-+            $pipe->close;
++            $self->cgi_subprocess($env, $file);
++            1;
++        } or do {
++            $err = "$@";
++            warn $@;
 +        };
-+        #warn "CHILD[$$] exit";
 +        exit;
 +    }
 +

+use Carp qw/cluck/;
+
+sub new {
+    my ($type, $id) = @_;
+    my $self = bless {
+        id => $id,
+        data => {},
+        rnd => rand(),

     my $dbh            = C4::Context->dbh;
diff --git a/Koha/Auth.pm b/Koha/Auth.pm
new file mode 100644
index 0000000..0eacafb
@@ -0,0 +1,259 @@
--- /dev/null
+++ b/Koha/Auth.pm
+use strict;
+use warnings;
+
