File: 0001-EVAL-Make-eval-with-empty-arguments-return-0.diff

package info (click to toggle)
dash 0.5.3-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,160 kB
  • ctags: 1,289
  • sloc: ansic: 12,660; sh: 1,068; makefile: 155; yacc: 105
file content (149 lines) | stat: -rw-r--r-- 3,638 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
From e5f903b9451c6e6a79eee939fcf6558a0b93cf8e Mon Sep 17 00:00:00 2001
From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Thu, 12 Jan 2006 21:02:26 +1100
Subject: [PATCH] [EVAL] Make eval with empty arguments return 0

On Tue, Jan 10, 2006 at 10:56:23AM +0000, Gerrit Pape wrote:
> tags 347232 + patch
> quit
>
> On Mon, Jan 09, 2006 at 04:29:19PM +0100, Marco Nenciarini wrote:
> > The problem is here:
> >
> > # Set the kernel 2.6 option only for fresh install
> > test -z "$(GetMenuOpt "kopt" "")" && kopt_2_6="root=$root_device_2_6 ro"
> >
> > # Extract options for specific kernels
> > eval $(ExtractMenuOpts "\(kopt_[a-zA-Z0-9_]\+\)")
> >
> > If the first test fails and the eval argument is empty then dash
> > terminate with exitcode 1.
>
> > This is a simple testcase:
> > tm:~# bash -c "set -e ;/bin/false && : ; eval ''; echo 'END'"; echo $?
> > END
> > 0
> > tm:~# dash -c "set -e ;/bin/false && : ; eval ''; echo 'END'"; echo $?
> > 1
> >
> > if you insert any command with successfull exit status before the
> > empty eval, all work ok:
> > tm:~# bash -c "set -e ;/bin/false && : ; : ; eval ''; echo 'END'"; echo $?
> > END
> > 0
> > tm:~# dash -c "set -e ;/bin/false && : ; : ; eval ''; echo 'END'"; echo $?
> > END
> > 0
>
> Yes, I can confirm this is a bug in dash.  The standard says
>
>  EXIT STATUS
>
>      If there are no arguments, or only null arguments, eval shall
>      return a zero exit status; otherwise, it shall return the exit
>      status of the command defined by the string of concatenated
>      arguments separated by <space>s.
>
> Hi Herbert, please see http://bugs.debian.org/347232

Changed evalstring to return the exit status instead of evalskip.  This
allows us to return zero if the string is empty.
---
 ChangeLog  |    4 ++++
 src/eval.c |   18 ++++++++----------
 src/trap.c |    9 ++++-----
 3 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9f87e4e..02b966c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-01-12  Herbert Xu <herbert@gondor.apana.org.au>
+
+	* Fixed eval exit status with empty arguments.
+
 2005-11-26  Herbert Xu <herbert@gondor.apana.org.au>
 
 	* Release 0.5.3.
diff --git a/src/eval.c b/src/eval.c
index f8f6f0a..07e7ee2 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -150,10 +150,9 @@ evalcmd(int argc, char **argv)
                         STPUTC('\0', concat);
                         p = grabstackstr(concat);
                 }
-                evalstring(p, ~SKIPEVAL);
-                
+                return evalstring(p, ~SKIPEVAL);
         }
-        return exitstatus;
+        return 0;
 }
 
 
@@ -166,24 +165,23 @@ evalstring(char *s, int mask)
 {
 	union node *n;
 	struct stackmark smark;
-	int skip;
+	int status;
 
 	setinputstring(s);
 	setstackmark(&smark);
 
-	skip = 0;
+	status = 0;
 	while ((n = parsecmd(0)) != NEOF) {
 		evaltree(n, 0);
+		status = exitstatus;
 		popstackmark(&smark);
-		skip = evalskip;
-		if (skip)
+		if (evalskip)
 			break;
 	}
 	popfile();
 
-	skip &= mask;
-	evalskip = skip;
-	return skip;
+	evalskip &= mask;
+	return status;
 }
 
 
diff --git a/src/trap.c b/src/trap.c
index bbff81a..eae6186 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -295,7 +295,6 @@ dotrap(void)
 	char *q;
 	int i;
 	int savestatus;
-	int skip = 0;
 
 	savestatus = exitstatus;
 	pendingsigs = 0;
@@ -309,13 +308,13 @@ dotrap(void)
 		p = trap[i + 1];
 		if (!p)
 			continue;
-		skip = evalstring(p, SKIPEVAL);
+		evalstring(p, SKIPEVAL);
 		exitstatus = savestatus;
-		if (skip)
-			break;
+		if (evalskip)
+			return evalskip;
 	}
 
-	return skip;
+	return 0;
 }
 
 
-- 
1.4.3.1