[Pkg-zsh-devel] Bug#794968: zsh: please clear console on logout (if recommended config is used)

Carsten Hey carsten at debian.org
Sat Aug 8 22:55:02 UTC 2015


* Frank Terbeck [2015-08-08 23:51 +0200]:
> Carsten Hey wrote:
> > Please clear console on logout if the recommended config for new users
> > is used.
>
> I think this should be doable with a zshexit hook like this:
>
>     function debian_clear_upon_exit () {
>         clear
>     }
>     add-zsh-hook zshexit debian_clear_upon_exit

Interesting :)  This could indeed avoid the need to ship a .zlogout for
new users.  (An ugly alternative would be to set some variable and clear
consoles in /etc/zsh/zlogout if this variable is set.)

By console I meant the thing you get if you press Ctrl-Alt-F1.  The
usual use case is to clear the console on logout for privacy reasons (an
other one is that the user might not want to be annoyed by things she/he
did in previous sessions whilst logging in again).

A minimal console_clear implementation with some tiny bugs could be
(this might fail to compile):

    #include "required_headers.h"

    void main(void) {
        int mode;
        if (ioctl(STDOUT_FILENO, KDGKBMODE, &mode) != 0)
            exit(EXIT_SUCCESS); /* not a console, exit successfully */
        if (access("/usr/bin/clear", R_OK | X_OK) == 0)
            execl("/usr/bin/clear", "/usr/bin/clear", (char *) NULL);
        exit(EXIT_FAILURE);
    }

To meet the requirements of this use case, but not clearing the terminal
if it is not required, the shell needs to check if the terminal is
a console (or rather let clear_console do this check), ensure that it is
not a subshell and check that ${0##*/} does not match (-su|su).  Also
checking if $SSH_CONNECTION is set would avoid some useless calls to
console_clear.

console_clear could be replaced by checking $(tty) and running clear if
the output indicates that the terminal is a console.  But relying on
ttyname() and correctly interpreting its result is not the clean
solution I would prefer.  I'd rather wait until doko has the time to fix
/usr/bin/clear_console, i.e., presumably after the gcc transition is
done.  Nevertheless, using an zshexit hook seems to be worth
considering.


Carsten



More information about the Pkg-zsh-devel mailing list