[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] linux-user: Use memfd for open syscall emulation
From: |
Rainer Müller |
Subject: |
Re: [PATCH v2] linux-user: Use memfd for open syscall emulation |
Date: |
Fri, 29 Jul 2022 23:19:17 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.23) Gecko/20090925 Thunderbird/2.0.0.23 Mnenhy/0.7.5.0 |
On 29/07/2022 18.01, Richard Henderson wrote:
> On 7/29/22 08:49, Rainer Müller wrote:
>> + /* create temporary file to map stat to */
>> + tmpdir = getenv("TMPDIR");
>> + if (!tmpdir)
>> + tmpdir = "/tmp";
>> + snprintf(filename, sizeof(filename),
>> "%s/qemu-open.XXXXXX", tmpdir);
>> + fd = mkstemp(filename);
>> + if (fd < 0) {
>> + return fd;
>> + }
>
> We've been using g_file_open_tmp elsewhere; probably good to follow suit
> here.
That seemed reasonable at first, but with regards to error handling it
gets a bit complicated.
The suggested g_file_open_tmp() would leave us with a GError only, but
to return something meaningful to the caller we must set errno in this
context. As far as I can see, there is no way to convert back to an
errno from GError.
With g_file_open_tmp() we could always set the same generic errno, but
that would hide the real cause completely. I debugged this problem with
this message that was confusing, but at least it gave away a hint:
cat: can't open '/proc/self/stat': Read-only file system
The other option would be to g_assert_true(fd >= 0) and kill the process
in case opening the temporary file failed. This also feels wrong, as the
caller could still recover from this state and continue.
Rainer