Improve process handling and environment setup for login shell functionality
This commit is contained in:
parent
088c61e19b
commit
2f002b9735
2 changed files with 74 additions and 7 deletions
|
@ -52,11 +52,15 @@ sub handle {
|
|||
# Check PATH directly
|
||||
foreach my $path (split(/:/, $ENV{PATH})) {
|
||||
my $full_path = "$path/$cmd_name";
|
||||
if (-x $full_path) {
|
||||
#print STDERR "DEBUG: Found in PATH: $full_path\n";
|
||||
system($command);
|
||||
return 2; # System command executed
|
||||
}
|
||||
if (-x $full_path) {
|
||||
my $pid = fork();
|
||||
die "Fork failed: $!" unless defined $pid;
|
||||
if ($pid == 0) { # Child
|
||||
exec($full_path, split(/\s+/, $command)) or die "Exec failed: $!";
|
||||
}
|
||||
waitpid($pid, 0); # Wait for child
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
#print STDERR "DEBUG: Command not found: $command\n";
|
||||
return -1; # Command not found
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue