init: restore mounts under /sys after enter_namespace
Entering a network namespace requires remounting sysfs to update contents of
/sys/class/net whose contents depend on the network namespace of the process
that mounted it rather than the effective network namespace of the reading
process.
A side effect of the remounting is unmounting all filesystems mounted under
/sys. In particular, unmounting tracefs (/sys/kernel/tracing) prevents
collecting ATrace traces from any init service that uses `enter_namespace
net`.
This CL makes init iterate over all current mounts and remount anything
under /sys/ after it remounts /sys for the service being started.
A minor change is to pass "sysfs" rather than the empty string as the
block device argument to mount. Otherwise, /proc/$PID/mounts inside the
process in network namespace contains a sysfs entry with no block device
name, which confuses the Fstab parser into thinking that /sys is the
block device, which made the included test fail.
Bug: 399071958
Test: th (test included)
Test: manual check: capture perfetto trace for a process started inside
Test: a network namespace, see ATrace traces showing up that weren't
Test: there before
Change-Id: Icc1e763dff115a06ac23b37f14cfbdd328bbe659
diff --git a/init/Android.bp b/init/Android.bp
index dbdf80b..b209c47 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -599,6 +599,7 @@
],
static_libs: [
"libbase",
+ "libfstab",
"libselinux",
"libpropertyinfoserializer",
"libpropertyinfoparser",