Gentoo Archives: gentoo-commits

From: Matt Turner <mattst88@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/
Date: Wed, 28 Oct 2020 22:22:39
Message-Id: 1603923743.0a2be9a29d11499d346d09628fabbe4a3d5b2822.mattst88@gentoo
1 commit: 0a2be9a29d11499d346d09628fabbe4a3d5b2822
2 Author: Matt Turner <mattst88 <AT> gentoo <DOT> org>
3 AuthorDate: Wed Oct 28 22:21:50 2020 +0000
4 Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
5 CommitDate: Wed Oct 28 22:22:23 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=0a2be9a2
7
8 wip
9
10 Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
11
12 catalyst/main.py | 33 ++++++++++++++++++++++++++++++---
13 1 file changed, 30 insertions(+), 3 deletions(-)
14
15 diff --git a/catalyst/main.py b/catalyst/main.py
16 index f4d3b7d7..0561aa1d 100644
17 --- a/catalyst/main.py
18 +++ b/catalyst/main.py
19 @@ -1,4 +1,5 @@
20 import argparse
21 +import contextlib
22 import datetime
23 import hashlib
24 import os
25 @@ -7,7 +8,7 @@ import textwrap
26
27 import toml
28
29 -from snakeoil.contexts import Namespace
30 +from snakeoil.process.namespaces import setns, simple_unshare
31
32 from DeComp.definitions import (COMPRESS_DEFINITIONS, DECOMPRESS_DEFINITIONS,
33 CONTENTS_DEFINITIONS)
34 @@ -22,6 +23,33 @@ from catalyst.version import get_version
35
36 conf_values = confdefaults
37
38 +@××××××××××.contextmanager
39 +def namespace(mount=True, uts=True, ipc=True, net=False, pid=False,
40 + user=False, hostname=None):
41 + namespaces = {
42 + (mount, "mnt"): None,
43 + (uts, "uts"): None,
44 + (ipc, "ipc"): None,
45 + (net, "net"): None,
46 + (pid, "pid"): None,
47 + (user, "user"): None,
48 + }
49 + pid = os.getpid()
50 +
51 + # Save fds of current namespaces
52 + for ns in [ns for ns in namespaces if ns[0]]:
53 + fp = open(f"/proc/{pid}/ns/{ns[1]}")
54 + namespaces[ns] = fp
55 +
56 + simple_unshare(mount=mount, uts=uts, ipc=ipc, net=net, pid=pid, user=user,
57 + hostname=hostname)
58 + try:
59 + yield None
60 + finally:
61 + for ns in [ns for ns in namespaces if ns[0]]:
62 + fp = namespaces[ns]
63 + setns(fp.fileno(), 0)
64 + fp.close()
65
66 def version():
67 log.info(get_version())
68 @@ -356,13 +384,12 @@ def _main(parser, opts):
69 # use pid & user namespaces, but snakeoil's namespace module has signal
70 # transfer issues (CTRL+C doesn't propagate), and user namespaces need
71 # more work due to Gentoo build process (uses sudo/root/portage).
72 - with Namespace(mount=True, uts=True, ipc=True, net=False, pid=False,
73 + with namespace(mount=True, uts=True, ipc=True, net=False, pid=False,
74 user=False, hostname='catalyst'):
75 # everything is setup, so the build is a go
76 try:
77 success = build_target(addlargs)
78 except KeyboardInterrupt:
79 - success = False
80 log.critical('Catalyst build aborted due to user interrupt (Ctrl-C)')
81
82 if not success: