Peter Jakobi | 7 Aug 2009 15:18
Picon
Favicon

Feature request: set -o pipefail

Hi,

[Note:  I'm not on the list, so put jakobi <at> acm.org in cc: if I need to
reply. thanx, Peter]

Feature request:

implement  set  -o pipefail. This will allow the user to  request  the
return  code  to be the one of the first pipe command with a  non-zero
error. 

The  lack  of  which  can be quite painful in  scripting,  even  if  a
bourne-shell/posix subset would otherwise be quite sufficient.

Advantages:

This  allows use of pipes with proper error detection, which is  quite
helpful  for  init  scripts / cron or  generally  administration-style
scripts which exec shell commands from shell/perl/python/... scripts.

Usage case: 

have  a  command  like mv -i act on user input, while  keeping  output
(stdout+err) in a log AND returning mv's error code (or tee's if mv is
ok). in a perl script, this would be something like:

   system "set -o pipefail; mv -i foo bar </dev/tty 2>&1 | tee -a LOG";

Part  of  the problem is that the shell used for open/system is  often
hard-coded in the interpreter to be /bin/sh.
(Continue reading)

Herbert Xu | 11 Aug 2009 04:45
Picon
Picon

Bug#429251: Debian Bug#429251: [PATCH] honor tab as IFS whitespace when splitting fields

I really loved your patch because it actually made dash smaller!

On Sun, Jul 05, 2009 at 12:45:49AM +0200, Stefan Potyra wrote:
>
> +static void
> +readcmd_handle_line(char *line, char **ap, size_t len)
> +{
> +	struct arglist arglist;
> +	struct strlist *sl;
> +	char *s, *backup;
> +
> +	/* ifsbreakup will fiddle with stack region... */
> +	s = grabstackstr(line + len);
> +	/* need a copy, so that delimiters aren't lost
> +	 * in case there are more fields than variables */
> +	if (len > 0) {
> +		backup = sstrdup(line);
> +	} else {
> +		/* len==0, so just nullify all arguments...
> +		 * otherwise memcpy (from sstrdup) would be called 
> +		 * with equal memory regions.
> +		 */

I think this is unnecessary.  See my revised patch below.  When
given the choice between a speed optimisation of an unusual case
and a smaller dash, the latter always wins :)

> +			ungrabstackstr(backup, 0);
> +			ungrabstackstr(s, 0);

(Continue reading)

Herbert Xu | 11 Aug 2009 06:01
Picon
Picon

Re: [PATCH] [BUILD] Avoid compiler warning

On Thu, Jul 09, 2009 at 06:52:15AM -0600, Eric Blake wrote:
> Pass correct type to ctype macro.
> 
> Signed-off-by: Eric Blake <ebb9 <at> byu.net>

Hmm, what warning did you get from the compiler?

Thanks,
--

-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert <at> gondor.apana.org.au>
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 majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Herbert Xu | 11 Aug 2009 06:03
Picon
Picon

Re: avoid compiler warning

On Thu, Jul 09, 2009 at 12:55:25PM +0000, Eric Blake wrote:
> ccache gcc -DHAVE_CONFIG_H -I. -I..  -include ../config.h -DBSD=1 -DSHELL
> -DIFS_BROKEN  -Wall -gdwarf-2 -Wall -Werror -MT mystring.o -MD -MP -MF
> .deps/mystring.Tpo -c -o mystring.o mystring.c
> miscbltin.c: In function `umaskcmd':
> miscbltin.c:201: warning: subscript has type `char'
> 
> isdigit is only defined over EOF and unsigned char values, so without this
> patch, you can trigger undefined behavior.

What compiler and what libc was this? isdigit is supposed to
be a function that takes an int argument according to POSIX.
If libc implements it as a macro then it's up to it to cast
the parameter to (int).

So I think you should fix this in your libc instead.

Thanks,
--

-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert <at> gondor.apana.org.au>
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 majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

H. Peter Anvin | 11 Aug 2009 18:33
Favicon

Re: avoid compiler warning

On 08/10/2009 09:03 PM, Herbert Xu wrote:
> On Thu, Jul 09, 2009 at 12:55:25PM +0000, Eric Blake wrote:
>> ccache gcc -DHAVE_CONFIG_H -I. -I..  -include ../config.h -DBSD=1 -DSHELL
>> -DIFS_BROKEN  -Wall -gdwarf-2 -Wall -Werror -MT mystring.o -MD -MP -MF
>> .deps/mystring.Tpo -c -o mystring.o mystring.c
>> miscbltin.c: In function `umaskcmd':
>> miscbltin.c:201: warning: subscript has type `char'
>>
>> isdigit is only defined over EOF and unsigned char values, so without this
>> patch, you can trigger undefined behavior.
> 
> What compiler and what libc was this? isdigit is supposed to
> be a function that takes an int argument according to POSIX.
> If libc implements it as a macro then it's up to it to cast
> the parameter to (int).
> 
> So I think you should fix this in your libc instead.
> 

Herbert... the *type* is int, but the *value* has to be in the range
[-1,UCHAR_MAX] or the behavior is undefined in both the C and POSIX
standards.

	-hpa

--

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.

--
(Continue reading)

Herbert Xu | 11 Aug 2009 23:56
Picon
Picon

Re: avoid compiler warning

On Tue, Aug 11, 2009 at 09:33:43AM -0700, H. Peter Anvin wrote:
> 
> Herbert... the *type* is int, but the *value* has to be in the range
> [-1,UCHAR_MAX] or the behavior is undefined in both the C and POSIX
> standards.

Good point.  I'll apply the patch.  I'd be very surprised though
if this was the only instance in which we pass a char along.

Cheers,
--

-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert <at> gondor.apana.org.au>
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 majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

H. Peter Anvin | 12 Aug 2009 00:06
Favicon

Re: avoid compiler warning

On 08/11/2009 02:56 PM, Herbert Xu wrote:
> On Tue, Aug 11, 2009 at 09:33:43AM -0700, H. Peter Anvin wrote:
>> Herbert... the *type* is int, but the *value* has to be in the range
>> [-1,UCHAR_MAX] or the behavior is undefined in both the C and POSIX
>> standards.
> 
> Good point.  I'll apply the patch.  I'd be very surprised though
> if this was the only instance in which we pass a char along.
> 

Personally I have a habit of wrapping most ctype things in macros or
inlines which cast the argument to (unsigned char), then it's up to me
to make sure EOF doesn't slink in.

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

Eric Blake | 12 Aug 2009 05:19
Gravatar

Re: avoid compiler warning

According to Herbert Xu on 8/11/2009 3:56 PM:
> On Tue, Aug 11, 2009 at 09:33:43AM -0700, H. Peter Anvin wrote:
>> Herbert... the *type* is int, but the *value* has to be in the range
>> [-1,UCHAR_MAX] or the behavior is undefined in both the C and POSIX
>> standards.
> 
> Good point.  I'll apply the patch.  I'd be very surprised though
> if this was the only instance in which we pass a char along.

I would be surprised, too, but this was the only instance that triggered a
-Wall warning from gcc for my libc (more details in another mail, as
requested), so all other use of ctype is either through unsigned char or
int, rather than straight char.

--

-- 
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 <at> byu.net
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Eric Blake | 12 Aug 2009 05:20
Gravatar

Re: [PATCH] [BUILD] Avoid compiler warning

According to Herbert Xu on 8/10/2009 10:01 PM:
> On Thu, Jul 09, 2009 at 06:52:15AM -0600, Eric Blake wrote:
>> Pass correct type to ctype macro.
>>
>> Signed-off-by: Eric Blake <ebb9 <at> byu.net>
> 
> Hmm, what warning did you get from the compiler?

As reported in my original patch submission:

miscbltin.c: In function `umaskcmd':
miscbltin.c:201: warning: subscript has type `char'

--

-- 
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 <at> byu.net
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Eric Blake | 12 Aug 2009 05:32
Gravatar

Re: avoid compiler warning

According to H. Peter Anvin on 8/11/2009 10:33 AM:
> Herbert... the *type* is int, but the *value* has to be in the range
> [-1,UCHAR_MAX] or the behavior is undefined in both the C and POSIX
> standards.

Actually, the *value* has to be either EOF (which is negative, but not
necessarily required to be -1) or [0,UCHAR_MAX].  But you are correct that
for most (all?) platforms, EOF is -1 even though it is not mandated as such.

--

-- 
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 <at> byu.net
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Gmane