Skip to content

Commit

Permalink
util: use Libc.memfd_create() when os.memfd_create() is missing
Browse files Browse the repository at this point in the history
This provide compat for pyton versions below 3.8. This can be
removed (together with the previous commit) once we are at
python3.8+.
  • Loading branch information
mvo5 committed Aug 12, 2024
1 parent ffd6caa commit 0cff045
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion osbuild/util/jsoncomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@
import socket
from typing import Any, Optional

from .linux import Libc
from .types import PathLike


@contextlib.contextmanager
def memfd(name):
fd = os.memfd_create(name, 0)
if hasattr(os, "memfd_create"):
fd = os.memfd_create(name)
else:
# we can remove this "if/else" once we are at python3.8+
# and just use "os.memfd_create()"
libc = Libc.default()
fd = libc.memfd_create(name)

try:
yield fd
finally:
Expand Down

0 comments on commit 0cff045

Please sign in to comment.