Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 250843 - <=app-shell/bash-3.2_p48 and <=dev-lang/python-2.6-r5 don't handle EAGAIN returned by fork() properly
Summary: <=app-shell/bash-3.2_p48 and <=dev-lang/python-2.6-r5 don't handle EAGAIN ret...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: Prefix Support (show other bugs)
Hardware: All Interix
: High normal
Assignee: Markus Duft (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on: 283384
Blocks:
  Show dependency tree
 
Reported: 2008-12-13 16:31 UTC by Alex Volkov
Modified: 2010-10-19 09:45 UTC (History)
1 user (show)

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


Attachments
fix fork() failing on EAGAIN in Bash (bash-3.2-EAGAIN.patch,665 bytes, patch)
2008-12-13 16:33 UTC, Alex Volkov
Details | Diff
fix fork() failing on EAGAIN in Python (python-2.5.2-EAGAIN.patch,539 bytes, patch)
2008-12-13 16:34 UTC, Alex Volkov
Details | Diff
A preload library, which fixes fork (fork.c,6.95 KB, text/plain)
2008-12-15 13:36 UTC, Markus Duft (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Volkov 2008-12-13 16:31:11 UTC
Bash and Python fail when they receive EAGAIN from fork(). Interix does that a lot so using emerge is nearly impossible.
After I patched Bash and Python to retry fork() if EAGAIN is received I no longer experience the errors (until new versions are installed and fail in the middle of updating world)


Reproducible: Sometimes

Steps to Reproduce:
1. Enable Subsystem for Unix-based Applications on Vista
2. Install Gentoo Prefix (on Interix 6)
3. Try to emerge something


Actual Results:  
With high probability you'll receive fork errors like these:
Example of error:
/usr/portage3/usr/lib/portage/bin/ecompressdir: fork: Resource temporarily unavailable
/usr/portage3/usr/lib/portage/bin/misc-functions.sh: fork: Resource temporarily unavailable
!!! post install failed; exiting.

>>> Failed to emerge sys-apps/findutils-4.5.2, Log file:

Another example:
>>> Emerging (1 of 52) sys-apps/findutils-4.5.2
 * findutils-4.5.2.tar.gz RMD160 SHA1 SHA256 size ;-) ...                                                        [ ok ]
 * checking ebuild checksums ;-) ...                                                                             [ ok ]
 * checking auxfile checksums ;-) ...                                                                            [ ok ]
 * checking miscfile checksums ;-) ...                                                                           [ ok ]
/usr/portage3/usr/lib/portage/bin/ebuild.sh: fork: Resource temporarily unavailable

>>> Failed to emerge sys-apps/findutils-4.5.2


Expected Results:  
I expect emerge to work [on Interix] without failing.

Portage 2.2.00.12182-prefix (default-prefix/windows/interix/6.0/x86, gcc-4.2.4, unavailable, 6.0 x86)
=================================================================
System uname: Interix-6.0-x86-32bit
Timestamp of tree: Sat, 13 Dec 2008 02:31:32 +0000
app-shells/bash:     3.2_p48
dev-lang/python:     2.5.2-r7
dev-python/pycrypto: 2.0.1-r6
sys-devel/autoconf:  2.13, 2.63
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.2
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r04.5
sys-devel/libtool:   1.5.26
ACCEPT_KEYWORDS="~x86-interix"
CBUILD="i586-pc-interix6.0"
CFLAGS=""
CHOST="i586-pc-interix6.0"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/revdep-rebuild /etc/term
info"
CXXFLAGS=""
DISTDIR="/usr/portage3/usr/portage/distfiles"
EPREFIX="/usr/portage3"
FEATURES="collision-protect distlocks fixpackages nostrip parallel-fetch preserve-libs protect-owned sfperms strict unme
rge-orphans userfetch"
GENTOO_MIRRORS="ftp://mirror.yandex.ru/gentoo-distfiles/"
LDFLAGS=""
PKGDIR="/usr/portage3/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --
timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/usr/portage3/var/tmp"
PORTDIR="/usr/portage3/usr/portage"
PORTDIR_OVERLAY="/usr/portage3/usr/local/portage/layman/Ark-kun"
SYNC="rsync://rsync.prefix.freens.org/gentoo-portage-prefix"
USE="X bzip2 cracklib gtk gtk2 jpeg midi moonlight ncurses nls png prefix readline slang ssl x86-interix xcomposite zlib
" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear
meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alia
s authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_use
r autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include in
fo log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vh
ost_alias" ELIBC="Interix" INPUT_DEVICES="keyboard mouse" KERNEL="Interix" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44
780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LANG, LC_ALL, LINGUAS, MAKEOPTS, PORTAGE_COMPRESS,
 PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Alex Volkov 2008-12-13 16:33:12 UTC
Created attachment 175215 [details, diff]
fix fork() failing on EAGAIN in Bash
Comment 2 Alex Volkov 2008-12-13 16:34:10 UTC
Created attachment 175216 [details, diff]
fix fork() failing on EAGAIN in Python
Comment 3 Alex Volkov 2008-12-13 16:37:44 UTC
I don't know if EAGAIN is returned on other systems so I filed this as Interix bug.
Comment 4 Fabian Groffen gentoo-dev 2008-12-14 09:56:11 UTC
Did you send these patches upstream?  If I look at the manpages for fork on Darwin and Interix they show about the same description for EAGAIN.

mduft, do you have any comment on this?  I think I didn't encounter this problem, but I'm on old Interix (3.5).
Comment 5 Markus Duft (RETIRED) gentoo-dev 2008-12-15 13:36:40 UTC
Created attachment 175328 [details]
A preload library, which fixes fork

the problem seems to appear in vista/server 2008 only here. i have a solution around this, which has been populated before on interopcommunity.com. i'll post the sources for it here. mainly this "solution" preloads every binary (so LD_PRELOAD needs to be set system wide for it to catch the login shell (bash in your case?))

otherwise you could start a bash and do something like this:

LD_PRELOAD=/path/to/libfork.so bash -l

und use that shell for working. then everything works like a charm, and it removes the need to patch every single program for interix (yeah, there are many of them, not handling EAGAIN).

you can build the attached source like this:

gcc -O2 -shared fork.c -DLIBC_NAME="\"libc.so.5.2\"" -DINSTALL_LIBNAME="\"`pwd`/libfork.so\"" -D_ALL_SOURCE -o libfork.so -ldl

be sure that INSTALL_LIBNAME is correct (an absolute path to the library as it will be loaded), since the library adds itselve back to LD_PRELOAD on every exec which would clean it from the environment.

also it is quite hard to replace the library after activating it from interix, since even the compiler and linker are preloaded with it, so the file cannot be replaced, nor can it be moved, since after moving nothing loads anymore ;) so if you happen to rebuild the library, change the -o to some other filename (but leave INSTALL_LIBNAME the same), and rename the two files in explorer (rename, replace won't work, since the lib may still be loaded somewhere), and all new processes will catch the new one.

you can add -DDEBUG to the compiler command to enable debug output (be aware, it's much ;)). also you can adjust the FORK_RETRY count in fork.c.

note that this only works for fork() and not for vfork(). for a more detailed description on why this is the case, look at the bottom of the source. there is a first implementation try, which is commented out, and described.

maybe interesting is the reason for why this happens: the windows kernel returns a "try again" error, whenever it's internal caching mechanisms are busy processing some executable - at least thats what i was told. this has become much worse on vista, since there is some new executable cache... although it _can_ happen on older systems too, it's more unlikely.

hope that helps. i guess i won't patch all interix ebuilds to handle fork correctly as long as this workaround works fine. it would be just too much work...

Cheers, Markus
Comment 6 Fabian Groffen gentoo-dev 2009-01-18 09:49:47 UTC
Hmmm, Markus, can we somehow get this in a package or something and use an env.d entry to get this automated for vista users?
Comment 7 Markus Duft (RETIRED) gentoo-dev 2009-01-19 07:07:34 UTC
(In reply to comment #6)
> Hmmm, Markus, can we somehow get this in a package or something and use an
> env.d entry to get this automated for vista users?

hmm, maybe, yes. this would make prefix work 1000times better than the rest of interix ;). but the only way to catch the whole system is to insert the LD_PRELOAD env var into the system variables.

the only real problem (besides interix not working properly outside of a prefix installation then... ;)) is preloading the prefix shell. if the env.d's are sourced, this is probably too late, since the shell won't catch the LD_PRELOAD variable (it's already running, right?).
Comment 8 Markus Duft (RETIRED) gentoo-dev 2009-01-19 07:24:05 UTC
thought a little about it... i guess the best way would be to create a package for prefix, and write out an einfo at the end telling the user (how) to set LD_PRELOAD in the windows system envrionment...
Comment 9 Fabian Groffen gentoo-dev 2009-05-20 17:45:53 UTC
how does this work currently?
Comment 10 Markus Duft (RETIRED) gentoo-dev 2009-05-25 06:10:11 UTC
(In reply to comment #9)
> how does this work currently?
> 

manually :( ATM, i'm still fixing this manually for every vista/server 2008 machine. i plan to create a package this week, and fix bash so it does not need the preload... this way at least after entering prefix, everything should work (and i guess it doesn't matter that the "outside prefix" world is completely b0rked... :))
Comment 11 Fabian Groffen gentoo-dev 2009-06-30 19:08:31 UTC
Markus, can you revisit this thing again?
Comment 12 Markus Duft (RETIRED) gentoo-dev 2009-07-06 06:27:57 UTC
i will..
Comment 13 Markus Duft (RETIRED) gentoo-dev 2009-09-22 14:40:26 UTC
the i6fork package is in the tree by now, and it seems to work quite well. however ATM i'm hunting a few server 2008 only bugs, which could be caused by i6fork... all this hackery is causing troubles over troubles - but nothing else would help except patching every package that fork()s... damn
Comment 14 Markus Duft (RETIRED) gentoo-dev 2010-10-19 09:45:16 UTC
this has been fixed by the user of the suacomp package, which i wrote to fix some of the major problems with the interix libc.