From: "Matt Turner" <mattst88@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/
Date: Wed, 28 Oct 2020 23:06:18 +0000 (UTC) [thread overview]
Message-ID: <1603926369.e1be09eedea2dba8c605a49d9211c868c2ee4dcc.mattst88@gentoo> (raw)
commit: e1be09eedea2dba8c605a49d9211c868c2ee4dcc
Author: Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Wed Oct 28 21:59:17 2020 +0000
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Wed Oct 28 23:06:09 2020 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=e1be09ee
catalyst: ...
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
catalyst/main.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 50 insertions(+), 9 deletions(-)
diff --git a/catalyst/main.py b/catalyst/main.py
index 543895c6..8f54ba89 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -1,4 +1,5 @@
import argparse
+import contextlib
import datetime
import hashlib
import os
@@ -7,7 +8,7 @@ import textwrap
import toml
-from snakeoil.process import namespaces
+from snakeoil.process.namespaces import setns, simple_unshare
from DeComp.definitions import (COMPRESS_DEFINITIONS, DECOMPRESS_DEFINITIONS,
CONTENTS_DEFINITIONS)
@@ -22,6 +23,33 @@ from catalyst.version import get_version
conf_values = confdefaults
+@contextlib.contextmanager
+def namespace(mount=True, uts=True, ipc=True, net=False, pid=False,
+ user=False, hostname=None):
+ namespaces = {
+ (mount, "mnt"): None,
+ (uts, "uts"): None,
+ (ipc, "ipc"): None,
+ (net, "net"): None,
+ (pid, "pid"): None,
+ (user, "user"): None,
+ }
+ pid = os.getpid()
+
+ # Save fds of current namespaces
+ for ns in [ns for ns in namespaces if ns[0]]:
+ fp = open(f"/proc/{pid}/ns/{ns[1]}")
+ namespaces[ns] = fp
+
+ simple_unshare(mount=mount, uts=uts, ipc=ipc, net=net, pid=pid, user=user,
+ hostname=hostname)
+ try:
+ yield None
+ finally:
+ for ns in [ns for ns in namespaces if ns[0]]:
+ fp = namespaces[ns]
+ setns(fp.fileno(), 0)
+ fp.close()
def version():
log.info(get_version())
@@ -352,19 +380,32 @@ def _main(parser, opts):
# catalyst cannot be run as a normal user due to chroots, mounts, etc
log.critical('This script requires root privileges to operate')
+ cxt = libmount.Context()
+ print("Before")
+ while (fs := cxt.mtab.next_fs()) is not None:
+ print(fs.target)
+
# Start off by creating unique namespaces to run in. Would be nice to
# use pid & user namespaces, but snakeoil's namespace module has signal
# transfer issues (CTRL+C doesn't propagate), and user namespaces need
# more work due to Gentoo build process (uses sudo/root/portage).
- namespaces.simple_unshare(
- mount=True, uts=True, ipc=True, pid=False, net=False, user=False,
- hostname='catalyst')
+ with namespace(mount=True, uts=True, ipc=True, net=False, pid=False,
+ user=False, hostname='catalyst'):
+ # everything is setup, so the build is a go
+ try:
+ success = build_target(addlargs)
+ cxt = libmount.Context()
+ print("During")
+ while (fs := cxt.mtab.next_fs()) is not None:
+ print(fs.target)
+ except KeyboardInterrupt:
+ log.critical('Catalyst build aborted due to user interrupt (Ctrl-C)')
+
+ cxt = libmount.Context()
+ print("After")
+ while (fs := cxt.mtab.next_fs()) is not None:
+ print(fs.target)
- # everything is setup, so the build is a go
- try:
- success = build_target(addlargs)
- except KeyboardInterrupt:
- log.critical('Catalyst build aborted due to user interrupt (Ctrl-C)')
if not success:
sys.exit(2)
sys.exit(0)
next reply other threads:[~2020-10-28 23:06 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-28 23:06 Matt Turner [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-01-29 23:50 [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/ Matt Turner
2021-01-28 2:09 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2021-01-28 1:54 Matt Turner
2020-10-29 19:05 Matt Turner
2020-10-29 16:34 Matt Turner
2020-10-29 16:14 Matt Turner
2020-10-29 16:04 Matt Turner
2020-10-29 16:04 Matt Turner
2020-10-29 15:47 Matt Turner
2020-10-29 15:47 Matt Turner
2020-10-29 3:33 Matt Turner
2020-10-29 3:33 Matt Turner
2020-10-28 22:22 Matt Turner
2020-10-28 22:08 Matt Turner
2020-10-28 22:00 Matt Turner
2020-10-28 21:33 Matt Turner
2020-10-28 20:51 Matt Turner
2020-10-23 4:36 Matt Turner
2020-10-22 18:59 Matt Turner
2020-05-21 20:25 [gentoo-commits] proj/catalyst:master " Matt Turner
2020-05-20 3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-21 20:25 [gentoo-commits] proj/catalyst:master " Matt Turner
2020-05-20 3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-21 20:25 [gentoo-commits] proj/catalyst:master " Matt Turner
2020-05-20 3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-20 3:39 Matt Turner
2020-05-20 3:39 Matt Turner
2020-05-20 1:52 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
2020-05-20 3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-20 1:52 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
2020-05-20 3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-20 1:52 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
2020-05-20 3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-20 1:52 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
2020-05-20 3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1603926369.e1be09eedea2dba8c605a49d9211c868c2ee4dcc.mattst88@gentoo \
--to=mattst88@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox