File: helper.pm

package info (click to toggle)
libfuse-perl 0.16.1%2B20180422git6becd92d7fce3fc411d7c-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 612 kB
  • sloc: perl: 1,938; makefile: 8
file content (42 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl
package # avoid cpan indexing
	test::helper;
use strict;
use Exporter;
use Config;
use POSIX qw(WEXITSTATUS);
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
@ISA = "Exporter";
@EXPORT_OK = qw($_loop $_opts $_point $_pidfile $_real $_logfile);
my $tmp = -d '/private' ? '/private/tmp' : '/tmp';

our $_loop    = 'examples/loopback.pl';
our $_point   = "$tmp/fusemnt-".$ENV{LOGNAME};
our $_pidfile = $ENV{'PWD'} . "/test/s/mounted.pid";
our $_real    = "$tmp/fusetest-".$ENV{LOGNAME};
our $_opts    = '';
our $_logfile = "$tmp/fusemnt.log";

$_opts  = ' --pidfile ' . $_pidfile;
$_opts .= ' --logfile ' . $_logfile;
$_opts .= $Config{useithreads} ? ' --use-threads' : '';

if($0 !~ qr|s/u?mount\.t$|) {
	my ($reject) = 1;
	if(open my $fh, '<', $_pidfile) {
		my $pid = do {local $/ = undef; <$fh>};
		close $fh;
		if(kill 0, $pid) {
			my $pattern = $^O eq 'solaris' ? qr{^$_point on }m : qr{on (?:/private)?$_point };
			if(`mount` =~ $pattern) {
				$reject = 0;
			} else {
				kill 1, $pid;
			}
		}
	}
	system("ls $_point >/dev/null");
	$reject = 1 if (POSIX::WEXITSTATUS($?));
	die "not properly mounted\n" if $reject;
}
1;