Re: [PATCH] Reset exit status before sourcing a file.

2011-03-10 Thread Herbert Xu
On Wed, Mar 02, 2011 at 08:42:34PM +, Jonathan Nieder wrote:
> 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)?

Patch applied.  Thanks a lot!

Of course this does rely on evaltree actually setting exitstatus,
which it doesn't always do due to oversights.

For example, evalpipe doesn't set exitstatus if the pipeline
is backgrounded.  Amusingly pdksh seems to share this bug.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Reset exit status before sourcing a file.

2011-03-02 Thread Jonathan Nieder
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 
---
 src/main.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c
index b4c07e9..b38dc27 100644
--- a/src/main.c
+++ b/src/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;
 }
 
 
@@ -318,7 +320,6 @@ int
 dotcmd(int argc, char **argv)
 {
int status = 0;
-   exitstatus = 0;
 
if (argc >= 2) {/* That's what SVR2 does */
char *fullname;
@@ -326,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;
 }
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html