Bug 688567

Summary: option -C (change directory) does not work in combination with -u (update archive)
Product: Red Hat Enterprise Linux 6 Reporter: Nicolas Mitsis <mitsis>
Component: tarAssignee: Pavel Raiskup <praiskup>
Status: CLOSED ERRATA QA Contact: Branislav Blaškovič <bblaskov>
Severity: low Docs Contact:
Priority: low    
Version: 6.0CC: azelinka, bblaskov, ovasik
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: tar-1.23-5.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 13:49:21 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
strace log from tar -C / -upvf ... none

Description Nicolas Mitsis 2011-03-17 11:37:20 UTC
Description of problem:

option -C (change directory) does not work in combination with -u (update archive)

Version-Release number of selected component (if applicable):

tar-1.23-3.el6.x86_64

How reproducible:

always

Steps to Reproduce:
1. create archive
2. update archive with options -C and -u
3. update fails
  
Actual results:

update fails

Expected results:

update to succeed

Additional info:

example follows:

[root@void ~]# ls -l /a/
total 0
-rw-r--r--. 1 root root 0 Mar 17 13:07 1
-rw-r--r--. 1 root root 0 Mar 17 13:07 2
[root@void ~]# tar -C / -cpvf a.tar a
a/
a/1
a/2
[root@void ~]# echo $RANDOM > /a/1
[root@void ~]# touch /a/3 
[root@void ~]# tar -C / -upvf a.tar a
tar: a/1: Cannot stat: No such file or directory
tar: a/3: Cannot stat: No such file or directory
tar: a/2: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
[root@void ~]# tar tvf a.tar 
drwxr-xr-x root/root         0 2011-03-17 13:07 a/
-rw-r--r-- root/root         0 2011-03-17 13:07 a/1
-rw-r--r-- root/root         0 2011-03-17 13:07 a/2

From strace it seems fchdir() is called for 2nd time with wrong arguments:

...................................................
open(".", O_RDONLY)                     = 4
dup(4)                                  = 5
close(5)                                = 0
chdir("/")                              = 0
lstat("a", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("a", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5
fcntl(5, F_GETFD)                       = 0x1 (flags FD_CLOEXEC)
getdents(5, /* 6 entries */, 32768)     = 144
getdents(5, /* 0 entries */, 32768)     = 0
close(5)                                = 0
open(".", O_RDONLY)                     = 5
dup(5)                                  = 6
close(6)                                = 0
fchdir(4)                               = 0
....................................................

Comment 2 RHEL Program Management 2011-03-17 12:07:52 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unfortunately unable to
address this request at this time. Red Hat invites you to
ask your support representative to propose this request, if
appropriate and relevant, in the next release of Red Hat
Enterprise Linux. If you would like it considered as an
exception in the current release, please ask your support
representative.

Comment 3 Ondrej Vasik 2011-03-31 14:36:07 UTC
Works for me on ext4 and tar-1.23-3.el6.i686 ...

[root@dhcp-24-196 tmp]# ls -l /a/
total 0
-rw-r--r--. 1 root root 0 Mar 31 16:32 1
-rw-r--r--. 1 root root 0 Mar 31 16:30 2
[root@dhcp-24-196 tmp]# tar -C / -cpvf a.tar a
a/
a/2
a/1
[root@dhcp-24-196 tmp]# echo $RANDOM > /a/1
[root@dhcp-24-196 tmp]# touch /a/3
[root@dhcp-24-196 tmp]# tar -C / -upvf a.tar a
a/3
[root@dhcp-24-196 tmp]# tar tvf a.tar
drwxr-xr-x root/root         0 2011-03-31 16:32 a/
-rw-r--r-- root/root         0 2011-03-31 16:30 a/2
-rw-r--r-- root/root         0 2011-03-31 16:32 a/1
-rw-r--r-- root/root         0 2011-03-31 16:30 a/3

Maybe something specific on your side?

Comment 4 Nicolas Mitsis 2011-04-01 15:36:47 UTC
Created attachment 489424 [details]
strace log from tar -C / -upvf ...

Comment 5 Nicolas Mitsis 2011-04-01 15:40:39 UTC
I've tried this in 2 different production systems and 1 clean vmware installation all on 64bit. Maybe the bug is absent from 32 ?

This is the version I've tried:

# tar --version
tar (GNU tar) 1.23

# rpm -q tar
tar-1.23-3.el6.x86_64

I've added also an strace log which shows fchdir() is called twice.

Comment 6 Ondrej Vasik 2011-04-01 16:28:04 UTC
Maybe, I'll check 64bit next week ... thanks for strace...

Comment 7 Ondrej Vasik 2011-06-06 12:31:56 UTC
Sorry for delay, behaviour confirmed on 64-bit RHEL-6 ... strange.

Comment 8 Ondrej Vasik 2011-06-06 13:04:50 UTC
Well, not exactly true, it seems to be reproducible even on 32 bit (but not always) ...
Failed stats:
x86_64:
lstat("a/2", 0x7fff0dcc68b0)            = -1 ENOENT (No such file or directory)
lstat("a/1", 0x7fff0dcc68b0)            = -1 ENOENT (No such file or directory)
lstat("a/3", 0x7fff0dcc6748)            = -1 ENOENT (No such file or directory)
i386:
lstat64("a/2", {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
lstat64("a/1", {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
lstat64("a/4", 0xbf939b44)              = -1 ENOENT (No such file or directory)

Will try to find out what's broken there ...

Comment 11 RHEL Program Management 2011-07-06 00:07:04 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unfortunately unable to
address this request at this time. Red Hat invites you to
ask your support representative to propose this request, if
appropriate and relevant, in the next release of Red Hat
Enterprise Linux. If you would like it considered as an
exception in the current release, please ask your support
representative.

Comment 13 Pavel Raiskup 2012-02-23 10:20:34 UTC
Fix proposed to upstream:

    http://www.mail-archive.com/bug-tar@gnu.org/msg03545.html

Comment 21 errata-xmlrpc 2012-06-20 13:49:21 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2012-0849.html

Comment 22 Pavel Raiskup 2017-12-18 10:52:04 UTC
In the end fixed through:
http://lists.gnu.org/archive/html/bug-tar/2016-09/msg00024.html