1 |
This works around some strange behavior in glibc's getaddrinfo() |
2 |
implementation when the AI_ADDRCONFIG flag is set. |
3 |
|
4 |
For example: |
5 |
|
6 |
struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_flags = AI_ADDRCONFIG }; |
7 |
getaddrinfo("localhost", NULL, &hints, &res); |
8 |
|
9 |
This returns no results if there is no non-loopback interface configured with an |
10 |
IPv4 address. |
11 |
|
12 |
Bug: https://bugs.gentoo.org/690758 |
13 |
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13 |
14 |
Signed-off-by: Mike Gilbert <floppym@g.o> |
15 |
--- |
16 |
lib/portage/process.py | 24 ++++++++++++++++++++++++ |
17 |
1 file changed, 24 insertions(+) |
18 |
|
19 |
diff --git a/lib/portage/process.py b/lib/portage/process.py |
20 |
index dfbda75de..c284c04f3 100644 |
21 |
--- a/lib/portage/process.py |
22 |
+++ b/lib/portage/process.py |
23 |
@@ -446,6 +446,29 @@ def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False, |
24 |
# Everything succeeded |
25 |
return 0 |
26 |
|
27 |
+def _configure_dummy_interface(): |
28 |
+ """ |
29 |
+ Configure a dummy interface to work around odd behavior in glibc's |
30 |
+ getaddrinfo() implementation when the AI_ADDRCONFIG flag is set. |
31 |
+ |
32 |
+ For example: |
33 |
+ |
34 |
+ struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_flags = AI_ADDRCONFIG }; |
35 |
+ getaddrinfo("localhost", NULL, &hints, &res); |
36 |
+ |
37 |
+ This returns no results if there is no non-loopback interface configured with an |
38 |
+ IPv4 address. |
39 |
+ |
40 |
+ Bug: https://bugs.gentoo.org/690758 |
41 |
+ Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13 |
42 |
+ """ |
43 |
+ try: |
44 |
+ subprocess.check_call(['ip','link','add','dummy','type','dummy']) |
45 |
+ subprocess.check_call(['ip','link','set','dummy','up']) |
46 |
+ subprocess.check_call(['ip','address','add','10.0.0.1/8','dev','dummy']) |
47 |
+ except subprocess.CalledProcessError: |
48 |
+ writemsg("Unable to configure dummy network interface\n") |
49 |
+ |
50 |
def _exec(binary, mycommand, opt_name, fd_pipes, |
51 |
env, gid, groups, uid, umask, cwd, |
52 |
pre_exec, close_fds, unshare_net, unshare_ipc, unshare_mount, unshare_pid, |
53 |
@@ -637,6 +660,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, |
54 |
errno.errorcode.get(e.errno, '?')), |
55 |
noiselevel=-1) |
56 |
sock.close() |
57 |
+ _configure_dummy_interface() |
58 |
except AttributeError: |
59 |
# unshare() not supported by libc |
60 |
pass |
61 |
-- |
62 |
2.22.0 |