Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: Clear terminal on logout + dinit (Read 1053 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Clear terminal on logout + dinit

Using 'reset' / 'tput clear' in .bash_logout seemingly has no effect when using dinit for the system init - viz., initial boot messages and session errors are still visible after logout. I see multiple threads in the subforum related to tty and agetty, but I guess I'm not smart enough to put 2 and 2 together and make it work. I'm using River (git version from AUR) with Wayland if it makes a difference.

It's only a mild security issue, this is a personal machine that sits in a private residence. Still, if anyone has any suggestions I'd appreciate it.

Re: Clear terminal on logout + dinit

Reply #1
I am not using wayland, but maybe my setup is somehow related. I'm logging in system in tty, and in my .bash_profile:
Code: [Select]
[[ -f ~/.bashrc ]] && . ~/.bashrc
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
  startx 2> $HOME/.log/.xsession-errors
  logout
fi
So after login Xorg session autoruns on tty1, and after I exit Xorg session there's immediate logout that clears tty.

Hope it helps.

Re: Clear terminal on logout + dinit

Reply #2
No difference with logout, however I'm also using dbus-run-session to start river so I could try running dbus as a user service it's just a pain

Code: [Select]
[[ -z "${DISPLAY}" && "${XDG_VTNR}" -eq 1 ]] && exec dbus-run-session river && logout

I'm no bash expert but that should be functionally equivalent to your if statement (XDG_VNTR is a systemd-ism but it works with elogind too). If I replace logout with my usual 'reset' I get an interesting error...

Code: [Select]
(EE) failed to read Wayland events: Broken piperor opening current controlling terminal for the process (`/dev/tty'): No such device or address (polkit-error-quark, 0)authentication-".NameHasNoOwneron filerage GL_EXT_texture_shadow_....

Then when I check my tty....

Code: [Select]
echo $(tty)
/dev/pts/0

It's possible I missed a critical step when installing dinit, I was using s6 before... I feel like I'm missing something really dumb if I'm actually running a pseudo-terminal?

Edit: nevermind the last part, I ran it in a terminal emulator...

Edit2: I did try your version at the end of .bash_profile and with both versions I occasionally got a dbus error related to /dev/tty not existing instead, so I don't think it's just a Wayland thing

Re: Clear terminal on logout + dinit

Reply #3
Well. I have openrc, maybe there's difference in tty init or something.

Re: Clear terminal on logout + dinit

Reply #4
So from what I understand you login to a terminal session and have that configured to start your display manager via .bash_profile, and then when you exit the wayland session it's not clearing the screen (which it should do on logout because you've put a reset or equivalent in your .bash_logout)?

If this is what you have in your .bash_profile:

Code: [Select]
[[ -z "${DISPLAY}" && "${XDG_VTNR}" -eq 1 ]] && exec dbus-run-session river && logout

... then the obvious problem is the 'exec'. Once that executes bash isn't running, so the "&& logout" doesn't execute, and the normal bash logout won't function either.

Re: Clear terminal on logout + dinit

Reply #5
It explains why the bash function 'logout' doesn't work (and to be clear, I didn't anticipate that it would, regardless of how I start my Wayland session all user programs including bash will terminate when I logout the first time), however it doesn't explain why the non-bash commands 'tset' and 'tput' generate the same errors for /dev/tty1

In other words, even if I don't 'exec'  /dev/tty1 still doesn't exist when I log out. The core issue remains.

Re: Clear terminal on logout + dinit

Reply #6
I'd like to try and recreate your issue in virtual system. What is your configuration exactly?

Re: Clear terminal on logout + dinit

Reply #7
... however it doesn't explain why the non-bash commands 'tset' and 'tput' generate the same errors for /dev/tty1

You mentioned dbus errors, but 'tset' and 'tput' don't use dbus. Is it possible you misread that error message? (It might also be unrelated).

Quote
In other words, even if I don't 'exec'  /dev/tty1 still doesn't exist when I log out. The core issue remains.

It's not likely that /dev/tty1 doesn't exist - again could you check the error message? Maybe post the exact error message here.

Edit: do you mean this message?

Code: [Select]
(EE) failed to read Wayland events: Broken piperor opening current controlling terminal for the process (`/dev/tty'): No such device or address

That's saying there's no controlling terminal (can't open /dev/tty, not /dev/tty1). It actually looks like a corrupt message ("Broken pipeeror"). But assuming that the problem is that there's no controlling terminal, that means your session is running without a terminal. So I'm guessing it's not actually a terminal login after all? That certainly would explain why 'tset' and 'tput' etc aren't clearing the screen.

Re: Clear terminal on logout + dinit

Reply #8
So I'm guessing it's not actually a terminal login after all? That certainly would explain why 'tset' and 'tput' etc aren't clearing the screen.

That's the weird part, and sorry for not being clearer. It is a terminal login - tty1 must exist, unless I've totally lost it now? Grabbing the whole error is going to be hard, it runs off the screen and I can't find where it's being logged (if anywhere), but I'll see what I can do. I agree that it's probably unrelated to dbus, and it appears unrelated to Wayland to me as well - the constant among the errors are the complaints about /dev/tty.

I'd like to try and recreate your issue in virtual system. What is your configuration exactly?

This was the state of dinit services, bash files, and window manager init prior to the start of this thread.

dinitctl list
Code: [Select]
[[+]     ] boot
[{+}     ] getty
[{+}     ] loginready (has console)
[{+}     ] setup
[{+}     ] cleanup
[{+}     ] fsck
[{+}     ] binfmt
[{+}     ] pseudofs
[{+}     ] locale
[{+}     ] root-rw
[{+}     ] mount-all
[{+}     ] udevd (pid: 1103)
[{+}     ] udevd-early
[{+}     ] tmpfs
[{+}     ] cgroups
[{+}     ] tmpfiles-dev
[{+}     ] kmod-static-nodes
[{+}     ] udev-settle
[{+}     ] udev-trigger
[{+}     ] cryptsetup
[{+}     ] hwclock
[{+}     ] net-lo
[{+}     ] random-seed
[{+}     ] swap
[{+}     ] sysctl
[{+}     ] sysusers
[{+}     ] tmpfiles-setup
[{+}     ] vconsole
[{+}     ] hostname
[{+}     ] mount
[{+}     ] misc
[{+}     ] modules
[{+}     ] network
[{+}     ] network-pre
[{+}     ] rclocal
[{+}     ] logind
[{+}     ] elogind (pid: 1169)
[{+}     ] dbus (pid: 1167)
[{+}     ] dbus-pre
[{+}     ] connmand (pid: 1168)
[{+}     ] firewalld (pid: 1171)
[{+}     ] syslog-ng (pid: 1156)
[{+}     ] dmeventd (pid: 9864)
[{+}     ] haveged (pid: 1163)
[{+}     ] ntpd (pid: 1170)
[{+}     ] cronie (pid: 1172)
[{+}     ] tty1 (pid: 3778)
[{+}     ] tty2 (pid: 1195)
[{+}     ] tty3 (pid: 1196)
[{+}     ] tty4 (pid: 1198)
[{+}     ] tty5 (pid: 1197)
[{+}     ] tty6 (pid: 1199)

.bashrc
Code: [Select]
#
# ~/.bashrc
#

# Return if non-interactive
[[ $- != *i* ]] && return

# Prompt
PS1='[\[\e[38;5;107m\]\u\[\e[0m\]@\h \[\e[38;5;74m\]\w\[\e[0m\]]\$ '

# Aliases
alias diff='diff --color=auto'
alias grep='grep --color=auto'
alias ip='ip -color=auto'
alias ls='ls --color=auto'

alias vim=nvim
alias kssh='/usr/bin/kitty +kitten ssh'
alias wget='wget --hsts-file="${XDG_STATE_HOME}/wget-hsts"'
alias zigup='zigup --install-dir "${XDG_DATA_HOME}/zigup"  --path-link "${HOME}/.local/bin/zig"'
alias pacman-rm-unused='pacman -Qtdq | sudo pacman -Rns -'
alias checkupdates='checkupdates && paru -Qua'

.bash_profile
Code: [Select]
#
# ~/.bash_profile
#

# Default text editors
export EDITOR=nvim
export VISUAL=emacs

# Add ~/.local/bin to $PATH
export PATH="${HOME}/.local/bin:${PATH}"

# XDG Base Directories
export XDG_CACHE_HOME="${HOME}/.cache"
export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_DATA_HOME="${HOME}/.local/share"
export XDG_STATE_HOME="${HOME}/.local/state"

# Force Java to behave when not using a DE
export _JAVA_AWT_WM_NONREPARENTING=1

# GPG passphrase prompt
export GPG_TTY=$(tty)

# Mozilla + Wayland
export MOZ_ENABLE_WAYLAND=1



## No littering in $HOME!

# bash
export HISTFILE="${XDG_STATE_HOME}/bash_history"

# cargo
export CARGO_HOME="${XDG_DATA_HOME}/cargo"

# dotnet
export DOTNET_BUNDLE_EXTRACT_BASE_DIR="${XDG_CACHE_HOME}/dotnet_bundle_extract"
export DOTNET_CLI_HOME="${XDG_DATA_HOME}/dotnet/cli"
export DOTNET_CLI_TELEMETRY_OPTOUT=true
export DOTNET_TOOLS_PATH="${XDG_DATA_HOME}/dotnet/tools"
export PATH="${DOTNET_TOOLS_PATH}:${PATH}"

# go
export GOPATH="${XDG_DATA_HOME}/go"
export GOMODCACHE="${XDG_CACHE_HOME}/go/mod"

# gpg
export GNUPGHOME="${XDG_DATA_HOME}/gnupg"

# gtk2
export GTK2_RC_FILES="${XDG_CONFIG_HOME}/gtk-2.0/gtkrc"

# node
export NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/npmrc"

# python
export PYTHONSTARTUP="${XDG_CONFIG_HOME}/python/pythonrc"
export PYTHONPYCACHEPREFIX="${XDG_CACHE_HOME}/python"
export PYTHONUSERBASE="${XDG_DATA_HOME}/python"

# wine
export WINEPREFIX="${XDG_DATA_HOME}/wine"

# Xorg
export XINITRC="${XDG_CONFIG_HOME}/X11/xinitrc"
export XAUTHORITY="${XDG_RUNTIME_DIR}/Xauthority"

# Source other dotfiles
[[ -f ~/.profile ]] && . ~/.profile

[[ -f ~/.bashrc ]] && . ~/.bashrc

# start river
[[ -z "${DISPLAY}" && "${XDG_VTNR}" -eq 1 ]] && exec dbus-run-session river

.bash_logout
Code: [Select]
#
# ~/.bash_logout
#

reset

.config/river/init
Code: [Select]
#!/bin/bash

# Do some logging
#exec 3>&1 4>&2
#trap 'exec 2>&4 1>&3' 0 1 2 3 RETURN
#exec 1>"${XDG_STATE_HOME}"/river.log 2>&1

# Start kitty
riverctl map normal Super Return spawn kitty

# Start fuzzel
riverctl map normal Super Space spawn fuzzel

# Lock screen
riverctl map normal Control+Alt L spawn 'waylock-launcher'

# Logout
riverctl map normal Super End spawn 'wleave -p layer-shell'
riverctl map locked Super+Alt+Control End spawn 'loginctl kill-session $XDG_SESSION_ID'

# Screenshot entire display to clipboard
riverctl map normal Control Print spawn 'grim -t png - | wl-copy -t image/png'

# Screenshot entire display and save to file
riverctl map normal Super+Control Print spawn 'grim -t png ~/Pictures/screenshot-$(date +%Y-%m-%d_%T).png'

# Screenshot selection to clipboard
riverctl map normal Alt Print spawn 'grim -t png -g "$(slurp -d)" - | wl-copy -t image/png'

# Screenshot selection and save to file
riverctl map normal Super+Alt Print spawn 'grim -t png -g "$(slurp -d)" ~/Pictures/screenshot-$(date +%Y-%m-%d_%T).png'

# Close the focused view
riverctl map normal Super Q close

# Exit river
riverctl map normal Super+Shift E exit

# Focus the next/previous view in the layout stack
riverctl map normal Super N focus-view next
riverctl map normal Super P focus-view previous

# Swap the focused view with the next/previous view in the layout stack
riverctl map normal Super+Alt N swap next
riverctl map normal Super+Alt P swap previous

# Focus the next/previous output
riverctl map normal Super V focus-output next
riverctl map normal Super+Alt V focus-output previous

# Send the focused view to the next/previous output
riverctl map normal Super+Shift Grave send-to-output next
riverctl map normal Super Grave send-to-output previous

# Bump the focused view to the top of the layout stack
riverctl map normal Super+Shift Return zoom

# Increase/decrease the main ratio of rivertile(1)
riverctl map normal Super B send-layout-cmd rivertile "main-ratio -0.05"
riverctl map normal Super F send-layout-cmd rivertile "main-ratio +0.05"

# Increment/decrement the main count of rivertile(1)
riverctl map normal Super+Alt F send-layout-cmd rivertile "main-count +1"
riverctl map normal Super+Alt B send-layout-cmd rivertile "main-count -1"

# Snap views to screen edges
riverctl map normal Super+Alt+Control B snap left
riverctl map normal Super+Alt+Control F snap right
riverctl map normal Super+Alt+Control P snap up
riverctl map normal Super+Alt+Control N snap down

# Resize views
riverctl map normal Super+Alt+Shift B resize horizontal  -100
riverctl map normal Super+Alt+Shift F resize horizontal   100
riverctl map normal Super+Alt+Shift P resize vertical    -100
riverctl map normal Super+Alt+Shift N resize vertical     100

# Move views
riverctl map normal Super+Alt+Control+Shift B move left   100
riverctl map normal Super+Alt+Control+Shift F move right  100
riverctl map normal Super+Alt+Control+Shift P move up     100
riverctl map normal Super+Alt+Control+Shift N move down   100

# Change layout
riverctl map normal Super+Shift B send-layout-cmd rivertile "main-location left"
riverctl map normal Super+Shift F send-layout-cmd rivertile "main-location right"
riverctl map normal Super+Shift P send-layout-cmd rivertile "main-location top"
riverctl map normal Super+Shift N send-layout-cmd rivertile "main-location bottom"

# Move views with mouse
riverctl map-pointer normal Super BTN_LEFT move-view

# Resize views with mouse
riverctl map-pointer normal Super BTN_RIGHT resize-view

# Toggle float with mouse
riverctl map-pointer normal Super BTN_MIDDLE toggle-float

for i in $(seq 1 9)
do
    tags=$((1 << ($i - 1)))

    # Super+[1-9] to focus tag [0-8]
    riverctl map normal Super $i set-focused-tags $tags

    # Super+Shift+[1-9] to tag focused view with tag [0-8]
    riverctl map normal Super+Shift $i set-view-tags $tags

    # Super+Control+[1-9] to toggle focus of tag [0-8]
    riverctl map normal Super+Control $i toggle-focused-tags $tags

    # Super+Shift+Control+[1-9] to toggle tag [0-8] of focused view
    riverctl map normal Super+Shift+Control $i toggle-view-tags $tags
done

# Super+0 to focus all tags
# Super+Shift+0 to tag focused view with all tags
all_tags=$(((1 << 32) - 1))
riverctl map normal Super 0 set-focused-tags $all_tags
riverctl map normal Super+Shift 0 set-view-tags $all_tags

# Toggle float
riverctl map normal Super S toggle-float

# Toggle fullscreen
riverctl map normal Super T toggle-fullscreen

# Declare a passthrough mode. This mode has only a single mapping to return to
# normal mode. This makes it useful for testing a nested wayland compositor
riverctl declare-mode passthrough

# Enter passthrough mode
riverctl map normal Super F11 enter-mode passthrough

# Return to normal mode
riverctl map passthrough Super F11 enter-mode normal

# Set background and border
riverctl background-color 0x323d43
riverctl border-color-focused 0xd8caac
riverctl border-color-unfocused 0x525c62
riverctl border-color-urgent 0xe68183
riverctl border-width 1

# Keyboard repeat rate
riverctl set-repeat 50 300

# Focus on 1st display at login
riverctl focus-output DP-1

# -app-id and title -"foo" start floating
riverctl rule-add -app-id 'Bitwarden' float
riverctl rule-add -app-id 'Blueman-manager' float
riverctl rule-add -add-id 'connman-gtk' float
riverctl rule-add -app-id 'galculator' float
riverctl rule-add -app-id '*KeePassXC' float
riverctl rule-add -app-id 'lutris' float
riverctl rule-add -app-id 'mousepad' float
riverctl rule-add -app-id 'Steam' float
riverctl rule-add -app-id 'vlc' float

# -app-id "bar" and any title use client-side decorations
riverctl rule-add -app-id 'emacs' csd

# Default layout generator - rivertile(1)
riverctl default-layout rivertile
rivertile -view-padding 4 -outer-padding 4 -main-ratio .55 &

# Autostart
dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=river &
/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
#/usr/lib/at-spi-bus-launcher --launch-immediately &
#gnome-keyring-daemon --start --components=pkcs11,secrets,ssh &
kanshi &
pipewire-launcher &
swayidle-launcher &
yambar-launcher &
dunst &
gammastep -r &
river-tag-overlay &
swaybg -m fill -i "${HOME}/Pictures/Wallpapers/dark-forest-path.jpg" &
nextcloud --background &

pacman -Qqe
Code: [Select]
amd-ucode
arkenfox-user.js
artix-archlinux-support
base
base-devel
bat
bitwarden
bluez-dinit
bluez-utils
btrfs-du
btrfs-progs
ccache
chezmoi
clang
connman-dinit
connman-gtk
cronie-dinit
cryptsetup
cryptsetup-dinit
cups-dinit
device-mapper-dinit
dhcpcd-dinit
dinit
dunst
eddie-ui
efibootmgr
efistub-standalone
elogind-dinit
emacs-wayland
everforest-gtk-theme-git
evince
file-roller
firefox
firefox-developer-edition
firewalld-dinit
flake8
fuzzel
fwupd
galculator
gamemode
gammastep
gdb
gimp
git
gnome-keyring
grim
haveged-dinit
htop
hunspell-en_us
hyphen-en
kanshi
keepassxc
kitty
lib32-gamemode
lib32-vkd3d
lib32-vulkan-icd-loader
lib32-vulkan-mesa-layers
lib32-vulkan-radeon
libreoffice-fresh
linux
linux-firmware
linux-headers
linux-zen
linux-zen-headers
logrotate
lutris
man-db
mousepad
mtr
mythes-en
ncdu
neofetch
neovim
nextcloud-client
noto-fonts-cjk
noto-fonts-emoji
openntpd-dinit
openresolv
openssh-dinit
orchis-theme-git
otf-font-awesome
p7zip
pacman-contrib
pamixer
paru-bin
pavucontrol
pipewire
pipewire-pulse
polkit-gnome
prettier
pulseaudio-control
pyright
python-black
python-debugpy
python-protobuf
qogir-gtk-theme-git
qogir-icon-theme
qt5-wayland
qt6-wayland
ristretto
river-git
river-tag-overlay-git
rsync
seahorse
simple-scan
slurp
smartmontools
snapper
spotify
st
strace
swaybg
swayidle
syslog-ng-dinit
thunar
thunar-archive-plugin
thunar-media-tags-plugin
thunar-volman
thunderbird
tmux
tor-browser
ttf-dejavu
ttf-fira-code
ttf-hack
ttf-liberation
ttf-nerd-fonts-symbols
ttf-nerd-fonts-symbols-mono
tutanota-desktop-bin
unrar
valgrind
vim
vimix-gtk-themes-git
vivaldi
vivaldi-ffmpeg-codecs
vkd3d
vlc
vulkan-mesa-layers
vulkan-radeon
vulkan-tools
waybar
waylock
wget
wine
wireplumber
wl-clipboard
wleave-git
wlr-randr
wlroots0.16
wpa_supplicant-dinit
wtype
xdg-desktop-portal-wlr
xdg-ninja
xdg-user-dirs
yambar-wayland
zigup-bin
zls-git

My other Wayland dotfiles are here: https://codeberg.org/andyscott/dotfiles/src/branch/wayland, but I manage them with chezmoi so it can be a little difficult to read where I've done templating. If you need anything else let me know. Thanks.

Re: Clear terminal on logout + dinit

Reply #9
I installed base artix with dinit in virtual machine. Couldn't build river-git, there is some build errors. So I tried with weston. Everything working as expected. .bash_profile:
Code: [Select]
[[ -f ~/.bashrc ]] && . ~/.bashrc
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
  weston
  logout
fi

.bash_logout:
Code: [Select]
#
# ~/.bash_logout
#
reset

Weston autostarts after login and when I "killall weston" in weston terminal it exits weston, logs me out, clears tty and shows login prompt again.

Maybe your issue is with river? How are you closing it? Is there river-specific exit command?

Re: Clear terminal on logout + dinit

Reply #10
Yeah sadly until zig-wlroots gets up to speed it will only build with wlroots 0.16 apparently, oh well

I usually logout/reboot/etc. with elogind commands, ex. loginctl terminate-session $XDG_SESSION_ID. I can tell river to terminate itself with 'riverctl exit' but the result is the same.

It's conceivable that this development build of river is mucking things up, especially with the version bump in wlroots. I just have no way to explain how the exact same version and setup function the way I expect on my laptop with s6. Anyway, I appreciate you taking the time to do that - at least now I know it's probably specific to my machines and not a dinit issue.

I have a copy of the last river package I built but it's too big to upload here by 500kb... if you want to test it I'll figure something out but I don't expect you to devote much more time to this.

Re: Clear terminal on logout + dinit

Reply #11
Ah. So you want to clear your tty when you reboot/shutdown and not on actual bash logout. It is different matter. AFAIK bash handles .bash_logout only if "you explicitly exit the shell with exit or logout" (https://superuser.com/a/410534). Or it definitely was so some time ago, I had similar problem back then. Since then I'm using wrapper script for reboot/shutdown, maybe you should too.

Or you can clear you tty before login and redirect session error messages to a file.

Re: Clear terminal on logout + dinit

Reply #12
Well, what I really want is for the terminal to clear after any logout. Clearing the screen on a reboot is less important to me overall, but a reboot/shutdown will require terminating the users session anyway. As for the functional limitations of the bash command logout, that's why I was using 'reset' instead of 'logout.' Reset works regardless of whether or not bash is running. At least it's supposed to...

I'm liking the idea of a wrapper script(s) - I only use elogind commands with wleave because that's what Artix ships with... I've been wanting to try replacing it with seatd I just never seem to have the time. Redirection could probably work too, the river init file is just a bash script so even if I use exec to replace the login shell I can redirect from within the script. It's a little hacky but at this point if it works then I'm all for it.

 

Re: Clear terminal on logout + dinit

Reply #13
A little script works fine, I feel silly for not trying it earlier. I guess I was just stumped as to why it worked on one system and not another.

For river the important lines are:
Code: [Select]
riverctl spawn 'reset'
riverctl exit

If you run the spawn command with reset/logout in a terminal emulator it doesn't clear that pseudo-terminal, it forks to the background which is perfect.

And not that it matters, but since I already passed control to river via dbus it feels more POSIX-y to logout that way than with systemd stuff anyway. If nothing else I'll hit the 'Solve Topic' button because you helped me be less reliant on elogind :)