File: hppfslib.pm

package info (click to toggle)
uml-utilities 20070815.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 752 kB
  • sloc: ansic: 3,392; perl: 1,277; makefile: 239; exp: 129; sh: 122
file content (64 lines) | stat: -rw-r--r-- 1,172 bytes parent folder | download | duplicates (8)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 
# Copyright (C) 2002, 2003 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#

package hppfslib;

use Exporter   ();
use vars       qw(@ISA @EXPORT);

use strict;

@ISA         = qw(Exporter);
@EXPORT      = qw(&remove_lines &host &host_proc &dup_proc_dir);

sub remove_lines {
    my @remove = @_;

    return( [ sub { my $input = shift;

		    foreach my $str (@remove){
			$input =~ s/^.*$str.*\n//mg;
		    }
		    return($input) }, 
	      "rw" ] );
}

sub host {
    my $file = shift;

    return( [ sub { return(`cat $file`); },
	      "r" ] );
}

sub host_proc {
    my $file = shift;

    return(host("/proc/$file"));
}

sub dup_proc_dir {
    my $to = shift;
    my $root = shift;
    my $new = "$root/proc/$to";
    
    -e $new and `rm -rf $new`;
    !mkdir $new and warn "Couldn't create '$new' : $!";

    my @dirs = `cd /proc/$to ; find . -type d -print`;
    chomp @dirs;
    foreach my $dir (@dirs){
	$dir eq "." and next;

	my $new_dir = "$new/$dir";
	!mkdir $new_dir and warn "Couldn't create '$new_dir' : $!";
    }

    my @files = `cd /proc ; find $to -type f -print`;
    chomp @files;

    return(map { $_ => host_proc($_) } @files);
}

1;