/usr/share/perl5/NeedRestart/Utils.pm is in needrestart 1.2-8+deb8u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | # needrestart - Restart daemons after library updates.
#
# Authors:
# Thomas Liske <thomas@fiasko-nw.net>
#
# Copyright Holder:
# 2013 - 2014 (C) Thomas Liske [http://fiasko-nw.net/~thomas/]
#
# License:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
package NeedRestart::Utils;
use strict;
use warnings;
use Proc::ProcessTable;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
nr_ptable
nr_ptable_pid
nr_parse_cmd
nr_parse_env
nr_readlink
nr_stat
nr_fork_pipe
nr_fork_pipe2
);
my %ptable = map {$_->pid => $_} @{ new Proc::ProcessTable(enable_ttys => 0)->table };
sub nr_ptable() {
return \%ptable;
}
sub nr_ptable_pid($) {
my $pid = shift;
return $ptable{$pid};
}
sub nr_parse_cmd($) {
my $pid = shift;
my $fh;
open($fh, '<', "/proc/$pid/cmdline") || return ();
local $/ = "\000";
my @cmdline = <$fh>;
chomp(@cmdline);
close($fh);
return @cmdline;
}
sub nr_parse_env($) {
my $pid = shift;
my $fh;
open($fh, '<', "/proc/$pid/environ") || return ();
local $/ = "\000";
my @env = <$fh>;
chomp(@env);
close($fh);
return map { (/^([^=]+)=(.*)$/ ? ($1, $2) : ()) } @env;
}
my %readlink;
sub nr_readlink($) {
my $pid = shift;
return $readlink{$pid} if(exists($readlink{$pid}));
my $fn = "/proc/$pid/exe";
return ($readlink{$pid} = readlink($fn));
}
my %stat;
sub nr_stat($) {
my $fn = shift;
return $stat{$fn} if(exists($stat{$fn}));
my @stat = stat($fn);
return undef unless($#stat > -1);
$stat{$fn} = {
dev => $stat[0],
ino => $stat[1],
mode => $stat[2],
nlink => $stat[3],
uid => $stat[4],
gid => $stat[5],
rdev => $stat[6],
size => $stat[7],
atime => $stat[8],
mtime => $stat[9],
ctime => $stat[10],
blksize => $stat[11],
blocks => $stat[12],
};
return $stat{$fn};
}
sub nr_fork_pipe($@) {
my $debug = shift;
my $pid = open(HPIPE, '-|');
defined($pid) || die "Can't fork: $!\n";
if($pid == 0) {
close(STDIN);
close(STDERR) unless($debug);
undef $ENV{LANG};
exec(@_);
exit;
}
\*HPIPE
}
sub nr_fork_pipe2($@) {
my $debug = shift;
my ($pread, $fhwrite);
pipe($pread, $fhwrite) || die "Can't pipe: $!\n";
my $fhread;
my $pid = open($fhread, '-|');
defined($pid) || die "Can't fork: $!\n";
if($pid == 0) {
open(STDIN, '<&', $pread) || die "Can't dup stdin: $!\n";
close(STDERR) unless($debug);
undef $ENV{LANG};
exec(@_);
exit;
}
close($pread);
return ($fhread, $fhwrite);
}
1;
|