utmp records of tmux

0x0

在 Ubuntu 19.04 (Disco Dingo) 上使用 tmux 的时候,观察到一个问题,在 w 或者 who 的输出里,会有好多条登录信息;如果 pane 开得多,甚至会满屏都是,影响显示效果。在另一台 Ubuntu 16.04.4 LTS (Xenial Xerus) 上,却没有遇到这样的问题。

0x1

感觉上是不同的软件版本、或者是操作系统版本引起的问题。根据搜索到的信息,比如这篇 utmp records are potentially dangerous,基本确认应该是对 utmp 信息的处理不一致。

0x2

查看并对比了 tmux 对应的依赖库:

$ ldd /usr/bin/tmux
        linux-vdso.so.1 (0x00007fff0437f000)
        libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007fca07370000)
        libutempter.so.0 => /lib/x86_64-linux-gnu/libutempter.so.0 (0x00007fca0716d000)
        libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007fca0713f000)
        libevent-2.1.so.6 => /lib/x86_64-linux-gnu/libevent-2.1.so.6 (0x00007fca06eee000)
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fca06ed3000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fca06ce8000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fca06cc5000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fca07427000)

观察到,在高版本的 Ubuntu 里,才出现了对 libutempter.so.0 的依赖。

进一步查看并对比了不同版本的 Ubuntu 里对 tmux 的编译:

--- 2.1/debian/rules    2015-10-19 02:05:15.000000000 +0800
+++ 2.6-3/debian/rules  2017-12-31 00:43:41.000000000 +0800
@@ -1,7 +1,10 @@
 #!/usr/bin/make -f

 export DEB_BUILD_MAINT_OPTIONS=hardening=+all
 export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed

 %:
        dh $@ --parallel --with autoreconf
+
+override_dh_auto_configure:
+       dh_auto_configure -- --enable-utempter

这就能看出问题了。原来,在高版本的 Ubuntu 里编译 tmux 时,打开了 --enable-utempter 编译选项。

0x3

这下问题就清楚了。--enable-utempter 这个编译选项的目的,是 tmux 在创建新的 shell 时,向系统更新一下 utempter。而这里的解决办法,就是下载 tmux 源码,关掉这个编译选项、编译并重新安装即可。

Read More: