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.
#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>
case 'f':
arg_follow = true;
+ signal(SIGWINCH, columns_cache_reset);
break;
case 'o':
int saved_argc = 0;
char **saved_argv = NULL;
+int parsed_columns = 0;
size_t page_size(void) {
static __thread size_t pgsz = 0;
}
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))
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);
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);