ftruncate failed at the second time ftruncate failed at the second time unix unix

ftruncate failed at the second time


I think this is a known "feature" of shm_open(), ftruncate(), mmap().

You have to ftruncate() the first time through to give the shared memory a length, but subsequent times ftruncate() gives that error number 22, which you can simply ignore.


The used implementation seems to conform to an older specification where returning an error is an allowed behavior for ftruncate(fd, length) when length exceeds the previous length:

If the file previously was smaller than this size, ftruncate() shall either increase the size of the file or fail.