2 #define I3__FILE__ "log.c"
31 #if defined(__APPLE__)
32 #include <sys/sysctl.h>
84 fprintf(stderr,
"Could not initialize errorlog\n");
87 if (fcntl(fileno(
errorfile), F_SETFD, FD_CLOEXEC)) {
88 fprintf(stderr,
"Could not set close-on-exec flag\n");
111 long long physical_mem_bytes;
112 #if defined(__APPLE__)
113 int mib[2] = {CTL_HW, HW_MEMSIZE};
114 size_t length =
sizeof(
long long);
115 sysctl(mib, 2, &physical_mem_bytes, &length, NULL, 0);
117 physical_mem_bytes = (
long long)sysconf(_SC_PHYS_PAGES) *
118 sysconf(_SC_PAGESIZE);
121 #if defined(__FreeBSD__)
128 fprintf(stderr,
"Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
132 #if defined(__OpenBSD__) || defined(__APPLE__)
134 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
138 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
148 fprintf(stderr,
"Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
157 pthread_condattr_t cond_attr;
158 pthread_condattr_init(&cond_attr);
159 if (pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED) != 0)
160 fprintf(stderr,
"pthread_condattr_setpshared() failed, i3-dump-log -f will not work!\n");
161 pthread_cond_init(&(header->
condvar), &cond_attr);
212 static void vlog(
const bool print,
const char *fmt, va_list args) {
215 static char message[4096];
216 static struct tm result;
218 static struct tm *tmp;
224 tmp = localtime_r(&t, &result);
226 len = strftime(message,
sizeof(message),
"%x %X - ", tmp);
239 gettimeofday(&tv, NULL);
240 printf(
"%s%d.%d - ", message, tv.tv_sec, tv.tv_usec);
242 printf(
"%s", message);
246 len += vsnprintf(message + len,
sizeof(message) - len, fmt, args);
247 if (len >=
sizeof(message)) {
248 fprintf(stderr,
"BUG: single log message > 4k\n");
262 strncpy(
logwalk, message, len);
268 pthread_cond_broadcast(&(header->
condvar));
271 fwrite(message, len, 1, stdout);
299 vlog(
true, fmt, args);
bool get_debug_logging(void)
Checks if debug logging is active.
char * get_process_filename(const char *prefix)
Returns the name of a temporary file with the specified prefix.
static char * loglastwrap
static bool debug_logging
static void vlog(const bool print, const char *fmt, va_list args)
void open_logbuffer(void)
Opens the logbuffer.
static i3_shmlog_header * header
void purge_zerobyte_logfile(void)
Deletes the unused log files.
uint32_t offset_next_write
void set_verbosity(bool _verbose)
Set verbosity of i3.
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 errorlog(char *fmt,...)
void close_logbuffer(void)
Closes the logbuffer.
uint32_t offset_last_wrap
void verboselog(char *fmt,...)
void debuglog(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...
static int logbuffer_size
void set_debug_logging(const bool _debug_logging)
Set debug logging.
struct i3_shmlog_header i3_shmlog_header