log.c: use posix_fallocate() instead of ftruncate() (Thanks don)
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.
This commit is contained in:
parent
3eea370db2
commit
bf760d0241
|
@ -129,10 +129,11 @@ void open_logbuffer(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftruncate(logbuffer_shm, logbuffer_size) == -1) {
|
int ret;
|
||||||
|
if ((ret = posix_fallocate(logbuffer_shm, 0, logbuffer_size)) != 0) {
|
||||||
close(logbuffer_shm);
|
close(logbuffer_shm);
|
||||||
shm_unlink(shmlogname);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue