Add a patch to make the optional shmlog mechanism works on FreeBSD.

This allows users to use i3-dump-log to gets logs out of i3 is it was run with the shmlog-size parameter set to something greater than 0
This commit is contained in:
Baptiste Daroussin 2013-03-20 17:19:06 +00:00
parent e555bb2656
commit f2d9a5ded5
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=314749
2 changed files with 69 additions and 0 deletions

View File

@ -3,6 +3,7 @@
PORTNAME= i3
DISTVERSION= 4.5.1
PORTREVISION= 1
CATEGORIES= x11-wm
MASTER_SITES= http://i3wm.org/downloads/ \
${MASTER_SITE_LOCAL}

View File

@ -0,0 +1,68 @@
--- ./src/log.c.orig 2013-03-20 15:28:14.746383400 +0100
+++ ./src/log.c 2013-03-20 18:27:56.885378021 +0100
@@ -81,11 +81,11 @@
void init_logging(void) {
if (!errorfilename) {
if (!(errorfilename = get_process_filename("errorlog")))
- ELOG("Could not initialize errorlog\n");
+ fprintf(stderr, "Could not initialize errorlog\n");
else {
errorfile = fopen(errorfilename, "w");
if (fcntl(fileno(errorfile), F_SETFD, FD_CLOEXEC)) {
- ELOG("Could not set close-on-exec flag\n");
+ fprintf(stderr, "Could not set close-on-exec flag\n");
}
}
}
@@ -107,25 +107,28 @@
sysconf(_SC_PAGESIZE);
#endif
logbuffer_size = min(physical_mem_bytes * 0.01, shmlog_size);
- sasprintf(&shmlogname, "/i3-log-%d", getpid());
+#if defined(__FreeBSD__)
+ asprintf(&shmlogname, "/tmp/i3-log-%d", getpid());
+#else
+ asprintf(&shmlogname, "/i3-log-%d", getpid());
+#endif
logbuffer_shm = shm_open(shmlogname, O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
if (logbuffer_shm == -1) {
- ELOG("Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
+ fprintf(stderr, "Could not shm_open SHM segment for the i3 log: %s\n", strerror(errno));
return;
}
-
if (ftruncate(logbuffer_shm, logbuffer_size) == -1) {
close(logbuffer_shm);
- shm_unlink("/i3-log-");
- ELOG("Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
+ shm_unlink(shmlogname);
+ fprintf(stderr, "Could not ftruncate SHM segment for the i3 log: %s\n", strerror(errno));
return;
}
logbuffer = mmap(NULL, logbuffer_size, PROT_READ | PROT_WRITE, MAP_SHARED, logbuffer_shm, 0);
if (logbuffer == MAP_FAILED) {
close(logbuffer_shm);
- shm_unlink("/i3-log-");
- ELOG("Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
+ shm_unlink(shmlogname);
+ fprintf(stderr, "Could not mmap SHM segment for the i3 log: %s\n", strerror(errno));
logbuffer = NULL;
return;
}
@@ -138,13 +141,14 @@
pthread_condattr_t cond_attr;
pthread_condattr_init(&cond_attr);
if (pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED) != 0)
- ELOG("pthread_condattr_setpshared() failed, i3-dump-log -f will not work!\n");
+ fprintf(stderr, "pthread_condattr_setpshared() failed, i3-dump-log -f will not work!\n");
pthread_cond_init(&(header->condvar), &cond_attr);
logwalk = logbuffer + sizeof(i3_shmlog_header);
loglastwrap = logbuffer + logbuffer_size;
store_log_markers();
}
+
atexit(purge_zerobyte_logfile);
}