On Tue, Mar 26, 2024 at 03:45:52PM +0100, David Hildenbrand wrote:
+ mode = 0;
+ oflag = O_RDWR | O_CREAT | O_EXCL;
+ backend_name = host_memory_backend_get_name(backend);
+
+ /*
+ * Some operating systems allow creating anonymous POSIX shared memory
+ * objects (e.g. FreeBSD provides the SHM_ANON constant), but this is not
+ * defined by POSIX, so let's create a unique name.
+ *
+ * From Linux's shm_open(3) man-page:
+ * For portable use, a shared memory object should be identified
+ * by a name of the form /somename;"
+ */
+ g_string_printf(shm_name, "/qemu-" FMT_pid "-shm-%s", getpid(),
+ backend_name);
Hm, shouldn't we just let the user specify a name, and if no name was
specified, generate one ourselves?
I thought about it and initially did it that way, but then some problems
came up so I tried to keep it as simple as possible for the user and for
our use case (having an fd associated with memory and sharing it with
other processes).
The problems I had were:
- what mode_t to use if the object does not exist and needs to be
created? >
- exclude O_EXCL if the user passes the name since they may have already
created it?
That said, if you think it's already useful from the beginning, I can
add the name as an optional parameter.
I'm also not quite sure if "host_memory_backend_get_name()" should be
used for the purpose here.
What problem do you see? As an alternative I thought of a static
counter.