1 |
On 8/1/19 6:22 AM, Mike Gilbert wrote: |
2 |
> This works around some strange behavior in glibc's getaddrinfo() |
3 |
> implementation when the AI_ADDRCONFIG flag is set. |
4 |
> |
5 |
> For example: |
6 |
> |
7 |
> struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_flags = AI_ADDRCONFIG }; |
8 |
> getaddrinfo("localhost", NULL, &hints, &res); |
9 |
> |
10 |
> This returns no results if there are no non-loopback addresses configured. |
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 | 50 +++++++++++++++++++++++++++++++----------- |
17 |
> 1 file changed, 37 insertions(+), 13 deletions(-) |
18 |
> |
19 |
> diff --git a/lib/portage/process.py b/lib/portage/process.py |
20 |
> index dfbda75de..77f7fac02 100644 |
21 |
> --- a/lib/portage/process.py |
22 |
> +++ b/lib/portage/process.py |
23 |
> @@ -446,6 +446,42 @@ def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False, |
24 |
> # Everything succeeded |
25 |
> return 0 |
26 |
> |
27 |
> +def _configure_loopback_interface(): |
28 |
> + """ |
29 |
> + Configure the loopback interface. |
30 |
> + """ |
31 |
> + |
32 |
> + IFF_UP = 0x1 |
33 |
> + ifreq = struct.pack('16sh', b'lo', IFF_UP) |
34 |
> + SIOCSIFFLAGS = 0x8914 |
35 |
> + |
36 |
> + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) |
37 |
> + try: |
38 |
> + fcntl.ioctl(sock, SIOCSIFFLAGS, ifreq) |
39 |
> + except IOError as e: |
40 |
> + writemsg("Unable to enable loopback interface: %s\n" % e.strerror, noiselevel=-1) |
41 |
> + sock.close() |
42 |
> + |
43 |
> + # We add some additional addresses to work around odd behavior in glibc's |
44 |
> + # getaddrinfo() implementation when the AI_ADDRCONFIG flag is set. |
45 |
> + # |
46 |
> + # For example: |
47 |
> + # |
48 |
> + # struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_flags = AI_ADDRCONFIG }; |
49 |
> + # getaddrinfo("localhost", NULL, &hints, &res); |
50 |
> + # |
51 |
> + # This returns no results if there are no non-loopback addresses |
52 |
> + # configured for a given address family. |
53 |
> + # |
54 |
> + # Bug: https://bugs.gentoo.org/690758 |
55 |
> + # Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13 |
56 |
> + |
57 |
> + try: |
58 |
> + subprocess.call(['ip', 'address', 'add', '10.0.0.1/8', 'dev', 'lo']) |
59 |
> + subprocess.call(['ip', 'address', 'add', 'fd00::1/8', 'dev', 'lo']) |
60 |
> + except OSError as e: |
61 |
> + writemsg("Error calling 'ip': %s\n" % e.strerror, noiselevel=-1) |
62 |
> + |
63 |
> def _exec(binary, mycommand, opt_name, fd_pipes, |
64 |
> env, gid, groups, uid, umask, cwd, |
65 |
> pre_exec, close_fds, unshare_net, unshare_ipc, unshare_mount, unshare_pid, |
66 |
> @@ -624,19 +660,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, |
67 |
> noiselevel=-1) |
68 |
> os._exit(1) |
69 |
> if unshare_net: |
70 |
> - # 'up' the loopback |
71 |
> - IFF_UP = 0x1 |
72 |
> - ifreq = struct.pack('16sh', b'lo', IFF_UP) |
73 |
> - SIOCSIFFLAGS = 0x8914 |
74 |
> - |
75 |
> - sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) |
76 |
> - try: |
77 |
> - fcntl.ioctl(sock, SIOCSIFFLAGS, ifreq) |
78 |
> - except IOError as e: |
79 |
> - writemsg("Unable to enable loopback interface: %s\n" % ( |
80 |
> - errno.errorcode.get(e.errno, '?')), |
81 |
> - noiselevel=-1) |
82 |
> - sock.close() |
83 |
> + _configure_loopback_interface() |
84 |
> except AttributeError: |
85 |
> # unshare() not supported by libc |
86 |
> pass |
87 |
> |
88 |
|
89 |
Looks good. Please merge. |
90 |
-- |
91 |
Thanks, |
92 |
Zac |