[Piuparts-devel] [Git][debian/piuparts][develop] bind-mount the minimal /dev devices if they can't be opened
Nicolas Dandrimont (@olasd)
gitlab at salsa.debian.org
Mon Oct 21 13:50:58 BST 2024
Nicolas Dandrimont pushed to branch develop at Debian / piuparts
Commits:
9f58e16c by Nicolas Dandrimont at 2024-10-11T17:13:30+01:00
bind-mount the minimal /dev devices if they can't be opened
When the piuparts temporary directory is mounted nodev, e.g. when it's
under the default /tmp tmpfs in current Debian sid, the minimal /dev
entries can be created with mknod, but they can't be opened. In that
case, bind-mount them.
Closes: #1084234
- - - - -
1 changed file:
- piuparts.py
Changes:
=====================================
piuparts.py
=====================================
@@ -1227,22 +1227,29 @@ class Chroot:
}
for devname, devnum in chardevices.items():
devname = "/dev/" + devname
+ inner_path = self.name + devname
isdevice = False
try:
- isdevice = stat.S_ISCHR(os.stat(self.name + devname).st_mode)
+ isdevice = stat.S_ISCHR(os.stat(inner_path).st_mode)
except FileNotFoundError:
# Try creating missing devices. If that fails with -EPERM, we
# likely are in an unprivileged namespace and resort to bind
# mounting them individually.
try:
- os.mknod(self.name + devname, stat.S_IFCHR | 0o666, devnum)
- os.chmod(self.name + devname, 0o666) # Override umask
+ os.mknod(inner_path, stat.S_IFCHR | 0o666, devnum)
+ os.chmod(inner_path, 0o666) # Override umask
isdevice = True
except OSError as err:
if err.errno != errno.EPERM:
raise
# Create a regular file to serve as a mount point.
- os.mknod(self.name + devname, stat.S_IFREG)
+ os.mknod(inner_path, stat.S_IFREG)
+ if isdevice:
+ try:
+ open(inner_path, "rb").close()
+ except PermissionError:
+ # Could not open the device, the filesystem is probably nodev.
+ isdevice = False
if not isdevice:
self.mount(devname, devname, opts=["bind"])
View it on GitLab: https://salsa.debian.org/debian/piuparts/-/commit/9f58e16cf4e4bcd2b3ed3abf4d323661c6d56d89
--
View it on GitLab: https://salsa.debian.org/debian/piuparts/-/commit/9f58e16cf4e4bcd2b3ed3abf4d323661c6d56d89
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/piuparts-devel/attachments/20241021/01688828/attachment-0001.htm>
More information about the Piuparts-devel
mailing list