aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-04-15 10:02:58 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-04-15 10:10:19 +1200
commit9934eda9775d6b182389f24df8a38d68b93ba032 (patch)
tree8ea17d0db86a20fc6a815246a482cc27b1733fde
parentTest banner written (diff)
downloadspsh-9934eda9775d6b182389f24df8a38d68b93ba032.tar.gz
spsh-9934eda9775d6b182389f24df8a38d68b93ba032.zip
Use execvp(3) to implement PATH search
-rw-r--r--README.markdown6
-rw-r--r--cmd.c22
2 files changed, 6 insertions, 22 deletions
diff --git a/README.markdown b/README.markdown
index 2cb0205..4f63cec 100644
--- a/README.markdown
+++ b/README.markdown
@@ -4,11 +4,6 @@ spsh: the shitposting shell
An experimental Bourne-style shell for me to learn moar C. Don't actually use
this for any serious reason.
-You need to fully-qualify the programs and arguments you call at the moment,
-like:
-
- spsh$ /bin/grep pattern /home/user/file
-
Author
: Tom Ryder <tom@sanctum.geek.nz>
Copyright
@@ -35,7 +30,6 @@ Not working but planned
In rough order of priority:
* At least a few simple builtins, like "cd" and "exit"
-* $PATH so you don't have to fully qualify all your programs
* Prompt with username and current directory
* Environment variables
* Quoting/escaping arguments (i.e. something better than just strtok())
diff --git a/cmd.c b/cmd.c
index b428d58..7e73a05 100644
--- a/cmd.c
+++ b/cmd.c
@@ -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;
}