NaNQ? tweak
[p5sagit/p5-mst-13.2.git] / t / lib / ipc_sysv.t
index f74c5fa..23476e1 100755 (executable)
@@ -3,7 +3,7 @@
 BEGIN {
     chdir 't' if -d 't';
 
-    @INC = '../lib';
+    unshift @INC, '../lib';
 
     require Config; import Config;
 
@@ -18,7 +18,7 @@ BEGIN {
 # Later the sem* tests will import more for themselves.
 
 use IPC::SysV qw(IPC_PRIVATE IPC_NOWAIT IPC_STAT IPC_RMID
-                S_IRWXU S_IRWXG S_IRWXO);
+                S_IRWXU S_IRWXG S_IRWXO S_IWGRP S_IROTH S_IWOTH);
 use strict;
 
 print "1..16\n";
@@ -28,11 +28,40 @@ my $sem;
 
 $SIG{__DIE__} = 'cleanup'; # will cleanup $msg and $sem if needed
 
+# FreeBSD is known to throw this if there's no SysV IPC in the kernel.
+$SIG{SYS} = sub {
+    print STDERR <<EOM;
+SIGSYS caught.
+It may be that your kernel does not have SysV IPC configured.
+
+EOM
+    if ($^O eq 'freebsd') {
+       print STDERR <<EOM;
+You must have following options in your kernel:
+
+options         SYSVSHM
+options         SYSVSEM
+options         SYSVMSG
+
+See config(8).
+EOM
+    }
+    exit(1);
+};
+
+my $perm;
+
+$perm = S_IRWXU | S_IRWXG | S_IRWXO | S_IWGRP | S_IROTH | S_IWOTH
+    if $^O eq 'vmesa';
+
+$perm = S_IRWXU | S_IRWXG | S_IRWXO unless defined $perm;
+
 if ($Config{'d_msgget'} eq 'define' &&
     $Config{'d_msgctl'} eq 'define' &&
     $Config{'d_msgsnd'} eq 'define' &&
     $Config{'d_msgrcv'} eq 'define') {
-    $msg = msgget(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO);
+
+    $msg = msgget(IPC_PRIVATE, $perm);
     # Very first time called after machine is booted value may be 0 
     die "msgget failed: $!\n" unless defined($msg) && $msg >= 0;
 
@@ -71,7 +100,7 @@ if($Config{'d_semget'} eq 'define' &&
 
     use IPC::SysV qw(IPC_CREAT GETALL SETALL);
 
-    $sem = semget(IPC_PRIVATE, 10, S_IRWXU | S_IRWXG | S_IRWXO | IPC_CREAT);
+    $sem = semget(IPC_PRIVATE, 10, $perm | IPC_CREAT);
     # Very first time called after machine is booted value may be 0 
     die "semget: $!\n" unless defined($sem) && $sem >= 0;
 
@@ -84,43 +113,19 @@ if($Config{'d_semget'} eq 'define' &&
     print "not " unless length($data);
     print "ok 9\n";
 
-    my $template;
-
-    # Find the pack/unpack template capable of handling native C shorts.
-
-    if      ($Config{shortsize} == 2) {
-       $template = "s";
-    } elsif ($Config{shortsize} == 4) {
-       $template = "l";
-    } elsif ($Config{shortsize} == 8) {
-       # Try quad last because not supported everywhere.
-       foreach my $t (qw(i q)) {
-           # We could trap the unsupported quad template with eval
-           # but if we get this far we should have quad support anyway.
-           if (length(pack($t, 0)) == 8) {
-               $template = $t;
-               last;
-           }
-       }
-    }
-
-    die "$0: cannot pack native shorts\n" unless defined $template;
-
-    $template .= "*";
-
     my $nsem = 10;
 
-    semctl($sem,0,SETALL,pack($template,(0) x $nsem)) or print "not ";
+    semctl($sem,0,SETALL,pack("s_*",(0) x $nsem)) or print "not ";
     print "ok 10\n";
 
     $data = "";
     semctl($sem,0,GETALL,$data) or print "not ";
     print "ok 11\n";
 
-    print "not " unless length($data) == length(pack($template,(0) x $nsem));
+    print "not " unless length($data) == length(pack("s_*",(0) x $nsem));
     print "ok 12\n";
 
-    my @data = unpack($template,$data);
+    my @data = unpack("s_*",$data);
 
     my $adata = "0" x $nsem;
 
@@ -130,14 +135,14 @@ if($Config{'d_semget'} eq 'define' &&
     my $poke = 2;
 
     $data[$poke] = 1;
-    semctl($sem,0,SETALL,pack($template,@data)) or print "not ";
+    semctl($sem,0,SETALL,pack("s_*",@data)) or print "not ";
     print "ok 14\n";
     
     $data = "";
     semctl($sem,0,GETALL,$data) or print "not ";
     print "ok 15\n";
 
-    @data = unpack($template,$data);
+    @data = unpack("s_*",$data);
 
     my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);