Ted Unangst wrote:
bytevolc...@safe-mail.net wrote:
Yes, it seems to create files with long names (that have nothing to do
with the template I provide) in the /tmp root.

If it doesn't respect the path or template, what is the point of having
this argument there in the first place, and what is the point of even
having a file on the file system?

The file is the backing for the memory. The path is so that you can refer to
the same object. There's no requirement that the path be the name of the file
in the filesystem, since you don't use normal file functions to talk to it.

When I use ftruncate(2) to actually allocate the segment, the file is as long as the segment that is allocated.

Even if the file is unlinked before ftruncate(2) is called, enough free space in the /tmp *file system* is required for the shared memory segment.

Is using ftruncate(2) to lengthen the segment the right way to do it, or is this yet another stupid limitation of POSIX shared memory? I did give SysV shared memory segments a go, but work required for cleanup is even more insane when the program crashes!


I do not see any promises here. The only promise here is that the shared
memory object will be created atomically. I found it creates long-name
files with mode 0600. If the implementation promises these permissions
for shm_mkstemp(3), then fantastic; it should really be mentioned in the
man page though.

"This implementation forces the mode to be 0600"

Thanks for pointing that out; I saw that, but I got confused as it was in the paragraph describing shm_open(3).


There's still an issue of the stale files on the file system, should
there be a crash, interruption, signal, or something like that. Even
with close(2), the file remains until shm_unlink(3) is called.

That's not unique to shm functions. Everything creating files can do that.


Indeed, but I don't see a use case for having shared memory backed verbatim by a file, to the point where the amount of shared memory that can be allocated depends on how much free space left in the /tmp file system.

Say I want to allocate 2GB shared memory object, I cannot do so with ftruncate(2) because I only have 128MB left in /tmp.

Reply via email to