命名管道时不显示/etc/motd?

Fir*_*ira 8 linux login gentoo motd

运行 Gentoo 3.4.0

最近听说过 /etc/motd 文件后,我试图让它显示随机的 cowsay 命运。我编写了一些随机的 bash 脚本来充当守护进程,将 /etc/motd 作为命名管道提供,如某些论坛上所见。

我不认为脚本有任何问题,因为 cat'ing 管道工作得很好,但 MOTD 不会在登录时显示(使用常规文件有效)!

fira@nyan ~ % cat /etc/motd
 _______________________________________ 
/ We didn't put in ^^ because then we'd \
| have to keep telling people what it   |
| means, and then we'd have to keep     |
| telling them why it doesn't short     |
| circuit. :-/                          |
|                                       |
| -- Larry Wall in                      |
\ <199707300650.XAA05515@wall.org>      /
 --------------------------------------- 
   \
    \
        .--.
       |o_o |
       |:_/ |
      //   \ \
     (|     | )
    /'\_   _/`\
    \___)=(___/
Run Code Online (Sandbox Code Playgroud)

我错过了一些明显的东西吗?

不使用 .hushlogin 之类的东西,尝试使用多个 shell,管道是可读的 a+r。

Jan*_*der 7

你没有遗漏任何明显的东西。我深入研究了pam_motd模块源代码来解决这个问题。

诀窍是pam_motd执行以下操作/etc/motd

  1. 检查文件的大小。
  2. 分配该大小的缓冲区。
  3. 将整个文件读入缓冲区。
  4. 通过正在使用的任何输出方法输出缓冲区。(毕竟,PAM 是模块化的;不能假设它是终端。)

由于管道没有文件大小,因此在第 1 步失败。

编辑:为什么 PAM 首先关注大小?我想这是为了防止有意或无意的拒绝服务。当PAM检查文件大小时,如果文件大于64kbytes,它也会拒绝输出motd。我想如果有人设法将 DVD 电影文件通过管道传输到 /etc/motd 中,那么任何试图登录系统的人都会非常难过——更不用说可能需要多少内存了。