devices/loopback: tolerate existing device node

It is not an error if the device node already exist, which is e.g.
the case when we are using `/dev` of the host.
This commit is contained in:
Christian Kellner 2022-11-22 15:01:14 +01:00
parent f8ca0cf4bc
commit 5219e96536

View file

@ -18,11 +18,13 @@ documentation for `osbuil.util.udev.UdevInhibitor`.
import argparse
import errno
import os
import sys
from typing import Dict
from osbuild import devices, loop
from osbuild.util import ctx
from osbuild.util.udev import UdevInhibitor
SCHEMA = """
@ -106,7 +108,8 @@ class LoopbackService(devices.DeviceService):
dir_fd = -1
try:
dir_fd = os.open(devpath, os.O_CLOEXEC | os.O_PATH)
self.lo.mknod(dir_fd)
with ctx.suppress_oserror(errno.EEXIST):
self.lo.mknod(dir_fd)
finally:
if dir_fd > -1:
os.close(dir_fd)