From bf760d0241f0f078735e230b4bf6da4fc83368fe Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 1 Aug 2013 00:42:24 +0200 Subject: [PATCH] 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. --- src/log.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; } -- 2.39.5