]> git.sur5r.net Git - i3/i3/blobdiff - src/log.c
Include sys/sysctl.h after i3.h to prevent redefinition warnings caused by queue...
[i3/i3] / src / log.c
index 34e345322e994e57a07b70e2b0e084c6337b9803..10149081ed3e54f574f91598fa97c226f2a8df3d 100644 (file)
--- a/src/log.c
+++ b/src/log.c
 #include <sys/stat.h>
 #include <errno.h>
 #include <pthread.h>
-#if defined(__APPLE__)
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#endif
 
 #include "util.h"
 #include "log.h"
 #include "libi3.h"
 #include "shmlog.h"
 
+#if defined(__APPLE__)
+#include <sys/sysctl.h>
+#endif
+
 static bool debug_logging = false;
 static bool verbose = false;
 static FILE *errorfile;
@@ -129,11 +129,16 @@ void open_logbuffer(void) {
             return;
         }
 
+#if defined(__OpenBSD__) || defined(__APPLE__)
+        if (ftruncate(logbuffer_shm, logbuffer_size) == -1) {
+            fprintf(stderr, "Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
+#else
         int ret;
         if ((ret = posix_fallocate(logbuffer_shm, 0, logbuffer_size)) != 0) {
+            fprintf(stderr, "Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
+#endif
             close(logbuffer_shm);
             shm_unlink(shmlogname);
-            fprintf(stderr, "Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
             return;
         }
 
@@ -245,7 +250,7 @@ static void vlog(const bool print, const char *fmt, va_list args) {
 
         /* If there is no space for the current message in the ringbuffer, we
          * need to wrap and write to the beginning again. */
-        if (len >= (logbuffer_size - (logwalk - logbuffer))) {
+        if (len >= (size_t)(logbuffer_size - (logwalk - logbuffer))) {
             loglastwrap = logwalk;
             logwalk = logbuffer + sizeof(i3_shmlog_header);
             store_log_markers();