develooper Front page | perl.perl5.porters | Postings from August 2001

[PATCH] pod/perlfunc.pod, lib/Net/Ping.pm, ext/POSIX/POSIX.pod

Thread Next
From:
chromatic
Date:
August 27, 2001 10:21
Subject:
[PATCH] pod/perlfunc.pod, lib/Net/Ping.pm, ext/POSIX/POSIX.pod
Message ID:
20010827172111.89491.qmail@onion.perl.org
The example code for waitpid in perlfunc recommends the &WNOHANG
construct.  In certain cases, this can cause a spurious and curious
warning message in the POSIX module.

For example:

	use POSIX;

	$SIG{CHLD} = sub {
		warn "@_";
		my $process_id = waitpid(-1,&WNOHANG); warn "Reaped $process_id!";
	};

	defined(my $pid = fork()) or die;

	if ($pid) {
    		warn "Launched $pid!";
    		sleep 1;
	}

producing:

	Argument "CHLD" isn't numeric in entersub at
	/usr/lib/perl5/5.00503/i386-linux/POSIX.pm line 207.

Removing the ampersand from WNOHANG avoids the warning. (It does not
silently pass along the contents of @_).

The following patches against 5.7.2 update the documentation to recommend
a bareword call (already used in perlipc).  In addition, one core module
used the dodgy semantics.

--- ext/POSIX/~POSIX.pod	Mon Aug 27 11:06:33 2001 +++ ext/POSIX/POSIX.pod
Mon Aug 27 11:06:50 2001 @@ -1535,7 +1535,7 @@
 Wait for a child process to change state.  This is identical to Perl's
 builtin C<waitpid()> function, see L<perlfunc/waitpid>.
 
-	$pid = POSIX::waitpid( -1, &POSIX::WNOHANG ); 
+	$pid = POSIX::waitpid( -1, POSIX::WNOHANG );
 	print "status = ", ($? / 256), "\n";
 
 =item wcstombs

--- pod/~perlfunc.pod	Mon Aug 27 10:56:12 2001 +++ pod/perlfunc.pod	Mon
Aug 27 10:56:26 2001 @@ -5915,7 +5915,7 @@
     use POSIX ":sys_wait_h";
     #...
     do {
-	$kid = waitpid(-1,&WNOHANG);
+	$kid = waitpid(-1,WNOHANG);
     } until $kid == -1;
 
 then you can do a non-blocking wait for all pending zombie processes.

--- lib/Net/~Ping.pm	Mon Aug 27 11:00:38 2001 +++ lib/Net/Ping.pm	Mon Aug
27 11:00:48 2001 @@ -353,7 +353,7 @@
 
 	# Wait for the child to return or for the timeout to expire. do {
-		$child = waitpid($pid, &WNOHANG);
+		$child = waitpid($pid, WNOHANG);
 		$ret = $?;
 	} until time > ($time + $timeout) or $child;
 
-- c

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About