17 #include <sys/socket.h>
31 #if defined(__APPLE__)
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);
141 #if defined(__FreeBSD__)
148 fprintf(stderr,
"Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
152 #if defined(__OpenBSD__) || defined(__APPLE__)
154 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
158 fprintf(stderr,
"Could not ftruncate SHM segment for the i3 log: %s\n", strerror(ret));
168 fprintf(stderr,
"Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
227 static void vlog(
const bool print,
const char *fmt, va_list args) {
230 static char message[4096];
231 static struct tm result;
233 static struct tm *tmp;
239 tmp = localtime_r(&t, &result);
241 len = strftime(message,
sizeof(message),
"%x %X - ", tmp);
254 gettimeofday(&tv, NULL);
255 printf(
"%s%d.%d - ", message, tv.tv_sec, tv.tv_usec);
257 printf(
"%s", message);
261 len += vsnprintf(message + len,
sizeof(message) - len, fmt, args);
262 if (len >=
sizeof(message)) {
263 fprintf(stderr,
"BUG: single log message > 4k\n");
268 len =
sizeof(message);
272 message[len - 2] =
'\n';
286 strncpy(
logwalk, message, len);
292 fwrite(message, len, 1, stdout);
322 vlog(
true, fmt, args);
386 struct sockaddr_un peer;
387 socklen_t len =
sizeof(
struct sockaddr_un);
389 if ((
fd = accept(w->fd, (
struct sockaddr *)&peer, &len)) < 0) {
390 if (errno != EINTR) {
397 (void)fcntl(
fd, F_SETFD, FD_CLOEXEC);
405 DLOG(
"log: new client connected on fd %d\n",
fd);
414 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 ...
char * get_process_filename(const char *prefix)
Returns the name of a temporary file with the specified prefix.
void set_nonblock(int sockfd)
Puts the given socket file descriptor into non-blocking mode or dies if setting O_NONBLOCK failed.
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 * 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...
#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