diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-04-15 10:02:58 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-04-15 10:10:19 +1200 |
commit | 9934eda9775d6b182389f24df8a38d68b93ba032 (patch) | |
tree | 8ea17d0db86a20fc6a815246a482cc27b1733fde /cmd.c | |
parent | Test banner written (diff) | |
download | spsh-9934eda9775d6b182389f24df8a38d68b93ba032.tar.gz spsh-9934eda9775d6b182389f24df8a38d68b93ba032.zip |
Use execvp(3) to implement PATH search
Diffstat (limited to 'cmd.c')
-rw-r--r-- | cmd.c | 22 |
1 files changed, 6 insertions, 16 deletions
@@ -30,23 +30,13 @@ void cmd(char *line) { return; } - /* If the command looks to be executable ... */ - if (access(cmd, X_OK) != -1) { - - /* ... fork and try to execute it; wait until the fork is done. */ - pid = fork(); - if (pid == 0) { - cmd_argv[0] = cmd; - execve(cmd, cmd_argv, environ); - } - waitpid(pid, &status, 0); - } - - /* Otherwise, print an error, because we couldn't find the command */ - else { - fprintf(stderr, "Command ā%sā not found\n", cmd); - return; + /* Fork and try to execute it; wait until the fork is done. */ + pid = fork(); + if (pid == 0) { + cmd_argv[0] = cmd; + execvp(cmd, cmd_argv); } + waitpid(pid, &status, 0); return; } |