aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-03-10 21:23:11 +0800
committermaximilian attems <max@stro.at>2011-06-03 18:44:13 +0200
commit0213c2371a01554a56d6c2a6c5f8a5f5be9b3a9c (patch)
tree34478466a06f7a2928541ce241a4cc8683f621fd
parente79a89772db804b4800a896e79c2300f1d4f735c (diff)
downloadklibc-0213c2371a01554a56d6c2a6c5f8a5f5be9b3a9c.tar.gz
[klibc] [BUILTIN] Dotcmd should exit with zero when doing nothing
Tim Allen wrote: > The POSIX specification for the dot command[1] states: > > EXIT STATUS > Returns the value of the last command executed, or a zero exit > status if no command is executed. > > If an empty file is sourced, then "no command is executed" I agree. Looking through "git log --patch src/main.c", though, I find v0.5.3~42 (Do not clobber exit status in dotcmd., 2005-03-03), which appears to have been meant to take care of the following case: $ cat printstatus.sh echo $? $ false $ . ./printstatus.sh 1 I wonder if the following on top might help (imitating evalcmd)? Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/dash/main.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/usr/dash/main.c b/usr/dash/main.c
index 1735c672fd483..b38dc2759cd32 100644
--- a/usr/dash/main.c
+++ b/usr/dash/main.c
@@ -202,6 +202,7 @@ cmdloop(int top)
union node *n;
struct stackmark smark;
int inter;
+ int status = 0;
int numeof = 0;
TRACE(("cmdloop(%d) called\n", top));
@@ -235,6 +236,7 @@ cmdloop(int top)
job_warning = (job_warning == 2) ? 1 : 0;
numeof = 0;
evaltree(n, 0);
+ status = exitstatus;
}
popstackmark(&smark);
@@ -245,7 +247,7 @@ cmdloop(int top)
}
}
- return 0;
+ return status;
}
@@ -325,9 +327,8 @@ dotcmd(int argc, char **argv)
fullname = find_dot_file(argv[1]);
setinputfile(fullname, INPUT_PUSH_FILE);
commandname = fullname;
- cmdloop(0);
+ status = cmdloop(0);
popfile();
- status = exitstatus;
}
return status;
}