2 #define I3__FILE__ "log.c"
24 #if defined(__APPLE__)
25 #include <sys/types.h>
26 #include <sys/sysctl.h>
84 ELOG(
"Could not initialize errorlog\n");
87 if (fcntl(fileno(
errorfile), F_SETFD, FD_CLOEXEC)) {
88 ELOG(
"Could not set close-on-exec flag\n");
100 long long physical_mem_bytes;
101 #if defined(__APPLE__)
102 int mib[2] = { CTL_HW, HW_MEMSIZE };
103 size_t length =
sizeof(
long long);
104 sysctl(mib, 2, &physical_mem_bytes, &length, NULL, 0);
106 physical_mem_bytes = (
long long)sysconf(_SC_PHYS_PAGES) *
107 sysconf(_SC_PAGESIZE);
113 ELOG(
"Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
119 shm_unlink(
"/i3-log-");
120 ELOG(
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
127 shm_unlink(
"/i3-log-");
128 ELOG(
"Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
138 pthread_condattr_t cond_attr;
139 pthread_condattr_init(&cond_attr);
140 if (pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED) != 0)
141 ELOG(
"pthread_condattr_setpshared() failed, i3-dump-log -f will not work!\n");
142 pthread_cond_init(&(header->
condvar), &cond_attr);
176 static void vlog(
const bool print,
const char *fmt, va_list args) {
179 static char message[4096];
180 static struct tm result;
182 static struct tm *tmp;
188 tmp = localtime_r(&t, &result);
190 len = strftime(message,
sizeof(message),
"%x %X - ", tmp);
203 gettimeofday(&tv, NULL);
204 printf(
"%s%d.%d - ", message, tv.tv_sec, tv.tv_usec);
206 printf(
"%s", message);
210 len += vsnprintf(message + len,
sizeof(message) - len, fmt, args);
211 if (len >=
sizeof(message)) {
212 fprintf(stderr,
"BUG: single log message > 4k\n");
226 strncpy(
logwalk, message, len);
232 pthread_cond_broadcast(&(header->
condvar));
235 fwrite(message, len, 1, stdout);
263 vlog(
true, fmt, args);