17#include <sys/socket.h>
32#include <sys/sysctl.h>
98 fprintf(stderr,
"Could not initialize errorlog\n");
102 fprintf(stderr,
"Could not initialize errorlog on %s: %s\n",
105 if (fcntl(fileno(
errorfile), F_SETFD, FD_CLOEXEC)) {
106 fprintf(stderr,
"Could not set close-on-exec flag\n");
112#if defined(__APPLE__)
113 int mib[2] = {CTL_HW, HW_MEMSIZE};
114 size_t length =
sizeof(
long long);
118 sysconf(_SC_PAGESIZE);
146#if defined(__FreeBSD__)
153 fprintf(stderr,
"Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
157#if defined(__OpenBSD__) || defined(__APPLE__)
159 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
163 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
173 fprintf(stderr,
"Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
232static void vlog(
const bool print,
const char *fmt, va_list args) {
235 static char message[4096];
236 static struct tm result;
238 static struct tm *tmp;
244 tmp = localtime_r(&t, &result);
246 len = strftime(message,
sizeof(message),
"%x %X - ", tmp);
259 gettimeofday(&tv, NULL);
260 printf(
"%s%d.%d - ", message, tv.tv_sec, tv.tv_usec);
262 printf(
"%s", message);
266 len += vsnprintf(message + len,
sizeof(message) - len, fmt, args);
267 if (len >=
sizeof(message)) {
268 fprintf(stderr,
"BUG: single log message > 4k\n");
273 len =
sizeof(message);
277 message[len - 2] =
'\n';
291 strncpy(
logwalk, message, len);
297 fwrite(message, len, 1, stdout);
329 vlog(
true, fmt, args);
400 struct sockaddr_un peer;
401 socklen_t len =
sizeof(
struct sockaddr_un);
403 if ((
fd = accept(w->fd, (
struct sockaddr *)&peer, &len)) < 0) {
404 if (errno != EINTR) {
411 (void)fcntl(
fd, F_SETFD, FD_CLOEXEC);
419 DLOG(
"log: new client connected on fd %d\n",
fd);
428 ssize_t n =
writeall(current->
fd, message, len);
void errorlog(char *fmt,...)
void debuglog(char *fmt,...)
bool get_debug_logging(void)
Checks if debug logging is active.
void log_new_client(EV_P_ struct ev_io *w, int revents)
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.
char * current_log_stream_socket_path
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.
void log_broadcast_to_clients(const char *message, size_t len)
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.
ssize_t writeall(int fd, const void *buf, size_t count)
Wrapper around correct write which returns -1 (meaning that write failed) or count (meaning that all ...
void set_nonblock(int sockfd)
Puts the given socket file descriptor into non-blocking mode or dies if setting O_NONBLOCK failed.
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
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...
char * get_process_filename(const char *prefix)
Returns the name of a temporary file with the specified prefix.
#define TAILQ_HEAD(name, type)
#define TAILQ_INSERT_TAIL(head, elm, field)
#define TAILQ_FIRST(head)
#define TAILQ_REMOVE(head, elm, field)
#define TAILQ_NEXT(elm, field)
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_ENTRY(type)
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