chiark / gitweb /
journalctl: reset cached column count on SIGWINCH
authorDave Reisner <dreisner@archlinux.org>
Sat, 22 Sep 2012 16:50:27 +0000 (12:50 -0400)
committerDave Reisner <dreisner@archlinux.org>
Mon, 24 Sep 2012 12:38:03 +0000 (08:38 -0400)
This requires a little bit of tip-toeing around to explicitly avoid
touching the environment from a sig handler. Instead, simply create a
function to reset the var to its "unset" state, allowing the next call
to columns() to recalculate and cache the new value.

src/journal/journalctl.c
src/shared/util.c
src/shared/util.h

index 6b580d430749d423aea39818924018cbad5a32ad..e491c2766230a326f183639a86c2ee0ba5a4fc17 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/poll.h>
 #include <time.h>
 #include <getopt.h>
+#include <signal.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <linux/fs.h>
@@ -175,6 +176,7 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case 'f':
                         arg_follow = true;
+                        signal(SIGWINCH, columns_cache_reset);
                         break;
 
                 case 'o':
index 97f766c33c5b043559472d3b6817d442626c4bc1..e0156868ade4e4259af439ab3fa5b9c77236cfa6 100644 (file)
@@ -70,6 +70,7 @@
 
 int saved_argc = 0;
 char **saved_argv = NULL;
+int parsed_columns = 0;
 
 size_t page_size(void) {
         static __thread size_t pgsz = 0;
@@ -3740,7 +3741,7 @@ int fd_columns(int fd) {
 }
 
 static unsigned columns_cached(bool cached) {
-        static __thread int parsed_columns = 0, env_columns = -1;
+        static __thread int env_columns = -1;
         const char *e;
 
         if (_likely_(parsed_columns > 0 && cached))
@@ -3776,6 +3777,11 @@ unsigned columns_uncached(void) {
         return columns_cached(false);
 }
 
+/* intended to be used as a SIGWINCH sighandler */
+void columns_cache_reset(int signum) {
+        parsed_columns = 0;
+}
+
 int fd_lines(int fd) {
         struct winsize ws;
         zero(ws);
index e1d4735ee38dec94278118343fd89d6b0cba6e69..61b88a8b2e6ad0279dea5ecef46609b72115605a 100644 (file)
@@ -385,6 +385,7 @@ int status_welcome(void);
 int fd_columns(int fd);
 unsigned columns(void);
 unsigned columns_uncached(void);
+void columns_cache_reset(int _unused_ signum);
 
 int fd_lines(int fd);
 unsigned lines(void);