# How do I prevent xdm from restarting X once I quit the window manager?



## user6020 (Oct 5, 2019)

I would like to be able to quit the window manager and exit X, but xdm restarts it. What do I have to modify so that this does not happen?


----------



## D-FENS (Oct 5, 2019)

Could you do `service xdm stop` ?


----------



## kpedersen (Oct 5, 2019)

Don't use XDM in the first place.

Instead perhaps log in as a user and immediately run `startx` from your profile scripts if `tty` returns "/dev/tty0"

If you don't want to login, perhaps you could also run `startx` from /etc/rc.local (i.e using `su -l <username> -c startx`)

If you really need XDM for some reason, then yes as roccobaroccoSC mentioned, you could execute `sudo service xdm stop` after the commands in your .xsession file (after configuring `sudo` to be able to run that command passwordless)


----------



## user6020 (Oct 5, 2019)

Thanks for answering. When I do `sudo service xdm stop` it doesn't work. It says `xdm does not exist in /etc/rc.d or the local startup directories (/usr/local/etc/rc.d), or is not executable`. Is there another way?

I'm used to xdm since I also use OpenBSD and startx is disabled there for security reasons. I may change to it though.


----------



## Sevendogsbsd (Oct 5, 2019)

How are you starting XDM?


----------



## gpw928 (Oct 6, 2019)

`grep xdm /etc/ttys` may provide the clue.  If it's "on" change it to "off".


----------



## D-FENS (Oct 6, 2019)

Then you probably use another display manager. I thought XDM because you wrote so.
Try:

```
service sddm stop

service gdm stop

service slim stop
```


----------



## kpedersen (Oct 6, 2019)

user6020 said:


> Thanks for answering. When I do `sudo service xdm stop` it doesn't work.



Ah of course, I forgot. XDM is started by the gettytab / ttys system. Not the services.

You instead might be able to get away with:

`sudo pkill -9 xdm`


----------



## gpw928 (Oct 7, 2019)

kpedersen said:


> `sudo pkill -9 xdm`


That will kill `xdm(8)`, stone dead, but not it's child, `Xorg(1)` (or whatever you use to run your display).

`init(8)` has a mission to constantly respawn `xdm(8)`, in the manner of `getty(8)`.

Killing `xdm(8)` (and all its children) more than once may seen to work, because `init(8)` will eventually refuse to respawn `xdm(8)` too rapidly.  But it will come back after the next reboot.

To "stop the service" edit /etc/ttys, as suggested above.  To make `init(8)` take notice of the change:
	
	



```
sudo init q
```


----------



## kpedersen (Oct 7, 2019)

gpw928 said:


> That will kill `xdm(8)`, stone dead, but not it's child, `Xorg(1)` (or whatever you use to run your display).



I think thats what the OP wants. They want XDM to start on boot but then disappear so if they exit X11, they are returned to the terminal.


----------



## gpw928 (Oct 7, 2019)

kpedersen said:


> I think thats what the OP wants. They want XDM to start on boot but then disappear so if they exit X11, they are returned to the terminal.


To return to the virtual terminal, you have to stop `init` re-spawning `xdm` every time it exits.


----------



## kpedersen (Oct 7, 2019)

I might suggest instead launching xdm using rc.local (and disable it from /etc/ttys) and then it should not get restarted if you pkill -9 it.

However then you might as well just use startx instead.


----------



## Geezer (Oct 8, 2019)

Why don't you start X from crontab :
`@reboot        startx`
And then when you log out of X session, you will be back to the terminal login prompt.


----------



## user6020 (Oct 8, 2019)

Sevendogsbsd said:


> How are you starting XDM?



This is what I did: `pkg install xorg xdm`, and as the handbook says I modified /etc/ttys with `ttyv8   "/usr/local/bin/xdm -nodaemon"  xterm   on secure`.

Then I created a .xsession file with:

```
xterm &
dwm
```

When I boot, the xdm login appears and once I'm authenticated the window manager starts. However, if I close the window manager, the xdm login appears again instead of the system console.


----------



## user6020 (Oct 8, 2019)

gpw928 said:


> `grep xdm /etc/ttys` may provide the clue.  If it's "on" change it to "off".



Isn't the "on" needed if I want xdm to start automatically when I boot? I would like to keep this behavior, but also be able to exit X to the system console just by closing the wm.


----------



## user6020 (Oct 8, 2019)

roccobaroccoSC said:


> Then you probably use another display manager. I thought XDM because you wrote so.
> Try:
> 
> ```
> ...



I only installed XDM and it is the one I'm using. Do you know why `sudo service xdm stop` doesn't work? Thank you.

Edit: Nevermind, I've just read kpedersen answer.


----------



## kpedersen (Oct 8, 2019)

On some setups, both the rc.local and crontab methods will actually leave your X11 session unable to use the keyboard. This is because if they start X before the command prompt login starts up in the background, the login will steal the keyboard input. Something like this is more robust.









						Trouble calling 'startx' in Start-Up Script
					

Hello everyone! This is my first post!  I'm trying to set-up a Thin Client that when booted will automatically log into a server for vnc. Right now, I have a bash shell script at /etc/rc.d/thinclient #!/bin/sh  echo "thinclient script starting..."  SERVER_IP="192.168.1.124"...




					forums.freebsd.org
				




Basically it consists of getting the console login to automatically log a user in, and then the profile script will start X.


----------



## Geezer (Oct 8, 2019)

kpedersen said:


> On some setups, both the rc.local and crontab methods will actually leave your X11 session unable to use the keyboard. This is because if they start X before the command prompt login starts up in the background



`@reboot        { sleep 15 ; startx ; }`


----------



## Sevendogsbsd (Oct 8, 2019)

To me, using xdm only "half" of the time is more work than just booting to a login prompt and using `startx`. Just my opinion though.


----------



## gpw928 (Oct 8, 2019)

user6020 said:


> Isn't the "on" needed if I want xdm to start automatically when I boot? I would like to keep this behavior, but also be able to exit X to the system console just by closing the wm.


They are mutually incompatible goals.  

If you start X11 via `init(8)` with an entry in /etc/ttys, you have to edit /etc/ttys (and `init q`) to stop it.  Otherwise it will re-spawn constantly.

If you start X11 via `startx(1)`, it has to be done manually.  But you will get the console back when it exits.

Are you aware that you can leave X11 running, and switch to a virtual terminal (of the type you get when `xdm(8)` exits) using the Ctrl-Alt-F1 through Ctrl-Alt-F7 key combinations (7 different virtual terminals are available)?


----------



## Deleted member 9563 (Oct 8, 2019)

gpw928 said:


> Are you aware that you can leave X11 running, and switch to a virtual terminal (of the type you get when  xdm(8) exits) using the Ctrl-Alt-F1 through Ctrl-Alt-F7 key combinations (7 different virtual terminals are available)?


That's how I do it. Seems to be the simplest and most direct way to operate.


----------

