Server IP : 172.67.216.182 / Your IP : 162.158.106.122 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/perl5/NeedRestart/ |
Upload File : |
# needrestart - Restart daemons after library updates. # # Authors: # Thomas Liske <[email protected]> # # Copyright Holder: # 2013 - 2020 (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_pipe_stderr nr_fork_pipew nr_fork_pipe2 ); my %ptable; { local $SIG{__WARN__} = sub {}; %ptable = map {$_->pid => $_} @{ new Proc::ProcessTable(enable_ttys => 1)->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_pipe_stderr { my $debug = shift; my $pid = open(HPIPE, '-|'); defined($pid) || die "Can't fork: $!\n"; if($pid == 0) { open(STDERR, '>&', STDOUT) || die "Can't dup stderr: $!\n"; close(STDIN); undef $ENV{LANG}; exec(@_); exit; } \*HPIPE } sub nr_fork_pipew($@) { my $debug = shift; my $pid = open(HPIPE, '|-'); defined($pid) || die "Can't fork: $!\n"; if($pid == 0) { close(STDOUT); 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;