2 #define I3__FILE__ "log.c"
31 #if defined(__APPLE__)
32 #include <sys/sysctl.h>
86 fprintf(stderr,
"Could not initialize errorlog\n");
89 if (fcntl(fileno(
errorfile), F_SETFD, FD_CLOEXEC)) {
90 fprintf(stderr,
"Could not set close-on-exec flag\n");
95 #if defined(__APPLE__)
96 int mib[2] = {CTL_HW, HW_MEMSIZE};
97 size_t length =
sizeof(
long long);
101 sysconf(_SC_PAGESIZE);
124 #if defined(__FreeBSD__)
131 fprintf(stderr,
"Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
135 #if defined(__OpenBSD__) || defined(__APPLE__)
137 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
141 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
151 fprintf(stderr,
"Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
160 pthread_condattr_t cond_attr;
161 pthread_condattr_init(&cond_attr);
162 if (pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED) != 0)
163 fprintf(stderr,
"pthread_condattr_setpshared() failed, i3-dump-log -f will not work!\n");
164 pthread_cond_init(&(header->
condvar), &cond_attr);
216 static void vlog(
const bool print,
const char *fmt, va_list args) {
219 static char message[4096];
220 static struct tm result;
222 static struct tm *tmp;
228 tmp = localtime_r(&t, &result);
230 len = strftime(message,
sizeof(message),
"%x %X - ", tmp);
243 gettimeofday(&tv, NULL);
244 printf(
"%s%d.%d - ", message, tv.tv_sec, tv.tv_usec);
246 printf(
"%s", message);
250 len += vsnprintf(message + len,
sizeof(message) - len, fmt, args);
251 if (len >=
sizeof(message)) {
252 fprintf(stderr,
"BUG: single log message > 4k\n");
257 len =
sizeof(message);
261 message[len - 2] =
'\n';
275 strncpy(
logwalk, message, len);
281 pthread_cond_broadcast(&(header->
condvar));
284 fwrite(message, len, 1, stdout);
312 vlog(
true, fmt, args);
struct i3_shmlog_header i3_shmlog_header
void set_verbosity(bool _verbose)
Set verbosity of i3.
static void store_log_markers(void)
static long long physical_mem_bytes
bool get_debug_logging(void)
Checks if debug logging is active.
uint32_t offset_next_write
void debuglog(char *fmt,...)
void set_debug_logging(const bool _debug_logging)
Set debug logging.
uint32_t offset_last_wrap
static int logbuffer_size
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
static char * loglastwrap
static bool debug_logging
void verboselog(char *fmt,...)
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
static i3_shmlog_header * header
char * get_process_filename(const char *prefix)
Returns the name of a temporary file with the specified prefix.
static void vlog(const bool print, const char *fmt, va_list args)
void open_logbuffer(void)
Opens the logbuffer.
void purge_zerobyte_logfile(void)
Deletes the unused log files.
void close_logbuffer(void)
Closes the logbuffer.
void errorlog(char *fmt,...)