- long long physical_mem_bytes = (long long)sysconf(_SC_PHYS_PAGES) *
- sysconf(_SC_PAGESIZE);
- logbuffer_size = min(physical_mem_bytes * 0.01, shmlog_size);
- sasprintf(&shmlogname, "/i3-log-%d", getpid());
- logbuffer_shm = shm_open(shmlogname, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
- if (logbuffer_shm == -1) {
- ELOG("Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
- return;
- }
+ long long physical_mem_bytes;
+#if defined(__APPLE__)
+ int mib[2] = {CTL_HW, HW_MEMSIZE};
+ size_t length = sizeof(long long);
+ sysctl(mib, 2, &physical_mem_bytes, &length, NULL, 0);
+#else
+ physical_mem_bytes = (long long)sysconf(_SC_PHYS_PAGES) *
+ sysconf(_SC_PAGESIZE);
+#endif
+ logbuffer_size = min(physical_mem_bytes * 0.01, shmlog_size);
+#if defined(__FreeBSD__)
+ sasprintf(&shmlogname, "/tmp/i3-log-%d", getpid());
+#else
+ sasprintf(&shmlogname, "/i3-log-%d", getpid());
+#endif
+ logbuffer_shm = shm_open(shmlogname, O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
+ if (logbuffer_shm == -1) {
+ fprintf(stderr, "Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
+ return;
+ }