commit d495beb5ae5037e0dec0a76da3718bb7ab300fe8
parent e67426d96dee92fe6f2b46a67cd64c0b3b3a2d9f
Author: Sebastian <sebastian@sebsite.pw>
Date: Thu, 21 Apr 2022 15:53:31 -0400
exec: proper error handling in lookup
lookup will continue searching if open returns noaccess or noentry, but
in all other cases it will propagate the error.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/os/exec/cmd.ha b/os/exec/cmd.ha
@@ -33,7 +33,7 @@ export fn cmd(name: str, args: str...) (command | error) = {
return nocmd;
};
} else {
- yield match (lookup(name)) {
+ yield match (lookup(name)?) {
case void =>
return nocmd;
case let p: platform_cmd =>
@@ -165,7 +165,7 @@ export fn nullstd(cmd: *command) void = {
addfile(cmd, os::stderr, nullfd);
};
-fn lookup(name: str) (platform_cmd | void) = {
+fn lookup(name: str) (platform_cmd | void | error) = {
const path = match (os::getenv("PATH")) {
case void =>
return;
@@ -183,8 +183,10 @@ fn lookup(name: str) (platform_cmd | void) = {
let path = strings::concat(item, "/", name);
defer free(path);
match (open(path)) {
- case let err: error =>
+ case (errors::noaccess | errors::noentry) =>
continue;
+ case let err: error =>
+ return err;
case let p: platform_cmd =>
return p;
};