From ArchWiki
(Redirected from Talk:.xinitrc)
Jump to navigation Jump to search

Running "Notes" Section

The two sets of notes at the bottom of xinitrc#Configuration should be condensed in some way. The first five bullet points all concern which tty X is running on. I could create this as its own subsection, and contain the information there, though I am not entirely convinced that this is necessary/appropriate/needed on this page at all. Would it be more appropriate to merge the relevant sections into the Xorg article, perhaps? Pid1 (talk) 00:30, 26 July 2015 (UTC)

First of all, the first 4 points are inaccurate. Back in 2013, this was indeed handled by the default /etc/X11/xinit/xserverrc, which contained
if [ -z "$XDG_VTNR" ]; then
  exec /usr/bin/X -nolisten tcp "$@"
  exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR
Now it contains only
exec /usr/bin/X -nolisten tcp "$@"
This will be more work than it seemed, we should investigate... Nevertheless, startx handles the vt parameter, but plain xinit doesn't, so I'd say the note is perfectly suitable for this page.
-- Lahwaacz (talk) 08:17, 26 July 2015 (UTC)
Thanks for the insights. I will cross-reference the documentation with what is provided here, and update accordingly. Pid1 (talk) 13:01, 26 July 2015 (UTC)
I've split this off into a new Running section. I think this section should be split into startx and xinit subsections and explain the details of using xinit in a way that is not a block of notes Ziusudra (talk) 00:19, 11 February 2016 (UTC)

propose to add to automatic startx

When combine automatic startx + automatic login to console, it may come to infinite loop/crash if (a) ~/.xinitrc goes wrong somewhere, after editing; or (b) after pacman -Syyu and Xorg crash. I propose to check if the last GUI session (startx session) really last long before start a new one.

if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then
	if [[ -f /tmp/login-check-startx.flag ]]; then
		rm /tmp/login-check-startx.flag
		echo -e "\nFile '/tmp/login-check-startx.flag' found, maybe the last GUI session did not last long!\n"
		## do nothing, start automatic console login
		touch /tmp/login-check-startx.flag
		( sleep 120; rm /tmp/login-check-startx.flag ) &
		exec startx
## Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.

Triplc (talk) 20:42, 20 April 2016 (UTC)

You might do that without the temporary file by simply looking at the age of the log file:
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then
	if [[ ! -e ~/.local/share/xorg/Xorg.0.log || $(find ~/.local/share/xorg/Xorg.0.log -mmin +2) != "" ]]; then
		exec startx
Or even more simply, don't exec startx, check its return code and drop to interactive shell on errors:
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then
	startx && exit
-- Lahwaacz (talk) 21:10, 20 April 2016 (UTC)
Thanks Lahwaacz. But (a) so the age of a file is based on it's creation time, not update time. OK, i did not know that. (b) about the startx exit code, i am not sure that it will correctly set if i edit something wrong in ~/.xinitrc which make GUI session crash
I just tried to change the resolution of X (xrandr...) and ~/.local/share/xorg/Xorg.0.log updated and get the new timestamp Triplc (talk) 21:36, 20 April 2016 (UTC)


there are 2 xinit examples which by themselves do not work as laid out, imo they should be removed and instead an optional note could be put (somewhere) that says something like:

xinit can be executed instead of startx if you know what options to use

otherwise it seems frustrating to recommend examples which will obviously fail --Ubone (talk) 02:29, 12 November 2018 (UTC)

xinit would not obviously fail if you specified the options in xserverrc. If you already have an X server started, you should also pass the :display_number option mentioned in the note after the first example. -- Lahwaacz (talk) 07:35, 12 November 2018 (UTC)
then replace or in #Usage with or if #xserverrc is configured: ? --Ubone (talk) 08:10, 12 November 2018 (UTC)
I think it should be worded in a way to make it clear why xserverrc is relevant, after all the right options can be specified on the command line as well. -- Lahwaacz (talk) 22:04, 12 November 2018 (UTC)

Autostart X at login

Make sure that startx is properly configured.

For Bash, add the following to the bottom of ~/.bash_profile. If the file does not exist, copy a skeleton version from /etc/skel/.bash_profile. For Zsh, add it to ~/.zprofile.

if systemctl -q is-active && [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
  exec startx


This reliably makes X fail to start after a complete restart. It just seems to wait and nothing happens until I enter startx. is default target. Old if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then worked.

Aufkrawall (talk) 16:26, 8 September 2019 (UTC)

Works for me™, I even tried it with Bash. What's the output of systemctl is-active before you start X? -- nl6720 (talk) 16:53, 8 September 2019 (UTC)
I guess it returns "active". Mxfm (talk) 18:32, 8 September 2019 (UTC)
It returns "inactive". It works on my stationary system, but for whatever reason not on my notebook after a full restart. Once X was started manually, it also starts automatically after logging out and in again. Aufkrawall (talk) 18:35, 8 September 2019 (UTC)
In my case it returns "active". I exited X, logout and check this. Anyway, 'systemctl is-active' should not depend on whether X is started via startx. By default on Arch default target is Mxfm (talk) 18:50, 8 September 2019 (UTC)
Something is preventing or delaying the start of, you should really find out what it is. -- nl6720 (talk) 06:32, 9 September 2019 (UTC)
Are you sure this is really needed? If user wants to autostart X at login, he obviously needs to ensure that relevant variables are set. Mxfm (talk) 18:32, 8 September 2019 (UTC)
Afaik it is not required for Plasma to set any variables manually. Aufkrawall (talk) 18:35, 8 September 2019 (UTC)

I would not recommend using XDG_VTNR over /dev/ttyX because in tmux I sometimes observe XDG_VTNR=1, even over SSH. Someone who encountered the same issue: Second, the advantage over /dev/ttyX mentioned in the wiki is that it allows range comparisons (-le 3), which is even more dangerous, because it succeeds if the variable is unset (i.e. [[ "" -le 3 ]] => true), which is usually the case over SSH sessions. Core-problem (talk) 12:30, 9 March 2020 (UTC)