Add fix for RT #71271.
[perl-fuse.git] / test / helper.pm
1 #!/usr/bin/perl
2 package test::helper;
3 use strict;
4 use Exporter;
5 use Config;
6 use POSIX qw(WEXITSTATUS);
7 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
8 @ISA = "Exporter";
9 @EXPORT_OK = qw($_loop $_opts $_point $_pidfile $_real);
10 my $tmp = -d '/private' ? '/private/tmp' : '/tmp';
11 our($_loop, $_point, $_pidfile, $_real, $_opts) = ('examples/loopback.pl',"$tmp/fusemnt-".$ENV{LOGNAME},"test/s/mounted.pid","$tmp/fusetest-".$ENV{LOGNAME}, '');
12 $_opts = '--pidfile ' . $_pidfile;
13 $_opts .= $Config{useithreads} ? ' --use-threads' : '';
14 if($0 !~ qr|s/u?mount\.t$|) {
15         my ($reject) = 1;
16         if(open my $fh, '<', $_pidfile) {
17                 my $pid = do {local $/ = undef; <$fh>};
18                 close $fh;
19                 if(kill 0, $pid) {
20                         if(`mount` =~ m{on (?:/private)?$_point }) {
21                                 $reject = 0;
22                         } else {
23                                 kill 1, $pid;
24                         }
25                 }
26         }
27         system("ls $_point >/dev/null");
28         $reject = 1 if (POSIX::WEXITSTATUS($?));
29         die "not properly mounted\n" if $reject;
30 }
31 1;