Re: [PATCH] Start revamping perlipc.pod

[email protected] (Shlomi Fish) Sun, 5 Sep 2010 18:01:08 +0300
Newsgroups perl.perl5.porters,perl.documentation
Message-ID <[email protected]>
On Sunday 05 September 2010 17:58:54 Shlomi Fish wrote:
> On Sunday 05 September 2010 08:13:02 Jesse Vincent wrote:
> > On Sun, Sep 05, 2010 at 08:03:41AM +0300, Shlomi Fish wrote:
> > > Hi all,
> > >=20
> > > Inspired by a message ot the perl documentation proejct, I started
> > > working on revamping perlipc.pod here:
> > >=20
> > > http://github.com/shlomif/perl/tree/perlipc-revamp
> > >=20
> > > What I did so far is convert all tabs to spaces (as the indentation w=
as
> > > very erratic) and started modernising the code
> >=20
> > Shlomi,
> >=20
> > Thanks for starting to look at perlipc. Is there a chance you could send
> > your patch as a series that splits out the whitespace changes from the
> > code/prose changes?  Heavy whitespace changes tend to make it much
> > harder to review "contentful" changes in a patch, since there are
> > so many lines of diff that aren't actually semantically meaningful.
> >=20
> > Thanks,
> > Jesse
>=20
> Thanks to the git history, I can. Here is the tabs->spaces patch and the
> next reply will contain the code/prose changes. I've marked the transition
> in the repository using the =ABperlipc_pod_after_changing_tabs_to_spaces=
=BB
> tag.
>=20
> Regards,
>=20
> 	Shlomi Fish
>=20

And here's the code/prose changes patch which works againt the version afte=
r=20
the tabs->spaces conversion:

Regards,

	Shlomi Fish

diff --git a/pod/perlipc.pod b/pod/perlipc.pod
index 9c556d0..4bc119b 100644
=2D-- a/pod/perlipc.pod
+++ b/pod/perlipc.pod
@@ -48,11 +48,21 @@ system, or you can retrieve them from the Config module=
=2E =20
Set up an
 indexed by name to get the number:
=20
     use Config;
=2D    defined $Config{sig_name} || die "No sigs?";
=2D    foreach $name (split(' ', $Config{sig_name})) {
=2D        $signo{$name} =3D $i;
=2D        $signame[$i] =3D $name;
=2D        $i++;
+
+    if (!defined $Config{sig_name})
+    {
+        die "No sigs?";
+    }
+
+    my (%signo, @signame);
+
+    my $index =3D 0;
+
+    foreach my $name (split(' ', $Config{sig_name})) {
+        $signo{$name} =3D $index;
+        $signame[$index] =3D $name;
+
+        $index++;
     }
=20
 So to check whether signal 17 and SIGALRM were the same, do just this:
@@ -82,8 +92,9 @@ values are "inherited" by functions called from within th=
at=20
block.)
=20
     sub precious {
         local $SIG{INT} =3D 'IGNORE';
=2D        &more_functions;
+        more_functions();
     }
+
     sub more_functions {
         # interrupts still ignored, for now...
     }
@@ -119,7 +130,7 @@ You may be able to determine the cause of failure using=
=20
C<%!>.
 You might also want to employ anonymous functions for simple signal
 handlers:
=20
=2D    $SIG{INT} =3D sub { die "\nOutta here!\n" };
+    $SIG{INT} =3D sub { die "\nOutta here!\n"; };
=20
 But that will be problematic for the more complicated handlers that need
 to reinstall themselves.  Because Perl's signal mechanism is currently
@@ -169,25 +180,38 @@ example:
     my %children;
=20
     $SIG{CHLD} =3D sub {
+
         # don't change $! and $? outside handler
         local ($!,$?);
+
         my $pid =3D waitpid(-1, WNOHANG);
+
         return if $pid =3D=3D -1;
+
         return unless defined $children{$pid};
+
         delete $children{$pid};
+
         cleanup_child($pid, $?);
     };
=20
     while (1) {
+
         my $pid =3D fork();
+
         if ($pid =3D=3D 0) {
=2D            # ...
+
+            # I'm the child - do something.
             exit 0;
=2D        } else {
=2D        $children{$pid}=3D1;
+
+        }
+        else {
+
+            $children{$pid}=3D1;
             # ...
             system($command);
             # ...
+
        }
     }
=20
@@ -202,12 +226,16 @@ using longjmp() or throw() in other languages.
 Here's an example:
=20
     eval {
=2D        local $SIG{ALRM} =3D sub { die "alarm clock restart" };
+
+        local $SIG{ALRM} =3D sub { die "alarm clock restart"; };
+
         alarm 10;
         flock(FH, 2);   # blocking write lock
         alarm 0;
+
     };
=2D    if ($@ and $@ !~ /alarm clock restart/) { die }
+
+    if ($@ and $@ !~ /alarm clock restart/) { die; }
=20
 If the operation being timed out is system() or qx(), this technique
 is liable to generate zombies.    If this matters to you, you'll
@@ -249,16 +277,18 @@ info to show that it works and should be replaced wit=
h=20
the real code.
=20
   $|=3D1;
=20
=2D  # make the daemon cross-platform, so exec always calls the script
+  # Make the daemon cross-platform, so exec always calls the script
   # itself with the right path, no matter how the script was invoked.
   my $script =3D File::Basename::basename($0);
   my $SELF =3D catfile $FindBin::Bin, $script;
=20
   # POSIX unmasks the sigprocmask properly
   my $sigset =3D POSIX::SigSet->new();
+
   my $action =3D POSIX::SigAction->new('sigHUP_handler',
                                      $sigset,
                                      &POSIX::SA_NODEFER);
+
   POSIX::sigaction(&POSIX::SIGHUP, $action);
=20
   sub sigHUP_handler {
@@ -269,9 +299,12 @@ info to show that it works and should be replaced with=
=20
the real code.
   code();
=20
   sub code {
+
       print "PID: $$\n";
       print "ARGV: @ARGV\n";
+
       my $c =3D 0;
+
       while (++$c) {
           sleep 2;
           print "$c\n";

=2D-=20
=2D----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Understand what Open Source is - http://shlom.in/oss-fs

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .