Improve process handling and environment setup for login shell functionality

This commit is contained in:
kake26 2025-04-24 20:57:38 -05:00
parent 088c61e19b
commit 2f002b9735
Signed by: kake26
GPG key ID: E0A989B571D1F99F
2 changed files with 74 additions and 7 deletions

View file

@ -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