GNU bug report logs - #21065
Small bug in touch

Previous Next

Package: coreutils;

Reported by: Rickard Norlander <rickardnorlander <at> gmail.com>

Date: Wed, 15 Jul 2015 15:03:01 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21065 in the body.
You can then email your comments to 21065 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#21065; Package coreutils. (Wed, 15 Jul 2015 15:03:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Rickard Norlander <rickardnorlander <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Wed, 15 Jul 2015 15:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rickard Norlander <rickardnorlander <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: Small bug in touch
Date: Wed, 15 Jul 2015 15:25:02 +0200
[Message part 1 (text/plain, inline)]
touch version 8.23

Command:
$ touch -- '-'
Happens:
Returns successfully, but no file is created (if file exists, timestamp is
not updated)

Rickard
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#21065; Package coreutils. (Wed, 15 Jul 2015 15:17:02 GMT) Full text and rfc822 format available.

Message #8 received at 21065 <at> debbugs.gnu.org (full text, mbox):

From: Rickard Norlander <rickardnorlander <at> gmail.com>
To: 21065 <at> debbugs.gnu.org
Subject: Re:bug#21065: Small bug in touch
Date: Wed, 15 Jul 2015 17:16:03 +0200
[Message part 1 (text/plain, inline)]
On second thought this may be the expected behaviour, but I am not
completely sure. Sorry if I wasted your time.

Rickard
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#21065; Package coreutils. (Wed, 15 Jul 2015 15:21:01 GMT) Full text and rfc822 format available.

Message #11 received at 21065 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Rickard Norlander <rickardnorlander <at> gmail.com>, 
 21065 <at> debbugs.gnu.org
Subject: Re: bug#21065: Small bug in touch
Date: Wed, 15 Jul 2015 16:20:36 +0100
On 15/07/15 14:25, Rickard Norlander wrote:
> touch version 8.23
> 
> Command:
> $ touch -- '-'
> Happens:
> Returns successfully, but no file is created (if file exists, timestamp is not updated)

That is inconsistent with other platforms, though is documented
at the top of the man page, and done on purpose since v5.90 with:
http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=e3513e1




Information forwarded to bug-coreutils <at> gnu.org:
bug#21065; Package coreutils. (Wed, 15 Jul 2015 15:51:02 GMT) Full text and rfc822 format available.

Message #14 received at 21065 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Pádraig Brady <P <at> draigBrady.com>, 
 Rickard Norlander <rickardnorlander <at> gmail.com>, 21065 <at> debbugs.gnu.org
Subject: Re: bug#21065: Small bug in touch
Date: Wed, 15 Jul 2015 08:50:26 -0700
Pádraig Brady wrote:
> done on purpose since v5.90 with:
> http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=e3513e1

Yes, the intent was that there be a way from the shell to touch a file even when 
one has only its file descriptor.  Although POSIX does not specify the behavior 
of 'touch -' so portable scripts can't rely on it, users of GNU 'touch' can use 
it regardless of the underlying platform.




Added tag(s) notabug. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Wed, 15 Jul 2015 16:37:01 GMT) Full text and rfc822 format available.

Reply sent to Eric Blake <eblake <at> redhat.com>:
You have taken responsibility. (Wed, 15 Jul 2015 16:37:02 GMT) Full text and rfc822 format available.

Notification sent to Rickard Norlander <rickardnorlander <at> gmail.com>:
bug acknowledged by developer. (Wed, 15 Jul 2015 16:37:02 GMT) Full text and rfc822 format available.

Message #21 received at 21065-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Rickard Norlander <rickardnorlander <at> gmail.com>, 21065-done <at> debbugs.gnu.org
Subject: Re: bug#21065: Small bug in touch
Date: Wed, 15 Jul 2015 09:40:08 -0600
[Message part 1 (text/plain, inline)]
On 07/15/2015 09:31 AM, Eric Blake wrote:
> tag 21065 notabug
> thanks
> 
> On 07/15/2015 07:25 AM, Rickard Norlander wrote:
>> touch version 8.23
>>
>> Command:
>> $ touch -- '-'
>> Happens:
>> Returns successfully, but no file is created (if file exists, timestamp is
>> not updated)
> 
> Like many other tools, '-' is special-cased in touch to mean operation
> on stdin:

Looks like I'm not careful in what I wrote; most utilities treat '-' as
stdin, but touch documented...

> 
> $ touch --help | grep -A1 ' - '
> A FILE argument string of - is handled specially and causes touch to
> change the times of the file associated with standard output.

...that it was affecting stdout.

> 
> So you successfully touched stdin (in your case, /dev/tty).

Either way, in your example, since you were using an interactive shell,
/dev/tty was still touched,

>  If you want
> to create a file named '-', use 'touch ./-'.

and this advice still holds.

On a related note, the just-released 8.24 fixed 'tee -' to NOT treat '-'
as meaning stdout (which was a violation of POSIX) and to instead treat
it as a literal file.

Here's what POSIX says:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

Guideline 13:
    For utilities that use operands to represent files to be opened for
either reading or writing, the '-' operand should be used to mean only
standard input (or standard output when it is clear from context that an
output file is being specified) or a file named -.

It's not obvious whether 'touch' is opening a file for reading or
writing (it doesn't always have to open a file, after all, but if it
creates the file it IS opening it even if it doesn't read or write to
the file).

We changed 'touch -' way back in 5.90, in 2005, when making a bunch of
POSIX cleanups, so I guess the argument at the time probably still holds
that we are not in violation of that guideline by treating '-' as
stdout, even though POSIX does not explicitly describe that behavior in:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#21065; Package coreutils. (Wed, 15 Jul 2015 16:37:03 GMT) Full text and rfc822 format available.

Message #24 received at 21065-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Rickard Norlander <rickardnorlander <at> gmail.com>, 21065-done <at> debbugs.gnu.org
Subject: Re: bug#21065: Small bug in touch
Date: Wed, 15 Jul 2015 09:31:05 -0600
[Message part 1 (text/plain, inline)]
tag 21065 notabug
thanks

On 07/15/2015 07:25 AM, Rickard Norlander wrote:
> touch version 8.23
> 
> Command:
> $ touch -- '-'
> Happens:
> Returns successfully, but no file is created (if file exists, timestamp is
> not updated)

Like many other tools, '-' is special-cased in touch to mean operation
on stdin:

$ touch --help | grep -A1 ' - '
A FILE argument string of - is handled specially and causes touch to
change the times of the file associated with standard output.

So you successfully touched stdin (in your case, /dev/tty).  If you want
to create a file named '-', use 'touch ./-'.

See also this FAQ:
https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#How-do-I-remove-files-that-start-with-a-dash_003f

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#21065; Package coreutils. (Wed, 15 Jul 2015 16:37:03 GMT) Full text and rfc822 format available.

Message #27 received at 21065-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: 21065-done <at> debbugs.gnu.org
Subject: Re: bug#21065: Small bug in touch
Date: Wed, 15 Jul 2015 10:36:56 -0600
[resending without a signature - I didn't see my reply land at
http://debbugs.gnu.org/21065, so I wonder if the list filters are
accidentally eating GPG-signed mail again]

On 07/15/2015 09:31 AM, Eric Blake wrote:
> tag 21065 notabug
> thanks
> 
> On 07/15/2015 07:25 AM, Rickard Norlander wrote:
>> touch version 8.23
>>
>> Command:
>> $ touch -- '-'
>> Happens:
>> Returns successfully, but no file is created (if file exists, timestamp is
>> not updated)
> 
> Like many other tools, '-' is special-cased in touch to mean operation
> on stdin:

Looks like I'm not careful in what I wrote; most utilities treat '-' as
stdin, but touch documented...

> 
> $ touch --help | grep -A1 ' - '
> A FILE argument string of - is handled specially and causes touch to
> change the times of the file associated with standard output.

...that it was affecting stdout.

> 
> So you successfully touched stdin (in your case, /dev/tty).

Either way, in your example, since you were using an interactive shell,
/dev/tty was still touched,

>  If you want
> to create a file named '-', use 'touch ./-'.

and this advice still holds.

On a related note, the just-released 8.24 fixed 'tee -' to NOT treat '-'
as meaning stdout (which was a violation of POSIX) and to instead treat
it as a literal file.

Here's what POSIX says:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

Guideline 13:
    For utilities that use operands to represent files to be opened for
either reading or writing, the '-' operand should be used to mean only
standard input (or standard output when it is clear from context that an
output file is being specified) or a file named -.

It's not obvious whether 'touch' is opening a file for reading or
writing (it doesn't always have to open a file, after all, but if it
creates the file it IS opening it even if it doesn't read or write to
the file).

We changed 'touch -' way back in 5.90, in 2005, when making a bunch of
POSIX cleanups, so I guess the argument at the time probably still holds
that we are not in violation of that guideline by treating '-' as
stdout, even though POSIX does not explicitly describe that behavior in:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org






Information forwarded to bug-coreutils <at> gnu.org:
bug#21065; Package coreutils. (Wed, 15 Jul 2015 16:46:02 GMT) Full text and rfc822 format available.

Message #30 received at 21065-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: 21065-done <at> debbugs.gnu.org
Subject: Re: bug#21065: Small bug in touch
Date: Wed, 15 Jul 2015 10:45:21 -0600
[Message part 1 (text/plain, inline)]
On 07/15/2015 10:36 AM, Eric Blake wrote:
> [resending without a signature - I didn't see my reply land at
> http://debbugs.gnu.org/21065, so I wonder if the list filters are
> accidentally eating GPG-signed mail again]

Maybe I should have been more patient. Just after sending, I got all my
messages, and now see them on the web page; on the other hand, the web
page shows mails out of order:
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21065#21 was sent later
than  http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21065#24

No idea where the delays are occurring, or if it is worth worrying
about, or even if sending a message without a signature forced a flush
of some pending queue.

> Here's what POSIX says:
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
> 
> Guideline 13:
>     For utilities that use operands to represent files to be opened for
> either reading or writing, the '-' operand should be used to mean only
> standard input (or standard output when it is clear from context that an
> output file is being specified) or a file named -.

But to add one more piece of information, POSIX also says:

Where a utility described in the Shell and Utilities volume of
POSIX.1-2008 as conforming to these guidelines is required to accept, or
not to accept, the operand '-' to mean standard input or output, this
usage is explained in the OPERANDS section. Otherwise, if such a utility
uses operands to represent files, it is implementation-defined whether
the operand '-' stands for standard input (or standard output), or for a
file named -.

and our change to 'tee' for 8.24 is correct, because 'tee' explicitly
documented that '-' shall not mean stdout; whereas for 'touch', POSIX is
silent (and it is therefore implementation-defined) about behavior of
'touch -'.


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#21065; Package coreutils. (Thu, 16 Jul 2015 12:31:01 GMT) Full text and rfc822 format available.

Message #33 received at 21065 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Vinh Nguyen <vnguyen <at> opswat.com>
Cc: 21065 <at> debbugs.gnu.org, Dave Patt <dpatt <at> opswat.com>
Subject: Re: bug#21056: [BUG] Bug with dirname on Ubuntu
Date: Thu, 16 Jul 2015 06:30:42 -0600
[Message part 1 (text/plain, inline)]
[adding the list back in, with permission]

On 07/14/2015 07:47 PM, Vinh Nguyen wrote:
> Dear Eric,
> Thank you for your useful information about dirname function. But the main thing I wanted to report is not the way to use dirname, but the weird behavior of dirname loading library named "." into the running process and cause error "Error while mapping shared library sections. '.' is not in executable format: Is a directory" and segmentation fault subsequently. The document says nothing about this behavior so it is a bug. Also, Dl_info's dli_fname is a char array, not const char* so the cast in "dirname((char*)info.dli_fname)" just do nothing.
> I'm looking forward to hearing from you soon.

Your problem stems from the fact that calling dirname() modifies its
argument.

>>         Dl_info info;
>>         if ( dladdr( ( const void* )function_to_get_address, &info ) == 0 )
>>             return false;
>>         if ( info.dli_fname == NULL )
>>             return false;
>>         dirname((char*)info.dli_fname); (1)

Whatever info.dli_fname was prior to dirname, it was modified in place
to now be "." after the invalid call.  So now that it has a changed
value, it is messing with all the assumptions of the rest of dl*() that
assume the name will not be changed.

I stand by my assertion that the bug is in your invalid use of dirname().

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 14 Aug 2015 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 265 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.