26 #if !defined(__OpenBSD__)
30 #if defined(__APPLE__)
31 #include <sys/sysctl.h>
85 fprintf(stderr,
"Could not initialize errorlog\n");
89 fprintf(stderr,
"Could not initialize errorlog on %s: %s\n",
92 if (fcntl(fileno(
errorfile), F_SETFD, FD_CLOEXEC)) {
93 fprintf(stderr,
"Could not set close-on-exec flag\n");
99 #if defined(__APPLE__)
100 int mib[2] = {CTL_HW, HW_MEMSIZE};
101 size_t length =
sizeof(
long long);
105 sysconf(_SC_PAGESIZE);
128 #if defined(__FreeBSD__)
135 fprintf(stderr,
"Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
139 #if defined(__OpenBSD__) || defined(__APPLE__)
141 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
145 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
155 fprintf(stderr,
"Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
164 #if !defined(__OpenBSD__)
165 pthread_condattr_t cond_attr;
166 pthread_condattr_init(&cond_attr);
167 if (pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED) != 0)
168 fprintf(stderr,
"pthread_condattr_setpshared() failed, i3-dump-log -f will not work!\n");
222 static void vlog(
const bool print,
const char *fmt, va_list args) {
225 static char message[4096];
226 static struct tm result;
228 static struct tm *tmp;
234 tmp = localtime_r(&t, &result);
236 len = strftime(message,
sizeof(message),
"%x %X - ", tmp);
249 gettimeofday(&tv, NULL);
250 printf(
"%s%d.%d - ", message, tv.tv_sec, tv.tv_usec);
252 printf(
"%s", message);
256 len += vsnprintf(message + len,
sizeof(message) - len, fmt, args);
257 if (len >=
sizeof(message)) {
258 fprintf(stderr,
"BUG: single log message > 4k\n");
263 len =
sizeof(message);
267 message[len - 2] =
'\n';
281 strncpy(
logwalk, message, len);
286 #if !defined(__OpenBSD__)
292 fwrite(message, len, 1, stdout);
320 vlog(
true, fmt, args);
void errorlog(char *fmt,...)
void debuglog(char *fmt,...)
bool get_debug_logging(void)
Checks if debug logging is active.
static bool debug_logging
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.
static i3_shmlog_header * header
void open_logbuffer(void)
Opens the logbuffer.
void verboselog(char *fmt,...)
void set_verbosity(bool _verbose)
Set verbosity of i3.
void purge_zerobyte_logfile(void)
Deletes the unused log files.
static char * loglastwrap
static void vlog(const bool print, const char *fmt, va_list args)
static long long physical_mem_bytes
static void store_log_markers(void)
void close_logbuffer(void)
Closes the logbuffer.
char * get_process_filename(const char *prefix)
Returns the name of a temporary file with the specified prefix.
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...
struct i3_shmlog_header i3_shmlog_header
Header of the shmlog file.
Header of the shmlog file.
uint32_t offset_last_wrap
uint32_t offset_next_write