chdir() back to old working directory is pointless and can fail

Bug #520763 reported by Andrew Pollock
50
This bug affects 10 people
Affects Status Importance Assigned to Milestone
apt (Debian)
New
Unknown
apt (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

Binary package hint: apt

It seems that the behaviour of "apt-get update" in Lucid includes a chdir() to /var/lib/apt/lists/ to do something, and then a chdir() back to what getcwd() returned prior to the chdir().

This chdir()ing back to the original working directory is pointless. The process is going to exit, and the working directory will be that of the parent process.

It can also fail, causing the "apt-get update" to exit 100 needlessly, in a Kerberised NFS environment where root cannot access the working directory that apt-get was in when it was invoked under sudo.

e.g.

I'm in /home/apollock

I invoke "sudo apt-get update"

It does its chdir()ing to /var/lib/apt/lists
It tries to chdir() back to /home/apollock
It gets an EACCES from this chdir() and decides to throw its hands up and return 100.

Here's a snippet from running it under strace:

open("/var/lib/apt/lists/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5
getcwd("/home/apollock/REDACTED", 298) = 59
chdir("/var/lib/apt/lists/") = 0
getdents(5, /* 94 entries */, 32768) = 8656
getdents(5, /* 0 entries */, 32768) = 0
close(5) = 0
chdir("/home/apollock/REDACTED") = -1 EACCES (Permission denied)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
brk(0x145a000) = 0x145a000
open("/var/lib/dpkg/lock", O_RDWR|O_CREAT|O_NOFOLLOW, 0640) = 5
fcntl(5, F_SETFD, FD_CLOEXEC) = 0
fcntl(5, F_SETLK, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0}) = 0
open("/var/lib/dpkg/updates/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 6
getdents(6, /* 2 entries */, 32768) = 48
getdents(6, /* 0 entries */, 32768) = 0
close(6) = 0
close(5) = 0
close(4) = 0
write(2, "E: ", 3) = 3
write(2, "Unable to change to /home/apollo"..., 111) = 111
write(2, "\n", 1) = 1
close(3) = 0
exit_group(100) = ?

Tags: glucid
tags: added: glucid
Changed in apt (Debian):
status: Unknown → New
Revision history for this message
Torsten Spindler (tspindler) wrote :

I was not able to reproduce the problem:

root@spitfire:/home/spindler# strace -f apt-get update > /tmp/apt-get-update 2>&1
root@spitfire:/home/spindler# vi /tmp/apt-get-update
root@spitfire:/home/spindler# grep chdir /tmp/apt-get-update

Can you still reproduce it? I tried with apt 0.7.25.3ubuntu9.4 on Ubuntu 10.04 LTS.

Changed in apt (Ubuntu):
status: New → Incomplete
Revision history for this message
Andrew Pollock (apollock) wrote :

I can confirm that I can no longer reproduce the problem with apt 0.7.25.3ubuntu9.3

Changed in apt (Ubuntu):
status: Incomplete → Invalid
Revision history for this message
AggieBill (aggiebill) wrote :

I get this error, and I'm using Ubuntu 13.04.

Revision history for this message
John Edwards (john-edwards) wrote :

I get this error, I am also using Ubuntu 13.04. My home directory is NFS mounted and secured with Kerberos preventing the local root account from gaining access.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.