From 9934eda9775d6b182389f24df8a38d68b93ba032 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 15 Apr 2016 10:02:58 +1200 Subject: Use execvp(3) to implement PATH search --- README.markdown | 6 ------ cmd.c | 22 ++++++---------------- 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 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; } -- cgit v1.2.3