From: Michael Stapelberg Date: Wed, 31 Jul 2013 22:42:24 +0000 (+0200) Subject: log.c: use posix_fallocate() instead of ftruncate() (Thanks don) X-Git-Tag: 4.6~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bf760d0241f0f078735e230b4bf6da4fc83368fe;p=i3%2Fi3 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. --- diff --git a/src/log.c b/src/log.c index e0679e15..34e34532 100644 --- a/src/log.c +++ b/src/log.c @@ -129,10 +129,11 @@ void open_logbuffer(void) { 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; }