23 #if !defined(__OpenBSD__) 33 #if defined(__APPLE__) 34 #include <sys/sysctl.h> 88 fprintf(stderr,
"Could not initialize errorlog\n");
92 fprintf(stderr,
"Could not initialize errorlog on %s: %s\n",
95 if (fcntl(fileno(
errorfile), F_SETFD, FD_CLOEXEC)) {
96 fprintf(stderr,
"Could not set close-on-exec flag\n");
102 #if defined(__APPLE__) 103 int mib[2] = {CTL_HW, HW_MEMSIZE};
104 size_t length =
sizeof(
long long);
108 sysconf(_SC_PAGESIZE);
131 #if defined(__FreeBSD__) 138 fprintf(stderr,
"Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
142 #if defined(__OpenBSD__) || defined(__APPLE__) 144 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
148 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
158 fprintf(stderr,
"Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
167 #if !defined(__OpenBSD__) 168 pthread_condattr_t cond_attr;
169 pthread_condattr_init(&cond_attr);
170 if (pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED) != 0)
171 fprintf(stderr,
"pthread_condattr_setpshared() failed, i3-dump-log -f will not work!\n");
172 pthread_cond_init(&(header->
condvar), &cond_attr);
225 static void vlog(
const bool print,
const char *fmt, va_list args) {
228 static char message[4096];
229 static struct tm result;
231 static struct tm *tmp;
237 tmp = localtime_r(&t, &result);
239 len = strftime(message,
sizeof(message),
"%x %X - ", tmp);
252 gettimeofday(&tv, NULL);
253 printf(
"%s%d.%d - ", message, tv.tv_sec, tv.tv_usec);
255 printf(
"%s", message);
259 len += vsnprintf(message + len,
sizeof(message) - len, fmt, args);
260 if (len >=
sizeof(message)) {
261 fprintf(stderr,
"BUG: single log message > 4k\n");
266 len =
sizeof(message);
270 message[len - 2] =
'\n';
284 strncpy(
logwalk, message, len);
289 #if !defined(__OpenBSD__) 291 pthread_cond_broadcast(&(header->
condvar));
295 fwrite(message, len, 1, stdout);
323 vlog(
true, fmt, args);
void open_logbuffer(void)
Opens the logbuffer.
uint32_t offset_next_write
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...
void verboselog(char *fmt,...)
static void store_log_markers(void)
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
char * get_process_filename(const char *prefix)
Returns the name of a temporary file with the specified prefix.
bool get_debug_logging(void)
Checks if debug logging is active.
void debuglog(char *fmt,...)
void set_verbosity(bool _verbose)
Set verbosity of i3.
void errorlog(char *fmt,...)
static void vlog(const bool print, const char *fmt, va_list args)
static bool debug_logging
struct i3_shmlog_header i3_shmlog_header
void set_debug_logging(const bool _debug_logging)
Set debug logging.
void purge_zerobyte_logfile(void)
Deletes the unused log files.
static int logbuffer_size
void close_logbuffer(void)
Closes the logbuffer.
uint32_t offset_last_wrap
static long long physical_mem_bytes
static i3_shmlog_header * header
static char * loglastwrap