The effect is that the error handling is much better. posix_fallocate()
will allocate all the requested space, whereas ftruncate() does not.
Before this commit, in case the /dev/shm filesystem is too small to hold
the _contents_ of the log file, i3 will SIGBUS when writing to the shm
logfile. With this commit, it will print an error message on startup,
but continue to run without logging.
return;
}
- if (ftruncate(logbuffer_shm, logbuffer_size) == -1) {
+ int ret;
+ if ((ret = posix_fallocate(logbuffer_shm, 0, logbuffer_size)) != 0) {
close(logbuffer_shm);
shm_unlink(shmlogname);
- fprintf(stderr, "Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
+ fprintf(stderr, "Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
return;
}