Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 430102 - sys-apps/portage: running emerge in a directory that will be deleted outputs lots of "getcwd: cannot access parent directories: No such file or directory"
Summary: sys-apps/portage: running emerge in a directory that will be deleted outputs ...
Status: CONFIRMED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Unclassified (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-05 23:01 UTC by Peter Stuge
Modified: 2022-10-20 02:43 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Stuge 2012-08-05 23:01:25 UTC
During various stages of emerge, portage outputs a bunch of errors if emerge was started in a directory which no longer exists. I just emerged gettext from a deleted directory and got:

...
>>> Completed installing gettext-0.18.1.1-r1 into /var/tmp/portage/sys-devel/gettext-0.18.1.1-r1/image/

Fixing .la files
   usr/lib64/libgettextlib.la
   usr/lib64/libgettextsrc.la
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
strip: x86_64-pc-linux-gnu-strip --strip-unneeded -R .comment -R .GCC.command.line
...
>>> Installing (1 of 1) sys-devel/gettext-0.18.1.1-r1
 * checking 216 files for package collisions
>>> Merging sys-devel/gettext-0.18.1.1-r1 to /
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
--- /usr/
--- /usr/bin/
>>> /usr/bin/msgen
...
>>> Safely unmerging already-installed instance...
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
No package files given... Grabbing a set.
...
<<<          dir /usr/share/doc/gettext-0.17
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
>>> Regenerating /etc/ld.so.cache...
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
>>> Original instance of package unmerged safely.
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
>>> sys-devel/gettext-0.18.1.1-r1 merged.
>>> Regenerating /etc/ld.so.cache...
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * Regenerating GNU info directory index...
 * Processed 97 info files.

Perhaps it would be a good idea to do a chdir('/') before anything else?
Comment 1 Fabian Groffen gentoo-dev 2012-08-06 06:38:02 UTC
maybe it makes more sense to just stat CWD/PWD when emerge starts, and error out if doesn't exist?
Comment 2 Peter Stuge 2012-08-06 10:46:23 UTC
(In reply to comment #1)
> maybe it makes more sense to just stat CWD/PWD when emerge starts, and error
> out if doesn't exist?

That seems like an artificial restriction. The emerge does work, so the directory isn't strictly needed.. / would be a safe bet that should exist on all systems. :)
Comment 3 Fabian Groffen gentoo-dev 2012-08-06 10:55:39 UTC
it's as artificial as always performing a chdir("/") imo
Comment 4 Peter Stuge 2012-08-06 11:23:43 UTC
(In reply to comment #3)
> it's as artificial as always performing a chdir("/") imo

With the slight difference that chdir() to a directory that is known to always exist allows to avoid any error and complete the user's command.
Comment 5 Fabian Groffen gentoo-dev 2012-08-06 11:28:35 UTC
I don't see why emerge/portage should be able to operate per se in a h0rkened environment.

fail early, instead of working around the issue and perhaps causing issues lateron
Comment 6 Peter Stuge 2012-08-06 12:58:23 UTC
(In reply to comment #5)
> I don't see why emerge/portage should be able to operate per se in a
> h0rkened environment.

Portage's environment often doesn't include the current working directory, which is of course why emerge does succeed even though $PWD is gone.


> fail early, instead of working around the issue and perhaps causing issues
> lateron

I agree, if the environment is so broken that emerge can not work. But that would be stuff like /usr/portage, /var/db, or /var/tmp gone missing, it doesn't seem that the random directory emerge was started from matters, which I think is very good and wise.

Maybe the next step would be to look at what exact operations cause the error messages. Since there doesn't seem to be a policy either way on whether $PWD must exist or not, maybe that's what this bug is really about.

I'm in favor of not depending on $PWD existing.
Comment 7 Zac Medico gentoo-dev 2012-08-06 15:42:37 UTC
We've already got the following code in /usr/lib/portage/pym/portage/__init__.py that's executed every time portage imported:

  	try:
		return os.getcwd()
	except OSError: #dir doesn't exist
		os.chdir("/")
		return "/"

So, it's already supposed to chdir("/") if the current cwd doesn't exist.

Maybe the problem is that os.getcwd() doesn't raise OSError when it's supposed to. It works for me.
Comment 8 Chí-Thanh Christopher Nguyễn gentoo-dev 2012-08-08 03:20:53 UTC
I think the issue is triggered when you start in a /var/tmp/portage subdirectory that is going to be removed during emerge run.
Comment 9 Zac Medico gentoo-dev 2012-08-08 07:48:06 UTC
(In reply to comment #8)
> I think the issue is triggered when you start in a /var/tmp/portage
> subdirectory that is going to be removed during emerge run.

I'd say it's the user's responsibility to choose a sane cwd before invoking emerge.
Comment 10 SpanKY gentoo-dev 2012-08-21 00:22:33 UTC
(In reply to comment #7)

yeah, i think it's "easy" to make the active dir disappear after the initial import.

related, i'm not sure putting this logic into the portage module is correct.  if you wanted to start off `emerge` with os.chdir("/"), that'd make sense to me (i can't see how it'd really be harmful), but emerge/etc... aren't the only packages that import portage, and i think it's a reasonable expectation that doing "import foo" in python shouldn't cause modification of the active environment (regardless of how "valid" it might be).
Comment 11 abandoned account 2015-02-08 10:55:12 UTC
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

had no idea the simple fix is: cd .
Comment 12 abandoned account 2015-02-08 11:05:12 UTC
by the way, running bash in a non-existent directory causes it to yell like that.

concrete example:

# cd /var/tmp/portage/dev-libs/gmp-6.0.0a/work/
hardeneduclibc1 work # pwd
/var/tmp/portage/dev-libs/gmp-6.0.0a/work
hardeneduclibc1 work # time emerge -av -u dev-libs/gmp

 * IMPORTANT: 8 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.


These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild     U  ] dev-libs/gmp-6.0.0a [5.1.3-r1] USE="cxx -doc -pgo -static-libs" 0 KiB

Total: 1 package (1 upgrade), Size of downloads: 0 KiB

Would you like to merge these packages? [Yes/No] 

>>> Verifying ebuild manifests

>>> Emerging (1 of 1) dev-libs/gmp-6.0.0a::gentoo
 * gmp-6.0.0a.tar.xz SHA256 SHA512 WHIRLPOOL size ;-) ...                [ ok ]
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
>>> Unpacking source...
>>> Unpacking gmp-6.0.0a.tar.xz to /var/tmp/portage/dev-libs/gmp-6.0.0a/work
>>> Source unpacked in /var/tmp/portage/dev-libs/gmp-6.0.0a/work
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
>>> Preparing source in /var/tmp/portage/dev-libs/gmp-6.0.0a/work/gmp-6.0.0 ...
 * Applying various patches (bugfixes/updates) ...
 *   ppc64-build.diff ...                                                [ ok ]
 * Done with patching
 * Running elibtoolize in: gmp-6.0.0/
 *   Applying portage/1.2.0 patch ...
 *   Applying sed/1.5.6 patch ...
 *   Applying as-needed/2.4.2 patch ...
 *   Applying target-nm/2.4.2 patch ...
>>> Source prepared.
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
>>> Configuring source in /var/tmp/portage/dev-libs/gmp-6.0.0a/work/gmp-6.0.0 ...
 * abi_x86_64.amd64: running multilib-minimal_abi_src_configure
 * econf: updating gmp-6.0.0/config.sub with /usr/share/gnuconfig/config.sub
 * econf: updating gmp-6.0.0/config.guess with /usr/share/gnuconfig/config.guess
/var/tmp/portage/dev-libs/gmp-6.0.0a/work/gmp-6.0.0/configure --prefix=/usr --build=x86_64-gentoo-linux-uclibc --host=x86_64-gentoo-linux-uclibc --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --libdir=/usr/lib --localstatedir=/var/state/gmp --enable-shared --enable-cxx --disable-static
checking build system type... x86_64-gentoo-linux-uclibc
checking host system type... x86_64-gentoo-linux-uclibc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=64
checking whether x86_64-gentoo-linux-uclibc-gcc is gcc... yes
checking compiler x86_64-gentoo-linux-uclibc-gcc -O2 -pipe -march=native -Wstack-protector -fstack-protector-all ... yes
checking for x86_64-gentoo-linux-uclibc-gcc... x86_64-gentoo-linux-uclibc-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether x86_64-gentoo-linux-uclibc-gcc accepts -g... yes
checking for x86_64-gentoo-linux-uclibc-gcc option to accept ISO C89... none needed
checking for x86_64-gentoo-linux-uclibc-gcc option to accept ISO C99... -std=gnu99
checking for x86_64-gentoo-linux-uclibc-gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu99
checking how to run the C preprocessor... x86_64-gentoo-linux-uclibc-gcc -std=gnu99 -E
checking build system compiler x86_64-gentoo-linux-uclibc-gcc -std=gnu99... yes
checking for build system preprocessor... x86_64-gentoo-linux-uclibc-gcc -std=gnu99 -E
checking for build system executable suffix... 
checking whether build system compiler is ANSI... yes
checking for build system compiler math library... -lm
checking for x86_64-gentoo-linux-uclibc-g++... x86_64-gentoo-linux-uclibc-g++
checking whether we are using the GNU C++ compiler... yes
checking whether x86_64-gentoo-linux-uclibc-g++ accepts -g... yes
checking C++ compiler x86_64-gentoo-linux-uclibc-g++  -O2 -pipe -march=native -Wstack-protector -fstack-protector-all... no, program does not run
configure.wrapped: error: C++ compiler not available, see config.log for details

!!! Please attach the following file when seeking support:
!!! /var/tmp/portage/dev-libs/gmp-6.0.0a/work/gmp-6.0.0-abi_x86_64.amd64/config.log
 * ERROR: dev-libs/gmp-6.0.0a::gentoo failed (configure phase):
 *   econf failed
 * 
 * Call stack:
 *          ebuild.sh, line   93:  Called src_configure
 *        environment, line 3092:  Called multilib-minimal_src_configure
 *        environment, line 2253:  Called multilib_foreach_abi 'multilib-minimal_abi_src_configure'
 *        environment, line 2460:  Called multibuild_foreach_variant '_multilib_multibuild_wrapper' 'multilib-minimal_abi_src_configure'
 *        environment, line 2184:  Called _multibuild_run '_multilib_multibuild_wrapper' 'multilib-minimal_abi_src_configure'
 *        environment, line 2182:  Called _multilib_multibuild_wrapper 'multilib-minimal_abi_src_configure'
 *        environment, line  428:  Called multilib-minimal_abi_src_configure
 *        environment, line 2247:  Called multilib_src_configure
 *        environment, line 2705:  Called econf '--localstatedir=/var/state/gmp' '--enable-shared' '--enable-cxx' '--disable-static'
 *   phase-helpers.sh, line  584:  Called die
 * The specific snippet of code:
 *   			die "econf failed"
 * 
 * If you need support, post the output of `emerge --info '=dev-libs/gmp-6.0.0a::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=dev-libs/gmp-6.0.0a::gentoo'`.
 * The complete build log is located at '/var/log/portage/ebuild.logs/build/dev-libs/gmp-6.0.0a:20150208-110049.log'.
 * For convenience, a symlink to the build log is located at '/var/tmp/portage/dev-libs/gmp-6.0.0a/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/dev-libs/gmp-6.0.0a/temp/environment'.
 * Working directory: '/var/tmp/portage/dev-libs/gmp-6.0.0a/work/gmp-6.0.0-abi_x86_64.amd64'
 * S: '/var/tmp/portage/dev-libs/gmp-6.0.0a/work/gmp-6.0.0'
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

>>> Failed to emerge dev-libs/gmp-6.0.0a, Log file:

>>>  '/var/log/portage/ebuild.logs/build/dev-libs/gmp-6.0.0a:20150208-110049.log'

 * Messages for package dev-libs/gmp-6.0.0a:

 * ERROR: dev-libs/gmp-6.0.0a::gentoo failed (configure phase):
 *   econf failed
 * 
 * Call stack:
 *          ebuild.sh, line   93:  Called src_configure
 *        environment, line 3092:  Called multilib-minimal_src_configure
 *        environment, line 2253:  Called multilib_foreach_abi 'multilib-minimal_abi_src_configure'
 *        environment, line 2460:  Called multibuild_foreach_variant '_multilib_multibuild_wrapper' 'multilib-minimal_abi_src_configure'
 *        environment, line 2184:  Called _multibuild_run '_multilib_multibuild_wrapper' 'multilib-minimal_abi_src_configure'
 *        environment, line 2182:  Called _multilib_multibuild_wrapper 'multilib-minimal_abi_src_configure'
 *        environment, line  428:  Called multilib-minimal_abi_src_configure
 *        environment, line 2247:  Called multilib_src_configure
 *        environment, line 2705:  Called econf '--localstatedir=/var/state/gmp' '--enable-shared' '--enable-cxx' '--disable-static'
 *   phase-helpers.sh, line  584:  Called die
 * The specific snippet of code:
 *   			die "econf failed"
 * 
 * If you need support, post the output of `emerge --info '=dev-libs/gmp-6.0.0a::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=dev-libs/gmp-6.0.0a::gentoo'`.
 * The complete build log is located at '/var/log/portage/ebuild.logs/build/dev-libs/gmp-6.0.0a:20150208-110049.log'.
 * For convenience, a symlink to the build log is located at '/var/tmp/portage/dev-libs/gmp-6.0.0a/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/dev-libs/gmp-6.0.0a/temp/environment'.
 * Working directory: '/var/tmp/portage/dev-libs/gmp-6.0.0a/work/gmp-6.0.0-abi_x86_64.amd64'
 * S: '/var/tmp/portage/dev-libs/gmp-6.0.0a/work/gmp-6.0.0'

real	0m24.158s
user	0m12.980s
sys	0m5.150s
hardeneduclibc1 work # pwd
/var/tmp/portage/dev-libs/gmp-6.0.0a/work
hardeneduclibc1 work # bash
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
hardeneduclibc1 work # cd .
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
hardeneduclibc1 . # pwd
.
hardeneduclibc1 . # exit
hardeneduclibc1 work # pwd
/var/tmp/portage/dev-libs/gmp-6.0.0a/work
hardeneduclibc1 work # bash
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
hardeneduclibc1 work # cd .
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
hardeneduclibc1 . # pwd
.
hardeneduclibc1 . # exit
hardeneduclibc1 work # cd .
hardeneduclibc1 work # pwd
/var/tmp/portage/dev-libs/gmp-6.0.0a/work
hardeneduclibc1 work # bash
hardeneduclibc1 work # exit
hardeneduclibc1 work # 


So "cd ." in the subshell that failed with that message won't work, but in parent will.
The above error(with C compiler missing) is for a different reason(yet to find out) so ignore that.