Skip to content

Commit

Permalink
Fixed "cannot fork" error in Windows Web PVR Manager (with caveats)
Browse files Browse the repository at this point in the history
The WPM must call waitpid() on Windows even though zombie child processes
are automatically reaped. This resets internal Perl data structures and
permits the WPM to fork more than 64 child processes, and thus enables
the pvr list to auto-run and the cache to auto-refresh for extended
periods of time.

However, waitpid() must be called in the main server loop on Windows (no
SIGCHLD generated). This means there is the potential for errors when an
auto-run pvr request comes at the same time as a request generated by
another WPM task in another window/tab. Windows users will need to avoid
that situation. Warning messages have been added to the auto-loading pages
(Windows only).

This does not affect Unix/OS X users or CGI deployments of the WPM.

Closes #268
  • Loading branch information
dinkypumpkin committed Jul 20, 2016
1 parent 992d670 commit 9986f11
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions get_iplayer.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ my @nosearch_params = qw/ /;
### Perl CGI Web Server ###
use Socket;
use IO::Socket;
use POSIX ":sys_wait_h";
my $IGNOREEXIT = 0;
# If the port number is specified then run embedded web server
if ( $opt_cmdline->{port} > 0 ) {
Expand All @@ -332,6 +333,10 @@ if ( $opt_cmdline->{port} > 0 ) {
# Parent
if ( $procid ) {
close $client;
# must call waitpid() on Windows
if ( IS_WIN32 ) {
while ( abs(waitpid(-1, WNOHANG)) > 1 ) {}
}
next;
}
# Child
Expand Down Expand Up @@ -739,6 +744,9 @@ sub run_cgi {

sub pvr_run {
print $fh "<strong><p>The PVR will auto-run every $opt->{AUTOPVRRUN}->{current} hour(s) if you leave this page open</p></strong>" if $opt->{AUTOPVRRUN}->{current};
if ( IS_WIN32 ) {
print $fh "<strong><p>Windows users: You may encounter errors if you perform other tasks in the Web PVR Manager while this page is reloading</p></strong>" if $opt->{AUTOPVRRUN}->{current};
}
print $se "INFO: Starting PVR Run\n";
my @cmd = (
$opt_cmdline->{getiplayer},
Expand Down Expand Up @@ -2740,6 +2748,9 @@ sub refresh {
my $typelist = join(",", $cgi->param( 'PROGTYPES' )) || 'tv';
my $refreshfuture = $cgi->param( 'REFRESHFUTURE' ) || 0;
print $fh "<strong><p>The cache will auto-refresh every $opt->{AUTOWEBREFRESH}->{current} hour(s) if you leave this page open</p></strong>" if $opt->{AUTOWEBREFRESH}->{current};
if ( IS_WIN32 ) {
print $fh "<strong><p>Windows users: You may encounter errors if you perform other tasks in the Web PVR Manager while this page is reloading</p></strong>" if $opt->{AUTOWEBREFRESH}->{current};
}
print $se "INFO: Refreshing\n";
my @cmd = (
$opt_cmdline->{getiplayer},
Expand Down

0 comments on commit 9986f11

Please sign in to comment.