psh
view release on metacpan or search on metacpan
lib/Psh/OS/Unix.pm view on Meta::CPAN
sub get_all_users {
unless (@user_cache) {
CORE::setpwent;
while (my ($name) = CORE::getpwent) {
push(@user_cache,'~'.$name);
}
CORE::endpwent;
}
return @user_cache;
}
}
#
# void display_pod(text)
#
sub display_pod {
my $tmp= Psh::OS::tmpnam();
my $text= shift;
local *TMP;
open( TMP,">$tmp");
print TMP $text;
close(TMP);
eval {
require Pod::Text;
Pod::Text::pod2text($tmp,*STDOUT);
};
Psh::Util::print_debug_class('e',"Error: $@") if $@;
print $text if $@;
unlink($tmp);
}
sub get_home_dir {
my $user = shift || $ENV{USER};
return $ENV{HOME} if ((! $user) && (-d $ENV{HOME}));
return (CORE::getpwnam($user))[7]||'';
}
sub get_rc_files {
my @rc=();
if (-r '/etc/pshrc') {
push @rc, '/etc/pshrc';
}
my $home= Psh::OS::get_home_dir();
if ($home) { push @rc, catfile($home,'.pshrc') };
return @rc;
}
sub get_path_extension { return (''); }
#
# int inc_shlvl ()
#
# Increments $ENV{SHLVL}. Also checks for login shell status and does
# appropriate OS-specific tasks depending on it.
#
sub inc_shlvl {
my @pwent = CORE::getpwuid($<);
if ((! $ENV{SHLVL}) && ($pwent[8] eq $0)) { # would use $Psh::bin, but login shells are guaranteed full paths
$Psh::login_shell = 1;
$ENV{SHLVL} = 1;
} else {
$Psh::login_shell = 0;
$ENV{SHLVL}++;
}
}
###################################################################
# JOB CONTROL
###################################################################
#
# void _give_terminal_to (int PID)
#
# Make pid the foreground process of the terminal controlling STDIN.
#
{
my $terminal_owner=0;
sub _give_terminal_to
{
# If a fork of a psh fork tries to call this then exit
# as it would probably mess up the shell
# This hack is necessary as e.g.
# alias ls=/bin/ls
# ls &
# call fork_process from within a fork
return if $Psh::OS::Unix::forked_already;
return if $terminal_owner==$_[0];
$terminal_owner=$_[0];
local $SIG{TSTP} = 'IGNORE';
local $SIG{TTIN} = 'IGNORE';
local $SIG{TTOU} = 'IGNORE';
local $SIG{CHLD} = 'IGNORE';
my ($pkg,$file,$line,$sub)= caller(1);
my $status= POSIX::tcsetpgrp(fileno STDIN,$_[0]);
}
sub _get_terminal_owner
{
return $terminal_owner;
}
}
#
# void _wait_for_system(int PID, [bool QUIET_EXIT], [bool NO_TERMINAL])
#
# Waits for a program to be stopped/ended, prints no message on normal
# termination if QUIET_EXIT is specified and true.
#
( run in 0.582 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )