You are not logged in.

#1 2015-01-09 10:58:44

drtebi
Member
Registered: 2013-02-09
Posts: 148

[SOLVED] auto-logout of tty1 after logout of desktop env. possible?

I don't know if I am missing something...

I have recently posted here about running X with different screen solutions: https://bbs.archlinux.org/viewtopic.php?id=191255

I now added the auto-login configuration described here and that helps, except that when I logout, I am stuck at the tty1 console again as opposed to going straight back into auto-login and starting X. I know it's just a simple Ctrl+D to logout of the console, but I would prefer to:

- logout of desktop environment
- tty1 auto-logout
- tty1 auto-login

Is there a way to do this?

Last edited by drtebi (2015-01-10 23:48:18)

Offline

#2 2015-01-09 13:14:06

drtebi
Member
Registered: 2013-02-09
Posts: 148

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

I am afraid that this is not possible, unless the root user (or sudo) invokes this?

I found a similar question here: http://superuser.com/questions/69807/wh … ot-under-x

Offline

#3 2015-01-09 13:35:54

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,721
Website

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

How are you starting your X session? Try running whatever starts it with exec.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2015-01-09 14:22:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

drtebi wrote:

I am afraid that this is not possible

We're you even going to wait for an answer?  Wrong, this is most certainly possible.

WorMzy wrote:

Try running whatever starts it with exec.

This is how.

If you're currently calling your 'e2k' and '34k' from the tty, just use 'exec e2k' or 'exec 34k'.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2015-01-10 01:38:30

drtebi
Member
Registered: 2013-02-09
Posts: 148

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Thanks for your replies.

The issue is not how to get the X-session started from the console. It's about how to get it "restarted" after doing a logout from the X-Session.

E.g., I am already inside my desktop environment (Enlightenment in this case), now my script does a modification to the xorg.conf file and then logs me out of Enlightenment. Ideally, I want the script to logout from Enlightenment and once back at the console, start Enlightenment again (this time with the modified xorg.conf file).

As I said before, everything works, except that once logged out of Enlightenment, there seems to be no way to automatically start Enlightenment again.

As far as I can see, this has nothing to do with Enlightenment itself--if you read the stackexchange post, it appears that X does not allow to send commands to the tty, thus a script has no access to it.

But if that is not true... I would love to see an example, as that would really make my script as smooth as it could possibly be.

Offline

#6 2015-01-10 01:51:49

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Again, how do you start your DE in the first place? It does matter.

Last edited by 2ManyDogs (2015-01-10 02:00:25)

Offline

#7 2015-01-10 01:59:59

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

We know what the issue is - but how you start X determines what will happen when it is done.  If you use the exec command as advised, you will be logged out of the tty as soon as X exits, and as you've set up autologin, you will be immediately logged back in.  I have this set up here - it works.

But hey, if you're so sure your problem couldn't possibly be solved, I'll leave you to be unhappy.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2015-01-10 22:28:25

drtebi
Member
Registered: 2013-02-09
Posts: 148

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Trilby wrote:

We know what the issue is - but how you start X determines what will happen when it is done.  If you use the exec command as advised, you will be logged out of the tty as soon as X exits, and as you've set up autologin, you will be immediately logged back in.  I have this set up here - it works.

But hey, if you're so sure your problem couldn't possibly be solved, I'll leave you to be unhappy.

Not in my nature to be unhappy smile

So let me try to give you all the details of my setup:

I have setup autologin to the console, as described in Automatic login to virtual console.

Once logged in at the console, ~/.bash_profile starts my desktop environment Enlightenment.

Here is my ~/.bash_profile:

#
# ~/.bash_profile
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# prompt
export PS1='[\u@\h \W]\$ '

#
# Auto-login to Enlightenment
#
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]
then
  # set default GUI browser
  export BROWSER=firefox
  
  # get RESOLUTION
  source ~/.RESOLUTION
  export RESOLUTION=$RESOLUTION
  # startx with xorg.conf file according to $RESOLUTION
  if [ $RESOLUTION = 'lowres' ]
  then
    echo "starting low-res setup"
    startx -- -config xorg.conf-2k
  else
    echo "starting hi-res setup"
    startx -- -config xorg.conf
  fi
fi

As you can see, I have two different xorg.conf files, one (/etc/X11/xorg.conf) sets up my four-monitor xinerama display, the other (/etc/X11/xorg.conf-2k) sets up a "normal" HD resolution display. These both work as expected.

The file ~/.RESOLUTION simply contains this:

RESOLUTION=hires

~/.bash_profile sources this file and sets the environment variable RESOLUTION, which is then used by ~/.xinitrc

My ~/.xinitrc file contains the following:

#!/bin/sh
#
# ~/.xinitrc
#

# Arch Linux Default
if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

# start Enlightenment according to the
# environment variable RESOLUTION
if [ $RESOLUTION = 'lowres' ]
then
  exec enlightenment_start
else
  exec enlightenment_start -fake-xinerama-screen 3840x2400+0+0
fi

I have created a script called resw that looks like this:

#!/usr/bin/bash
#
# @author: DrTebi@gmail.com
# @since: 2015-01-09
# @version: 0.1
# @bugs: Works but should really also logout of tty1
#
# Script that pops up a zenity list menu
# with a 'lowres' and 'hires' option. When
# either is selected and 'OK' is clicked, the file '~/.RESOLUTION'
# will change it's 'RESOLUTION' value to the one chosen, and
# Enlightenment exits
#
# Now .bash_profile and .xinitrc can use the RESOLUTION value
# to act accordingly.
#
RESOLUTION=`zenity \
  --title="Choose Resolution" \
  --width=680 --height=230 \
  --list --column="Variable" --column="Description" \
  hires "Switch to high resolution [3840x2400]" \
  lowres "Switch to low resolution [1920x1200]"`

if [[ $RESOLUTION = 'hires' ]]
then
  sed -i s/lowres/hires/ ~/.RESOLUTION
  enlightenment_remote -exit
elif [[ $RESOLUTION = 'lowres' ]]
then
  sed -i s/hires/lowres/ ~/.RESOLUTION
  enlightenment_remote -exit
else
  exit 0
fi

As you can probably make out from the comments in that file, this is what happens when I run the script:

- A window with a selection-list pops up where I can choose "hires" or "lowres"
- When I choose either of these, the script rewrites the file ~/.RESOLUTION accordingly
- The script calls Enlightenment's "exit" function, which shuts down Enlightenment
- Restarting Enlightenment now will have ~/.bash_profile and ~/.xinitrc use the value that's set in ~/.RESOLUTION to start Enlightenment with the corresponding xorg.conf or xorg.conf-2k file

Everything works as expected, but what I am trying to accomplish is, that Enlightenment will automatically restart after I use the script above.

A manual logout does that once back at the console (tty1). But I can not seem to trigger that logout from the script.

In other words, everything works as expected, but after the script runs and Enlightenment exits, I have to manually do Ctrl+D to logout, which in turn does the automatic login again.

I know it may sound a bit overkill... but it would really be nice to get this working.

In case you wonder: running a custom xrandr command or script does not work in my case. It did before, when I was running Enlightenment e17, but apparently they changed something—once Enlightenment is in xinerama mode, it stays there, no matter what xrandr sets. I have tried that before, but it didn't work and that's why I came up with the more complicated solution above which uses two different xorg.conf files and a conditional startup command for startx and enlightenment_start

I hope it all makes sense, I would really be happy to find a solution for this...

Offline

#9 2015-01-10 22:40:35

bstaletic
Member
Registered: 2014-02-02
Posts: 658

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

As stated above exec enables what you're asking. Instead of startx use exec startx in your shell profile

Offline

#10 2015-01-10 22:50:45

drtebi
Member
Registered: 2013-02-09
Posts: 148

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Ohhhhhhhh... exec!

But I don't need it in my .bash_profile, but rather in the custom script I wrote. If I put exec logout after the Enlightment exit command, it does logout of the console!

GREAT

It now works. The only modification I made was to add exec logout at the appropriate places in my resw script:

#!/usr/bin/bash
#
# @author: DrTebi@gmail.com
# @since: 2015-01-09
# @version: 0.1
# @bugs: Works but should really also logout of tty1
#
# Script that pops up a zenity list menu
# with a 'lowres' and 'hires' option. When
# either is selected and 'OK' is clicked, the file '~/.RESOLUTION'
# will change it's 'RESOLUTION' value to the one chosen, and
# Enlightenment exits
#
# Now .bash_profile and .xinit can use the RESOLUTION value
# to act accordingly.
#
RESOLUTION=`zenity \
  --title="Choose Resolution" \
  --width=680 --height=230 \
  --list --column="Variable" --column="Description" \
  hires "Switch to high resolution [3840x2400]" \
  lowres "Switch to low resolution [1920x1200]"`

if [[ $RESOLUTION = 'hires' ]]
then
  sed -i s/lowres/hires/ ~/.RESOLUTION
  enlightenment_remote -exit
  exec logout
elif [[ $RESOLUTION = 'lowres' ]]
then
  sed -i s/hires/lowres/ ~/.RESOLUTION
  enlightenment_remote -exit
  exec logout
else
  exit 0
fi

Thanks a lot!

Last edited by drtebi (2015-01-10 22:51:11)

Offline

#11 2015-01-10 22:57:24

bstaletic
Member
Registered: 2014-02-02
Posts: 658

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Remember to prepend solved to topic title.

You could use exec startx in your .bash_profile, but if this works it's fine.

Offline

#12 2015-01-10 23:47:18

drtebi
Member
Registered: 2013-02-09
Posts: 148

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Yes, I will mark it solved.

It works fine now, although once in a while I got "exec logout: command not found" I wonder why that is? It only happens once in a while, I wonder if there is some kind of "race condition"?

I have adapted the scripts a bit, since I realized I don't really need an environment variable, but can rather just source the file ~/.RESOLUTION. I also added exec to the startx command:

~/.bash_profile

#
# ~/.bash_profile
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# prompt
export PS1='[\u@\h \W]\$ '

#
# Auto-login to Enlightenment
#
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]
then
  # set default GUI browser
  export BROWSER=firefox
  
  # get RESOLUTION variable
  source ~/.RESOLUTION
  # startx with xorg.conf file according to $RESOLUTION
  if [[ $RESOLUTION = 'lowres' ]]
  then
    echo "starting low-res setup"
    exec startx -- -config xorg.conf-2k
  elif [[ $RESOLUTION = 'hires' ]]
  then
    echo "starting hi-res setup"
    exec startx -- -config xorg.conf
  else
    echo "~/.RESOLUTION neither set to 'hires' or 'lowres'."
    echo "Check configuration or start X manually."
    exit 1
  fi
fi

~/.xinitrc

#!/bin/sh
#
# ~/.xinitrc
#
# Custom script to start Enlightenment with `hires` or `lowres` resolution.
#
# @author:  DrTebi@gmail.com
# @since:   2014-12-19
# @version: 0.2
#

# Arch Linux Default
if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

# start Enlightenment according to value of ~/.RESOLUTION
source ~/.RESOLUTION
if [[ $RESOLUTION = 'lowres' ]]
then
  exec enlightenment_start
elif [[ $RESOLUTION = 'hires' ]]
then
  exec enlightenment_start -fake-xinerama-screen 3840x2400+0+0
else
  echo "~/.RESOLUTION neither set to 'hires' or 'lowres'."
  echo "Check configuration or use xinit manually."
  exit 1
fi

/usr/local/bin/resw

#!/usr/bin/bash
#
# @author: DrTebi@gmail.com
# @since: 2015-01-09
# @version: 0.2
#
# Script that pops up a zenity list menu
# with a 'lowres' and 'hires' option. When
# either is selected and 'OK' is clicked, the file '~/.RESOLUTION'
# will change it's 'RESOLUTION' value to the one chosen, and
# Enlightenment exits
#
# Now .bash_profile and .xinit can use the RESOLUTION value
# to act accordingly.
#
RESOLUTION=`zenity \
  --title="Choose Resolution" \
  --width=680 --height=230 \
  --list --column="Variable" --column="Description" \
  hires "Switch to high resolution [3840x2400]" \
  lowres "Switch to low resolution [1920x1200]"`

if [[ $RESOLUTION = 'hires' ]]
then
  sed -i s/lowres/hires/ ~/.RESOLUTION
  enlightenment_remote -exit
  exec logout
elif [[ $RESOLUTION = 'lowres' ]]
then
  sed -i s/hires/lowres/ ~/.RESOLUTION
  enlightenment_remote -exit
  exec logout
else
  exit 0
fi

I also wrote a .desktop file, so that I can quickly run this script from the Everything Launcher.

~/.local/share/applications/resw.desktop

[Desktop Entry]
Type=Application
Name=resw
GenericName=Resolution Switcher
Categories=Utility
Keywords=resolution;xorg.conf;switch resolution
Icon=video-display
Comment=A mini-application that allows to switch xorg.conf configurations dynamically
TryExec=/usr/local/bin/resw
Exec=resw

I wonder if I should write a simplified article for the Arch Linux Wiki. I have seen a couple people ask about how to start X with different xorg.conf files. Do you think it would be worth it? It may be too much of a custom setup...

I've never written an article on the wiki though, so I'd have to learn some of the rules first...

Offline

#13 2015-01-11 13:16:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

drtebi wrote:

Ohhhhhhhh... exec!

Yes, like we've been saying all along.

As to the "logout command not found" that's to be expected.  Logout is a shell builtin, you can't 'exec' it.  The only reason your script does what you want is because of a side-effect of that mistake.  Exec replaces the current login shell, so you are logged out as soon as what you try to exec finishes.  Logout finishes immediately, just with an error.  You could just as well put "exec smurfs" there and it would have the same effect.  You should probably put exec at the start of the previous line "exec enlightenment ..."

EDIT: scratch that, the best place - and the place we were saying from the beginning - is just infront of the startx commands in your bash profile.  Just keep those as "exec startx --- whatever.conf" and it will do what you want.  None of the other execs really do any harm, but they're not needed - and if you forget (or seemingly never figured out) what exec actually does, then those extra ones might get in the way of troubleshooting those scripts sometime down the line.

Last edited by Trilby (2015-01-11 13:58:18)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#14 2015-01-11 23:20:15

drtebi
Member
Registered: 2013-02-09
Posts: 148

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Trilby wrote:
drtebi wrote:

Ohhhhhhhh... exec!

Yes, like we've been saying all along.

As to the "logout command not found" that's to be expected.  Logout is a shell builtin, you can't 'exec' it.  The only reason your script does what you want is because of a side-effect of that mistake.  Exec replaces the current login shell, so you are logged out as soon as what you try to exec finishes.  Logout finishes immediately, just with an error.  You could just as well put "exec smurfs" there and it would have the same effect.  You should probably put exec at the start of the previous line "exec enlightenment ..."

EDIT: scratch that, the best place - and the place we were saying from the beginning - is just infront of the startx commands in your bash profile.  Just keep those as "exec startx --- whatever.conf" and it will do what you want.  None of the other execs really do any harm, but they're not needed - and if you forget (or seemingly never figured out) what exec actually does, then those extra ones might get in the way of troubleshooting those scripts sometime down the line.

You are right. If you look at the last post , you can see that I already have the 'exec' in front of the 'startx' command. So I simply took out the 'exec logout' lines and it does indeed work perfectly.

I do have to admit however, that I don't exactly understand how it does that...

My understanding is this:
When the script runs "enlightenment_remote -exit', the X-server is shut down, enlightenment is 'killed' as well, and I am returned to the console. But now what is it that automatically restarts enlightenment? Is it because when I get back to the console, the .bash_profile script is read again, which does the 'startx'? I expected that that wouldn't happen, since I thought '.bash_profile' is only read once (after booting).

So while it all works perfectly now, I would like to understand it too smile

Last edited by drtebi (2015-01-11 23:21:35)

Offline

#15 2015-01-11 23:48:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Exec replaces the current process with the one you specify.  That's it.  Just think about what those processes are.  Your previous setup:

1) Getty configured to autologin spawns bash as a new process
2) Bash configured in your bash_profile to start x spawns startx as a new process
3) Startx reads the xinitrc and runs the commands there.

The key is that when each finishes, they give control back the previous, so when you shut down X (#3) you are dropped back to bash inthe tty.  This is what you wanted to change.  Now, with 'exec startx':

1) Getty configured to autologin spawns bash a a new process
2) Bash configured in your bash_profile to exec startx does not spawn a new process, but instead replaces this one with X.  Now, this second process is startx, it reads your xinitrc and runs the commands there.

Now when you exit enlightenment, there is no shell running, and control is handed back to getty.  Getty is still configured to autologin, so it logs you back in to start the process again.

You can check the output of pstree in X under each condition to see for yourself.  When I startx with a plain 'xinit' from the tty, my pstree output includes the following:

├─login───bash───xinit─┬─Xorg.bin─┬─xf86-video-inte
│                      │          └─{Xorg.bin}

When I startx as I normally do with 'exec xinit', my pstree output includes this (bash is gone):

├─login───xinit─┬─Xorg.bin─┬─xf86-video-inte
│               │          └─{Xorg.bin}

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#16 2015-01-12 12:01:51

drtebi
Member
Registered: 2013-02-09
Posts: 148

Re: [SOLVED] auto-logout of tty1 after logout of desktop env. possible?

Great explanation, thank you.

Now it really all makes sense to me.

I had never seen 'pstree" before, that's nice. 'top' also shows the tree, but not as detailed.

OK, I am perfectly happy with my setup now, it works, and I understand it.

Offline

Board footer

Powered by FluxBB