pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

wip/p5-FCGI-Daemon: Update to FCGI-Daemon 0.20220206



Module Name:	pkgsrc-wip
Committed By:	Adrian Steinmann <ast%NetBSD.org@localhost>
Pushed By:	ast
Date:		Thu Jul 28 16:58:40 2022 +0000
Changeset:	5ded0650feeb64055b7a612d5cd42ea9d2729f89

Modified Files:
	p5-FCGI-Daemon/Makefile
	p5-FCGI-Daemon/PLIST
	p5-FCGI-Daemon/distinfo
Added Files:
	p5-FCGI-Daemon/patches/patch-lib-FCGI-Daemon.pm
Removed Files:
	p5-FCGI-Daemon/patches/patch-bsd1
	p5-FCGI-Daemon/patches/patch-bsd2
	p5-FCGI-Daemon/patches/patch-bsd3
	p5-FCGI-Daemon/patches/patch-bsd4
	p5-FCGI-Daemon/patches/patch-bsd5
	p5-FCGI-Daemon/patches/patch-bsd6
	p5-FCGI-Daemon/patches/patch-bsd7

Log Message:
wip/p5-FCGI-Daemon: Update to FCGI-Daemon 0.20220206

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=5ded0650feeb64055b7a612d5cd42ea9d2729f89

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 p5-FCGI-Daemon/Makefile                         |   6 +-
 p5-FCGI-Daemon/PLIST                            |   6 +-
 p5-FCGI-Daemon/distinfo                         |  14 +-
 p5-FCGI-Daemon/patches/patch-bsd1               |  23 ---
 p5-FCGI-Daemon/patches/patch-bsd2               |  15 --
 p5-FCGI-Daemon/patches/patch-bsd3               |  37 ----
 p5-FCGI-Daemon/patches/patch-bsd4               |  54 -----
 p5-FCGI-Daemon/patches/patch-bsd5               |  57 ------
 p5-FCGI-Daemon/patches/patch-bsd6               |  28 ---
 p5-FCGI-Daemon/patches/patch-bsd7               |  40 ----
 p5-FCGI-Daemon/patches/patch-lib-FCGI-Daemon.pm | 259 ++++++++++++++++++++++++
 11 files changed, 269 insertions(+), 270 deletions(-)

diffs:
diff --git a/p5-FCGI-Daemon/Makefile b/p5-FCGI-Daemon/Makefile
index ec2bed8893..48d5ba9ece 100644
--- a/p5-FCGI-Daemon/Makefile
+++ b/p5-FCGI-Daemon/Makefile
@@ -1,7 +1,7 @@
 # $NetBSD$
 
 PKGBASE=	FCGI-Daemon
-DISTNAME=	${PKGBASE}-0.20151226
+DISTNAME=	${PKGBASE}-0.20220206
 PKGNAME=	p5-${DISTNAME}
 PKGREVISION=	1
 CATEGORIES=	www perl5
@@ -14,9 +14,9 @@ LICENSE=	gnu-agpl-v3
 
 USE_TOOLS+=	perl:run
 
-DEPENDS+=	p5-FCGI>=0.71:../../www/p5-FCGI
+DEPENDS+=	p5-FCGI>=0.82:../../www/p5-FCGI
 DEPENDS+=	p5-BSD-Resource>=1.29:../../devel/p5-BSD-Resource
-DEPENDS+=	p5-FCGI-ProcManager>=0.18:../../www/p5-FCGI-ProcManager
+DEPENDS+=	p5-FCGI-ProcManager>=0.28:../../www/p5-FCGI-ProcManager
 
 FCGID_EG_DIR=	share/examples/fcgi-daemon
 FCGID_NGINX=	nginx/common.conf nginx/ikiwiki.conf nginx/sample.conf
diff --git a/p5-FCGI-Daemon/PLIST b/p5-FCGI-Daemon/PLIST
index 4d05ea1e8c..b55593abb6 100644
--- a/p5-FCGI-Daemon/PLIST
+++ b/p5-FCGI-Daemon/PLIST
@@ -1,7 +1,7 @@
 @comment $NetBSD$
-share/examples/rc.d/fcgi_daemon
+${PERL5_SUB_INSTALLVENDORLIB}/FCGI/Daemon.pm
+lib/perl5/vendor_perl/man/man3/FCGI::Daemon.3
 share/examples/fcgi-daemon/nginx/common.conf
 share/examples/fcgi-daemon/nginx/ikiwiki.conf
 share/examples/fcgi-daemon/nginx/sample.conf
-${PERL5_SUB_INSTALLVENDORLIB}/FCGI/Daemon.pm
-lib/perl5/vendor_perl/man/man3/FCGI::Daemon.3
+share/examples/rc.d/fcgi_daemon
diff --git a/p5-FCGI-Daemon/distinfo b/p5-FCGI-Daemon/distinfo
index 02db8e040d..53f700de86 100644
--- a/p5-FCGI-Daemon/distinfo
+++ b/p5-FCGI-Daemon/distinfo
@@ -1,12 +1,6 @@
 $NetBSD$
 
-RMD160 (FCGI-Daemon-0.20151226.tar.gz) = 8f56061adb572e43d3c7cde9c7416a9920a4c16f
-SHA512 (FCGI-Daemon-0.20151226.tar.gz) = 67e0e92a8a01400c70a219f9df7c30a1f67c0ee0ea9506f0dbf388473a9931d64f2a5d7f4b34329241ae5c5bd1caf55dfce4f1dd1b5f4d6f6c7ee4615612dd14
-Size (FCGI-Daemon-0.20151226.tar.gz) = 23375 bytes
-SHA1 (patch-bsd1) = bd6eef790759a1eb2df143f888820b47fbce4d3c
-SHA1 (patch-bsd2) = adedc89ffc5cfc2289ebad569e495273d80df3cf
-SHA1 (patch-bsd3) = 0a59d856c66b0f8dc829c858fd4caf58660ff281
-SHA1 (patch-bsd4) = 31491220625b8691962dd354d588a081dcf52229
-SHA1 (patch-bsd5) = c504b293a68cb07429914a0d6b00fe7c72cab8e0
-SHA1 (patch-bsd6) = b09927b4637f0fc9bc8bd2eed0e606cc2ca7cfa5
-SHA1 (patch-bsd7) = ed612ef7fdd161cc6c175441ee5dbc5766b93e1f
+BLAKE2s (FCGI-Daemon-0.20220206.tar.gz) = ca58656d54596755b961fd4f0430c49c8a31b658341fb7471092125f0ec6dd7d
+SHA512 (FCGI-Daemon-0.20220206.tar.gz) = 827d3940f18c66c9cc155aa3045fb24e6afecef6ce9b03d3a8344e339749216db63ab39910ec826c2b7a992b4d21c3fede634355fffc3241892737743eb1b1dc
+Size (FCGI-Daemon-0.20220206.tar.gz) = 25156 bytes
+SHA1 (patch-lib-FCGI-Daemon.pm) = 3e9a640c06ead3dd46c34ab8b14e03362512951d
diff --git a/p5-FCGI-Daemon/patches/patch-bsd1 b/p5-FCGI-Daemon/patches/patch-bsd1
deleted file mode 100644
index 16ab651456..0000000000
--- a/p5-FCGI-Daemon/patches/patch-bsd1
+++ /dev/null
@@ -1,23 +0,0 @@
-$NetBSD$
-
-Use POSIX calls setgid and setuid to non-root user when running as
-"root" daemon; add debug flag.
-
---- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
-+++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
-@@ -7,12 +7,15 @@
- our $VERSION = '0.20151226';
- use 5.14.2;
- use English '-no_match_vars';
-+use POSIX;
- use BSD::Resource;                      # on Debian available as libbsd-resource-perl
- use FCGI 0.71;                          # on Debian available as libfcgi-perl
- use FCGI::ProcManager 0.18;             # on Debian available as libfcgi-procmanager-perl
- use Getopt::Std;
- use autouse 'Pod::Usage'=>qw(pod2usage);
- 
-+my $DEBUG = 0;
-+
- =head1 NAME
- 
- FCGI::Daemon - Perl-aware Fast CGI daemon for use with nginx web server.
diff --git a/p5-FCGI-Daemon/patches/patch-bsd2 b/p5-FCGI-Daemon/patches/patch-bsd2
deleted file mode 100644
index 7392306475..0000000000
--- a/p5-FCGI-Daemon/patches/patch-bsd2
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD$
-
-Attempt to unlink each file one by one.
-
---- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
-+++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
-@@ -39,7 +42,7 @@
- sub dieif {
-     if($ARG[0]){
-         my $err=$ARG[1];
--        unlink @o{'pidfile','sockfile'};
-+        unlink $o{$_} for qw(pidfile sockfile);
-         print "Error - $err:\n",$ARG[0],"\n";
-         exit 1;
-     }
diff --git a/p5-FCGI-Daemon/patches/patch-bsd3 b/p5-FCGI-Daemon/patches/patch-bsd3
deleted file mode 100644
index 2bc0f001fc..0000000000
--- a/p5-FCGI-Daemon/patches/patch-bsd3
+++ /dev/null
@@ -1,37 +0,0 @@
-$NetBSD$
-
-Use only $EFFECTIVE_USER_ID to discrimiate if we need to set[gu]id
-and don't install signal handlers INT and TERM as FCGI::ProcManager
-does that.
-
---- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
-+++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
-@@ -62,26 +65,18 @@
-     $o{file_pattern}=$o{'f'}||qr{\.pl};
-     $o{leak_threshold}=$o{'l'}||1.3;
- 
--    if($REAL_USER_ID==$EFFECTIVE_USER_ID and $EFFECTIVE_USER_ID==0){        # if run as root
-+    if($EFFECTIVE_USER_ID==0){
-         $o{gid}=$o{g}||'www-data'; $o{gid_num}=scalar getgrnam($o{gid});
-         $o{uid}=$o{u}||'www-data'; $o{uid_num}=scalar getpwnam($o{uid});
-     }
- 
--    local $SIG{INT}= local $SIG{TERM}= sub{
--        # actually FCGI::ProcManager override our TERM handler so .sock and .pid files will be removed only by sysv script... :(
--        $o{fcgi_pm}->pm_remove_pid_file() if $o{fcgi_pm};
--        unlink @o{'sockfile','pidfile'};
--        $o{fcgi_pm}->pm_die() if $o{fcgi_pm};   #pm_die() does not return
--        exit 0;
--    };
--
-     # daemonize
-     if($o{'d'}){
-         chdir '/';                              # this is good practice for unmounting
-         local $PROGRAM_NAME='FCGI::Daemon';
-         defined(my $pid=fork) or die "Can't fork: $!";
-         exit if $pid;
--        eval {use POSIX qw(setsid); POSIX::setsid();} or die q{Can't start a new session: }.$OS_ERROR;
-+        POSIX::setsid() or die q{Can't start a new session: }.$OS_ERROR;
-         open *STDIN,'<','/dev/null';
-         open *STDOUT,'>>','/dev/null';
-         open *STDERR,'>>','/dev/null';
diff --git a/p5-FCGI-Daemon/patches/patch-bsd4 b/p5-FCGI-Daemon/patches/patch-bsd4
deleted file mode 100644
index 1a5f00bb30..0000000000
--- a/p5-FCGI-Daemon/patches/patch-bsd4
+++ /dev/null
@@ -1,54 +0,0 @@
-$NetBSD$
-
-Add debug flag and prepare to remove files in pm_die() routine
-
---- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
-+++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
-@@ -94,24 +89,38 @@
-                                         pid_fname=>$o{pidfile}
-                                       });
-     print "Opening socket $o{sockfile}\n";
-+    $o{socket_fh} = FCGI::OpenSocket($o{sockfile},$o{prefork}*$o{queue});
-     my $rqst=FCGI::Request(\*STDIN,\*STDOUT,\*STDERR,\%req_env,
--             FCGI::OpenSocket($o{sockfile},$o{prefork}*$o{queue}),
--             FCGI::FAIL_ACCEPT_ON_INTR())
-+             $o{socket_fh}, FCGI::FAIL_ACCEPT_ON_INTR())
-         or die "Error: Unable to create FCGI::Request...";
- 
--    if(defined $o{gid_num} and defined $o{uid_num}){                # if run as root
--        chown $o{uid_num},$o{gid_num},$o{sockfile}                  # chown SOCKfile
-+    if($EFFECTIVE_USER_ID==0){
-+        chown $o{uid_num},$o{gid_num},$o{sockfile}
-             or dieif($OS_ERROR,'Unable to chown SOCKfile');
-     }
- 
-     $o{fcgi_pm}->pm_manage();   # from now on we are worker process
- 
-+    if ($DEBUG) {
-+        use Data::Dumper;
-+        $Data::Dumper::Indent = 1;
-+        warn Data::Dumper->Dump([\%o],['o']);
-+    }
-+
-     # drop privileges if run as root
--    if(defined $o{gid_num} and defined $o{uid_num}){
--        local $REAL_GROUP_ID= local $EFFECTIVE_GROUP_ID= getgrnam($o{gid});
--            dieif($OS_ERROR,'Unable to change group_id to '.$o{gid});
--        local $REAL_USER_ID= local $EFFECTIVE_USER_ID= getpwnam($o{uid});
--            dieif($OS_ERROR,'Unable to change user_id to '.$o{uid});
-+    my $old_euid = $EFFECTIVE_USER_ID;
-+    if ($old_euid==0) {
-+        POSIX::setgid($o{gid_num}) or dieif($OS_ERROR,
-+            "UID $old_euid couldn't change group to $o{gid} ($o{gid_num})");
-+        POSIX::setuid($o{uid_num}) or dieif($OS_ERROR,
-+            "UID $old_euid couldn't change user to $o{uid} ($o{uid_num})");
-+    }
-+
-+    if ($DEBUG) {
-+        warn "REAL_USER_ID = $REAL_USER_ID";
-+        warn "EFFECTIVE_USER_ID = $EFFECTIVE_USER_ID";
-+        warn "REAL_GROUP_ID = $REAL_GROUP_ID";
-+        warn "EFFECTIVE_GROUP_ID = $EFFECTIVE_GROUP_ID";
-     }
- 
-     ## set rlimit(s)
diff --git a/p5-FCGI-Daemon/patches/patch-bsd5 b/p5-FCGI-Daemon/patches/patch-bsd5
deleted file mode 100644
index d1d8cb6f53..0000000000
--- a/p5-FCGI-Daemon/patches/patch-bsd5
+++ /dev/null
@@ -1,57 +0,0 @@
-$NetBSD$
-
-Instead of using a non-portable /proc/$$/status read to get memory
-usage on Linux, use a non-portable /bin/ps command on BSD platforms.
-
---- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
-+++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
-@@ -171,21 +180,37 @@
-                 delete $main::{$_};
-             }
- 
--            if(open my $STAT,'<',"/proc/$$/status"){
--                my %stat;
--                while(my ($k,$v)=split /\:\s+/,<$STAT>){
--                    chop $v;
--                    $stat{$k}=$v;
-+            exit unless --$o{max_evals};
-+
-+            # exit if child takes too much resident memory
-+            my %stat = ();
-+            if ( $OSNAME =~ m{bsd}oi ) {
-+                if (open my $STAT,'-|',"/bin/ps -o vsz,rss -p $$") {
-+                    while(<$STAT>) {
-+                        if ( m{^\s*(\d+)\s+(\d+)$}o ) {
-+                             $stat{VmSize} = $1;
-+                             $stat{VmRSS} = $2;
-+                             last;
-+                        }
-+                    }
-+                    close $STAT;
-                 }
--                close $STAT;
--                # check if child takes too much resident memory and terminate if necessary
--                if($stat{VmSize}/$stat{VmRSS}<$o{leak_threshold}){
--                    print {*STDERR} 'fcgi-daemon :: terminating child - memory leak? '
--                    ."VmSize:$stat{VmSize}; VmRSS:$stat{VmRSS}; Ratio:".$stat{VmSize}/$stat{VmRSS};
--                    exit;
-+            } else {
-+                if(open my $STAT,'<',"/proc/$$/status"){
-+                    while(my ($k,$v)=split /\:\s+/,<$STAT>){
-+                        chop $v;
-+                        $stat{$k}=$v;
-+                    }
-+                    close $STAT;
-                 }
-             }
--            exit unless --$o{max_evals};
-+            if ( $stat{VmSize} && $stat{VmRSS}
-+                   && ($stat{VmSize}/$stat{VmRSS}<$o{leak_threshold}) ) {
-+                 die 'fcgi-daemon :: terminating child - memory leak? '
-+                     ."VmSize:$stat{VmSize}; VmRSS:$stat{VmRSS}; Ratio:"
-+                     .$stat{VmSize}/$stat{VmRSS};
-+            }
-+
-             next REQ_LOOP;
-         }
- 
diff --git a/p5-FCGI-Daemon/patches/patch-bsd6 b/p5-FCGI-Daemon/patches/patch-bsd6
deleted file mode 100644
index ef57446c6d..0000000000
--- a/p5-FCGI-Daemon/patches/patch-bsd6
+++ /dev/null
@@ -1,28 +0,0 @@
-$NetBSD$
-
-Close socket when running as root (manager) and remove files in
-pm_die() routine.
-
---- lib/FCGI/Daemon.pm.orig	2015-12-26 09:28:53.000000000 +0100
-+++ lib/FCGI/Daemon.pm	2016-02-07 18:03:39.000000000 +0100
-@@ -243,6 +268,20 @@
-     return;
- }
- 
-+# close socket as manager
-+sub managing_init {
-+    # manager (running as root) doesn't need to listen on the socket
-+    close $o{socket_fh} if $EFFECTIVE_USER_ID==0;
-+    return $o{fcgi_pm}->managing_init(shift @_);
-+}
-+
-+# exit cleanly
-+sub pm_die {
-+    # manager (running as root) can remove these better
-+    unlink $o{$_} for qw(pidfile sockfile);
-+    return $o{fcgi_pm}->pm_die(shift @_);
-+}
-+
- # overriding process names
- sub FCGI::ProcManager::pm_change_process_name {
-     my ($self,$name)=@_;
diff --git a/p5-FCGI-Daemon/patches/patch-bsd7 b/p5-FCGI-Daemon/patches/patch-bsd7
deleted file mode 100644
index 0fd0fadb20..0000000000
--- a/p5-FCGI-Daemon/patches/patch-bsd7
+++ /dev/null
@@ -1,40 +0,0 @@
-$NetBSD$
-
-Option -X to enable debugging.
-
---- lib/FCGI/Daemon.pm.orig     2015-12-26 09:28:53.000000000 +0100
-+++ lib/FCGI/Daemon.pm  2016-02-07 18:03:39.000000000 +0100
-@@ -52,7 +52,7 @@
-     Modulino-style main routine
- =cut
- sub run {
--    getopts('hde:f:q:p:s:g:u:m:c:l:w:',\%o) or help(0);
-+    getopts('hde:f:q:p:s:g:u:m:c:l:w:X',\%o) or help(0);
-     help(2) if $o{'h'};
- 
-     $o{sockfile}=$o{'s'}||'/var/run/fcgi-daemon.sock';
-@@ -64,6 +64,7 @@
-     $o{max_evals}=defined $o{'e'} ? $o{'e'} : 10240;   #max evals before exit - paranoid to free memory if leaks
-     $o{file_pattern}=$o{'f'}||qr{\.pl};
-     $o{leak_threshold}=$o{'l'}||1.3;
-+    $DEBUG++ if $o{'X'};
- 
-     if($EFFECTIVE_USER_ID==0){
-         $o{gid}=$o{g}||'www-data'; $o{gid_num}=scalar getgrnam($o{gid});
-@@ -80,7 +80,7 @@
-         POSIX::setsid() or die q{Can't start a new session: }.$OS_ERROR;
-         open *STDIN,'<','/dev/null';
-         open *STDOUT,'>>','/dev/null';
--        open *STDERR,'>>','/dev/null';
-+        open *STDERR,'>>','/dev/null' unless $DEBUG;
-         umask 022;
-     }
-
-@@ -380,6 +381,7 @@
-   -u www-data                     # user name to become (if run as root)
-   -g www-data                     # group name to become (if run as root)
-   -d                              # daemonize (run in background)
-+  -X                              # enable debugging
- 
- All options are optional.
- 
diff --git a/p5-FCGI-Daemon/patches/patch-lib-FCGI-Daemon.pm b/p5-FCGI-Daemon/patches/patch-lib-FCGI-Daemon.pm
new file mode 100644
index 0000000000..997a2a8c90
--- /dev/null
+++ b/p5-FCGI-Daemon/patches/patch-lib-FCGI-Daemon.pm
@@ -0,0 +1,259 @@
+$NetBSD$
+
+Add an option -X to enable debugging.
+
+Unlink files without testing for existence as we ignore exit status
+anyway.
+
+Use POSIX calls setgid and setuid to non-root user when running as
+"root" daemon.
+
+Use only $EFFECTIVE_USER_ID to discrimiate if we need to set[gu]id
+and don't install signal handlers INT and TERM as FCGI::ProcManager
+does that.
+
+Close socket when running as root (manager) and remove files in
+pm_die() routine.
+
+Instead of using a non-portable /proc/$$/status read to get memory
+usage on Linux, use a non-portable /bin/ps command on BSD platforms.
+
+Mention NetBSD and pkgsrc in POD.
+
+Make sure all test pass.
+ 
+
+--- lib/FCGI/Daemon.pm.orig	2022-02-06 15:23:10.000000000 +0000
++++ lib/FCGI/Daemon.pm	2022-07-28 16:42:18.127502146 +0000
+@@ -6,6 +6,7 @@
+ package FCGI::Daemon;
+ our $VERSION = '0.20220206';
+ use 5.14.2;
++use POSIX;
+ use English '-no_match_vars';
+ use BSD::Resource;                      # on Debian available as libbsd-resource-perl
+ use FCGI 0.82;                          # on Debian available as libfcgi-perl
+@@ -25,6 +26,7 @@
+ =cut
+ 
+ my %o;
++my $DEBUG = 0;
+ 
+ __PACKAGE__->run() unless caller();     # modulino i.e. executable rather than module
+ 
+@@ -39,9 +41,7 @@
+ sub dieif {
+     if($ARG[0]){
+         my $err=$ARG[1];
+-        for my $f ( @o{'pidfile','sockfile'} ) {
+-            unlink $f if -f $f; 
+-        }        
++        unlink $o{$_} for qw(pidfile sockfile);
+         print "Error - $err:\n",$ARG[0],"\n";
+         exit 1;
+     }
+@@ -51,7 +51,7 @@
+     Modulino-style main routine
+ =cut
+ sub run {
+-    getopts('hde:f:q:p:s:g:u:m:c:l:w:',\%o) or help(0);
++    getopts('hde:f:q:p:s:g:u:m:c:l:w:X',\%o) or help(0);
+     help(2) if $o{'h'};
+ 
+     $o{sockfile}=$o{'s'}||'/var/run/fcgi-daemon.sock';
+@@ -63,21 +63,18 @@
+     $o{max_evals}=defined $o{'e'} ? $o{'e'} : 10240;   #max evals before exit - paranoid to free memory if leaks
+     $o{file_pattern}=$o{'f'}||qr{\.pl};
+     $o{leak_threshold}=$o{'l'}||1.3;
++    $DEBUG++ if $o{'X'};
+ 
+-    if($REAL_USER_ID==$EFFECTIVE_USER_ID and $EFFECTIVE_USER_ID==0){        # if run as root
++    if($EFFECTIVE_USER_ID==0){
+         $o{gid}=$o{g}||'www-data'; $o{gid_num}=scalar getgrnam($o{gid});
+         $o{uid}=$o{u}||'www-data'; $o{uid_num}=scalar getpwnam($o{uid});
+     }
+ 
+-    local $SIG{INT}= local $SIG{TERM}= sub{
+-        # actually FCGI::ProcManager override our TERM handler so .sock and .pid files will be removed only by sysv script... :(
+-        $o{fcgi_pm}->pm_remove_pid_file() if $o{fcgi_pm};
+-        for my $f ( @o{'pidfile','sockfile'} ) {
+-            unlink $f if -f $f; 
+-        }    
+-        $o{fcgi_pm}->pm_die() if $o{fcgi_pm};   #pm_die() does not return
+-        exit 0;
+-    };
++    if ($DEBUG) {
++        use Data::Dumper;
++        $Data::Dumper::Indent = 1;
++        warn Data::Dumper->Dump([\%o],['o']);
++    }
+ 
+     # daemonize
+     if($o{'d'}){
+@@ -85,10 +82,10 @@
+         local $PROGRAM_NAME='FCGI::Daemon';
+         defined(my $pid=fork) or die "Can't fork: $!";
+         exit if $pid;
+-        eval {use POSIX qw(setsid); POSIX::setsid();} or die q{Can't start a new session: }.$OS_ERROR;
++        POSIX::setsid() or die q{Can't start a new session: }.$OS_ERROR;
+         open *STDIN,'<','/dev/null';
+         open *STDOUT,'>>','/dev/null';
+-        open *STDERR,'>>','/dev/null';
++        open *STDERR,'>>','/dev/null' unless $DEBUG;
+         umask 022;
+     }
+ 
+@@ -98,32 +95,24 @@
+                                         pid_fname=>$o{pidfile}
+                                       });
+     print "Opening socket $o{sockfile}\n";
++    $o{socket_fh} = FCGI::OpenSocket($o{sockfile},$o{prefork}*$o{queue});
+     my $rqst=FCGI::Request(\*STDIN,\*STDOUT,\*STDERR,\%req_env,
+-             FCGI::OpenSocket($o{sockfile},$o{prefork}*$o{queue}),
+-             FCGI::FAIL_ACCEPT_ON_INTR())
++             $o{socket_fh}, FCGI::FAIL_ACCEPT_ON_INTR())
+         or die "Error: Unable to create FCGI::Request...";
+ 
+-    if(defined $o{gid_num} and defined $o{uid_num}){                # if run as root
+-        chown $o{uid_num},$o{gid_num},$o{sockfile}                  # chown SOCKfile
+-            or dieif($OS_ERROR,'Unable to chown SOCKfile');
++    # drop privileges if run as root
++    if(defined $o{uid_num} && defined $o{gid_num}) {
++        my $old_euid = $EFFECTIVE_USER_ID;
++        chown $o{uid_num},$o{gid_num},$o{sockfile}
++            or dieif($OS_ERROR,'Unable to chown SOCKfile '.$o{sockfile});
++        POSIX::setgid($o{gid_num}) or dieif($OS_ERROR,
++            "UID $old_euid couldn't change group to $o{gid} ($o{gid_num})");
++        POSIX::setuid($o{uid_num}) or dieif($OS_ERROR,
++            "UID $old_euid couldn't change user to $o{uid} ($o{uid_num})");
+     }
+ 
+     $o{fcgi_pm}->pm_manage();   # from now on we are worker process
+ 
+-    # drop privileges if run as root
+-    if(defined $o{gid_num} and defined $o{uid_num}){
+-       my $gid = getgrnam($o{gid});
+-       $EFFECTIVE_GROUP_ID = "$gid $gid";
+-       dieif($OS_ERROR,'Unable to effective group_id to '.$o{gid});
+-       $REAL_GROUP_ID = $gid;
+-       dieif($OS_ERROR,'Unable to change real group_id to '.$o{gid});
+-       my $uid = getpwnam($o{uid});
+-       $EFFECTIVE_USER_ID = $uid;
+-       dieif($OS_ERROR,'Unable to change effective user_id to '.$o{uid});
+-       $REAL_USER_ID  = $uid;
+-       dieif($OS_ERROR,'Unable to change real user_id to '.$o{uid});
+-    }
+-
+     ## set rlimit(s)
+     setrlimit(RLIMIT_AS, $o{rlimit_vmem}, $o{rlimit_vmem})
+       or warn "Unable to set RLIMIT_AS.\n";
+@@ -181,21 +170,37 @@
+                 delete $main::{$_};
+             }
+ 
+-            if(open my $STAT,'<',"/proc/$$/status"){
+-                my %stat;
+-                while(my ($k,$v)=split /\:\s+/,<$STAT>){
+-                    chop $v;
+-                    $stat{$k}=$v;
++            exit unless --$o{max_evals};
++
++            # exit if child takes too much resident memory
++            my %stat = ();
++            if ( $OSNAME =~ m{bsd}oi ) {
++                if (open my $STAT,'-|',"/bin/ps -o vsz,rss -p $$") {
++                    while(<$STAT>) {
++                        if ( m{^\s*(\d+)\s+(\d+)$}o ) {
++                             $stat{VmSize} = $1;
++                             $stat{VmRSS} = $2;
++                             last;
++                        }
++                    }
++                    close $STAT;
+                 }
+-                close $STAT;
+-                # check if child takes too much resident memory and terminate if necessary
+-                if($stat{VmSize}/$stat{VmRSS}<$o{leak_threshold}){
+-                    print {*STDERR} 'fcgi-daemon :: terminating child - memory leak? '
+-                    ."VmSize:$stat{VmSize}; VmRSS:$stat{VmRSS}; Ratio:".$stat{VmSize}/$stat{VmRSS};
+-                    exit;
++            } else {
++                if(open my $STAT,'<',"/proc/$$/status"){
++                    while(my ($k,$v)=split /\:\s+/,<$STAT>){
++                        chop $v;
++                        $stat{$k}=$v;
++                    }
++                    close $STAT;
+                 }
+             }
+-            exit unless --$o{max_evals};
++            if ( $stat{VmSize} && $stat{VmRSS}
++                   && ($stat{VmSize}/$stat{VmRSS}<$o{leak_threshold}) ) {
++                 die 'fcgi-daemon :: terminating child - memory leak? '
++                     ."VmSize:$stat{VmSize}; VmRSS:$stat{VmRSS}; Ratio:"
++                     .$stat{VmSize}/$stat{VmRSS};
++            }
++
+             next REQ_LOOP;
+         }
+ 
+@@ -253,6 +258,24 @@
+     return;
+ }
+ 
++=head2 managing_init ()
++    close socket as manager
++=cut
++sub managing_init {
++    # manager (running as root) doesn't need to listen on the socket
++    close $o{socket_fh} if $EFFECTIVE_USER_ID==0;
++    return $o{fcgi_pm}->managing_init(shift @_);
++}
++
++=head2 pm_die()
++    exit cleanly
++=cut
++sub pm_die {
++    # manager (running as root) can remove these better
++    unlink $o{$_} for qw(pidfile sockfile);
++    return $o{fcgi_pm}->pm_die(shift @_);
++}
++
+ # overriding process names
+ sub FCGI::ProcManager::pm_change_process_name {
+     my ($self,$name)=@_;
+@@ -293,7 +316,7 @@
+ CGI applications.
+ 
+ Like mod_perl FCGI-Daemon stay persistent in memory and accelerate
+-unmodified CGI applications written in Perl. 
++unmodified CGI applications written in Perl.
+ 
+ FCGI-Daemon run CGI scripts with RLIMITs and predefined number of workers.
+ 
+@@ -302,7 +325,7 @@
+ 
+ FCGI-Daemon check for executable in path and correctly set PATH_INFO
+ environment variable which is crucial for some CGI applications like
+-fossil (L<http://fossil-scm.org>). 
++fossil (L<http://fossil-scm.org>).
+ (Lack of this functionality make cgiwrap-fcgi.pl unsuitable for some scripts.)
+ 
+ 
+@@ -351,6 +374,7 @@
+   -u www-data                     # user name to become (if run as root)
+   -g www-data                     # group name to become (if run as root)
+   -d                              # daemonize (run in background)
++  -X                              # enable debugging
+ 
+ All options are optional.
+ 
+@@ -410,7 +434,7 @@
+ 
+ =head1 COMPATIBILITY
+ 
+-Tested only on GNU/Linux systems.
++Tested on GNU/Linux and NetBSD systems (pkgsrc).
+ NOT tested and not expected to work on Windows.
+ 
+ =head1 NOTES


Home | Main Index | Thread Index | Old Index