From 4e734bf33132cf8ad0e2e668d1d24da8589ca2ea Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 2 May 2012 20:00:50 +0200 Subject: [PATCH 1/4] makefile: use LDFLAGS when linking test.commands_parser (Thanks Marcus) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 25290b81..192d3d78 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ include/GENERATED_tokens.h: include/GENERATED_call.h # and once as an object file for i3. src/commands_parser.o: src/commands_parser.c ${HEADERS} ${CMDPARSE_HEADERS} echo "[i3] CC $<" - $(CC) $(CPPFLAGS) $(CFLAGS) -DTEST_PARSER -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -o test.commands_parser $< $(LIBS) + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DTEST_PARSER -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -o test.commands_parser $< $(LIBS) $(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -c -o $@ $< src/cfgparse.yy.o: src/cfgparse.l src/cfgparse.y.o ${HEADERS} From eedd1a64d75d196adc7ccb9251a2e757a05af61d Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 2 May 2012 20:05:07 +0200 Subject: [PATCH 2/4] Make log.c figure out the physical amount of memory on Mac OS X (Thanks Marcus) --- src/log.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/log.c b/src/log.c index fd98081b..768ce92b 100644 --- a/src/log.c +++ b/src/log.c @@ -18,6 +18,10 @@ #include #include #include +#if defined(__APPLE__) +#include +#include +#endif #include "util.h" #include "log.h" @@ -93,8 +97,15 @@ void init_logging(void) { * For 512 MiB of RAM this will lead to a 5 MiB log buffer. * At the moment (2011-12-10), no testcase leads to an i3 log * of more than ~ 600 KiB. */ - long long physical_mem_bytes = (long long)sysconf(_SC_PHYS_PAGES) * - sysconf(_SC_PAGESIZE); + 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); sasprintf(&shmlogname, "/i3-log-%d", getpid()); logbuffer_shm = shm_open(shmlogname, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); From 07a385bb7ad36fa567972e999f743fa4aaaf5cd2 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 2 May 2012 20:06:57 +0200 Subject: [PATCH 3/4] =?UTF-8?q?don=E2=80=99t=20link=20against=20librt=20on?= =?UTF-8?q?=20Mac=20OS=20X=20(Thanks=20Marcus)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common.mk b/common.mk index 537d4dda..43949059 100644 --- a/common.mk +++ b/common.mk @@ -68,7 +68,10 @@ CPPFLAGS += -DPCRE_HAS_UCP=1 endif LIBS += -lm +# Darwin (Mac OS X) doesn’t have librt +ifneq ($(UNAME),Darwin) LIBS += -lrt +endif LIBS += -L $(TOPDIR)/libi3 -li3 LIBS += $(call ldflags_for_lib, xcb-event,xcb-event) LIBS += $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms) From 280a35717bbb6c6f0ba5e97bf48f5e8b9a0d98a5 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 2 May 2012 20:07:59 +0200 Subject: [PATCH 4/4] log.c: len is always positive, remove useless check (Thanks Marcus) --- src/log.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/log.c b/src/log.c index 768ce92b..92e8f57c 100644 --- a/src/log.c +++ b/src/log.c @@ -210,11 +210,6 @@ static void vlog(const bool print, const char *fmt, va_list args) { vprintf(fmt, args); } else { len += vsnprintf(message + len, sizeof(message) - len, fmt, args); - if (len < 0 ) { - fprintf(stderr, "BUG: something is overflowing here. Dropping the log entry\n"); - return; - } - if (len >= sizeof(message)) { fprintf(stderr, "BUG: single log message > 4k\n"); }