Difference between revisions of "Talk:Xinit"

From ArchWiki
Jump to: navigation, search
(exec on last line…: re)
(Default tty method: re, close)
 
(60 intermediate revisions by 14 users not shown)
Line 1: Line 1:
== Backgrounding ==
+
== about "&" and "exec" in .xinitrc ==
  
The article points out that any process (e.g. programs and daemons) preceding the 'exec WM/DE' statement should be backgrounded. This sounds logical in order to execute all of the desired statements (included the WM/DM launcher), without waiting for a process to exit. Looking at the file examples (some provided by myself), I noticed that 'xrdb ...' is not backgrounded. This made me test my own [https://github.com/roygbiiv/dotfiles/blob/master/.xinitrc config], without backgrounding anything except the 'xscreensaver' daemon statement, and the results are the same - only I don't have a lot of backgrounded processes when using 'ps -a'. This matter confuses me a little so, my question is: are there any general rule on what processes should be backgrounded in .xinitrc? Starting daemons is one example of processes that should be backgrounded. --[[User:Roygbiv|Roygbiv]] 16:55, 28 August 2011 (EDT)
+
I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- [[User talk:Tom.ty89|Tom.ty89]] 2015-03-17 19:43  (UTC)
:I'm using [https://aur.archlinux.org/packages.php?O=0&K=urxvtcd&do_Search=Go urxvtcd] and it doesn't have to be backgrounded in order for dwm to start. If I use urxvt instead, dwm won't start unless I background urxvt or it starts only after I exit urxvt. -- [[User:Karol|Karol]] 17:13, 28 August 2011 (EDT)
+
::Ok. So it isn't necessary to background all daemon processes. Looking at other processes though, it's not clear to me what to do. In the this talk page:[https://wiki.archlinux.org/index.php/Talk:X_resources xresources] there was an issue with backgrounding xrdb statements for intance. The solution was to not background it. I guess there isn't a general rule for all processes, because it depends how the different processes behave, but it seems backgrounding in most cases is more generally adviced to not override/delay the xinit process. I don't know here, maybe you got some more expericence. -- [[User:Roygbiv|Roygbiv]] 02:04, 29 August 2011 (EDT)
+
  
== exec on last line… ==
+
:Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:54, 17 March 2015 (UTC)
 +
:edit: I saw you already made some changes. Appreciated. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 19:57, 17 March 2015 (UTC)
  
Someone please explain AlexanderR that he shouldn’t revert edits blindly… See https://wiki.archlinux.org/index.php?title=Xinitrc&action=historysubmit&diff=241683&oldid=241177 I’m not up for this little game :( [[User:Stqn|Stqn]] ([[User talk:Stqn|talk]]) 15:15, 28 December 2012 (UTC)
+
::''exec'' for the window manager is necessary if the process forks into background, on the other hand appending ''&'' to other commands is not necessary when the process forks into background. I've tried to [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368632&oldid=368631 clarify that]. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 16:34, 5 April 2015 (UTC)
  
:Eheh don't take it personally :) What AlexanderR means is that the note shouldn't try to teach what happens if a command is in a non-executed code block, and I agree with him.
+
:::I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like {{ic|xrdb -merge ~/.Xresources}} which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 13:57, 7 April 2015 (UTC)
:In order to avoid an edit war, let's try to improve the wording here, my proposal is:
+
 
:{{Note|Make sure to uncomment only one {{ic|exec}} line, since that will be the last command run from the script; all the following lines will just be ignored.}}
+
::::It's a good example (and mentioned in [[X_resources#Parsing_.Xresources]]) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 14:21, 7 April 2015 (UTC)
:-- [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 12:40, 29 December 2012 (UTC)
+
 
 +
:::::I've added [https://wiki.archlinux.org/index.php?title=Xinitrc&diff=368963&oldid=368632]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — [[User:Kynikos|Kynikos]] ([[User talk:Kynikos|talk]]) 02:56, 8 April 2015 (UTC)
 +
 
 +
== 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? [[User:Pid1|Pid1]] ([[User talk:Pid1|talk]]) 00:30, 26 July 2015 (UTC)
 +
 
 +
:First of all, the first 4 points are inaccurate. Back in [https://wiki.archlinux.org/index.php?title=General_troubleshooting&diff=270284&oldid=239571 2013], this was indeed handled by the default {{ic|/etc/X11/xinit/xserverrc}}, which contained {{bc|<nowiki>
 +
#!/bin/sh
 +
if [ -z "$XDG_VTNR" ]; then
 +
  exec /usr/bin/X -nolisten tcp "$@"
 +
else
 +
  exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR
 +
fi
 +
</nowiki>}}
 +
:Now it contains only {{bc|<nowiki>
 +
#!/bin/sh
 +
exec /usr/bin/X -nolisten tcp "$@"
 +
</nowiki>}}
 +
:This will be more work than it seemed, we should investigate... Nevertheless, ''startx'' handles the {{ic|vt}} parameter, but plain ''xinit'' doesn't, so I'd say the note is perfectly suitable for this page.
 +
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk: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. [[User:Pid1|Pid1]] ([[User talk: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 [[User:Ziusudra|Ziusudra]] ([[User talk: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.
 +
 
 +
{{bc|1=<nowiki>
 +
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
 +
else
 +
touch /tmp/login-check-startx.flag
 +
( sleep 120; rm /tmp/login-check-startx.flag ) &
 +
exec startx
 +
fi
 +
fi
 +
## Change '/tmp/login-check-startx.flag' to '$HOME/login-check-startx.flag' if you want that check also valid after reboot.
 +
</nowiki>}}
 +
 
 +
[[User:Triplc|Triplc]] ([[User talk: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: {{bc|<nowiki>
 +
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
 +
fi
 +
fi
 +
</nowiki>}}
 +
:Or even more simply, don't {{ic|exec startx}}, check its return code and drop to interactive shell on errors: {{bc|<nowiki>
 +
if [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then
 +
startx && exit
 +
fi
 +
</nowiki>}} -- [[User:Lahwaacz|Lahwaacz]] ([[User talk: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 [[User:Triplc|Triplc]] ([[User talk:Triplc|talk]]) 21:36, 20 April 2016 (UTC)
 +
 
 +
== /etc/profile.d/locale.sh ==
 +
 
 +
Should there be some mention of /etc/profile.d/locale.sh here? I had to add this to my .xinitrc file in order for my locale to load properly when using startx.
 +
 
 +
[[User:Archies|Archies]] ([[User talk:Archies|talk]]) 22:51, 12 September 2016 (UTC)
 +
 
 +
:{{ic|/etc/profile.d/locale.sh}} should be loaded by {{ic|/etc/profile}}. Is the locale loaded at the point you run startx? -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 06:38, 13 September 2016 (UTC)
 +
 
 +
::I went ahead and commented the line out and tested my locale, it is now loaded before and after startx, whereas before /etc/profile.d/locale.sh was run the first time it was certainly not loaded after startx. This is across two separate installs of arch. I don't use a display manager and I did follow the installation guide thoroughly both times. I can't really explain it. This is the issue I was having https://github.com/robbyrussell/oh-my-zsh/issues/3436 and adding locale.sh to my .xinitrc was what solved the issue. It's now commented out and locale still is loaded. I can't explain it. [[User:Archies|Archies]] ([[User talk:Archies|talk]]) 16:38, 13 September 2016 (UTC)
 +
 
 +
== <s>Default tty method</s> ==
 +
 
 +
Regarding [[Xinit#Autostart_X_at_login]], you could allow comparison with {{ic|-le}} and {{ic|tty}} if you first store the result in a variable, then use parameter expansion (this is functional with POSIX shells like dash [http://pubs.opengroup.org/onlinepubs/9699919799//utilities/V3_chap02.html#tag_18_06_02]).
 +
{{bc|1=
 +
tty=$(tty)
 +
if [ -z "$DISPLAY" ] && [ "${tty##*/}" -le 3 ]; then
 +
  exec startx
 +
fi
 +
}}
 +
 
 +
Maybe a bit clunky to use in the note, so we could swap places with {{ic|$XDG_VTNR}} (which unlike ''tty'' depends on a functional logind session). -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 10:02, 16 October 2016 (UTC)
 +
 
 +
:I'm pretty sure you don't want to start X from {{ic|/dev/pts/2}} etc. This could be either graphical terminal, which is excluded by the $DISPLAY test, or screen or tmux or SSH session. -- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 10:20, 16 October 2016 (UTC)
 +
 
 +
::Good point, I hadn't considered that. Closing then -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 10:23, 16 October 2016 (UTC)

Latest revision as of 10:23, 16 October 2016

about "&" and "exec" in .xinitrc

I doubt if they are absolutely/always necessary. It seems appropriate to me to emphasize or explain about them in this page. (I also question a bit about the correctness of the purpose and consequence stated in the explanation) -- Tom.ty89 2015-03-17 19:43 (UTC)

Feel free to make changes as you see fit. I took the existing "explanation" and reworded it for brevity, but it's as horrible as before. -- Alad (talk) 19:54, 17 March 2015 (UTC)
edit: I saw you already made some changes. Appreciated. -- Alad (talk) 19:57, 17 March 2015 (UTC)
exec for the window manager is necessary if the process forks into background, on the other hand appending & to other commands is not necessary when the process forks into background. I've tried to clarify that. -- Lahwaacz (talk) 16:34, 5 April 2015 (UTC)
I can't think of a way to explain this in the article now, but the forking thing is trickier than that: for example, you don't want to fork a command like xrdb -merge ~/.Xresources which usually ends up in xinitrc, otherwise the other applications that are started in the script may not be able to make use of Xresources because of the race condition. — Kynikos (talk) 13:57, 7 April 2015 (UTC)
It's a good example (and mentioned in X_resources#Parsing_.Xresources) - as an upside, xrdb is part of the default xinitrc and the article doesn't mention modifying it. -- Alad (talk) 14:21, 7 April 2015 (UTC)
I've added [1]. I wonder if Tom.ty89 is happy with the current state of the article, can we close this? — Kynikos (talk) 02:56, 8 April 2015 (UTC)

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
#!/bin/sh
if [ -z "$XDG_VTNR" ]; then
  exec /usr/bin/X -nolisten tcp "$@"
else
  exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR
fi
Now it contains only
#!/bin/sh
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
	else
		touch /tmp/login-check-startx.flag
		( sleep 120; rm /tmp/login-check-startx.flag ) &
		exec startx
	fi
fi
## 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
	fi
fi
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
fi
-- 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)

/etc/profile.d/locale.sh

Should there be some mention of /etc/profile.d/locale.sh here? I had to add this to my .xinitrc file in order for my locale to load properly when using startx.

Archies (talk) 22:51, 12 September 2016 (UTC)

/etc/profile.d/locale.sh should be loaded by /etc/profile. Is the locale loaded at the point you run startx? -- Lahwaacz (talk) 06:38, 13 September 2016 (UTC)
I went ahead and commented the line out and tested my locale, it is now loaded before and after startx, whereas before /etc/profile.d/locale.sh was run the first time it was certainly not loaded after startx. This is across two separate installs of arch. I don't use a display manager and I did follow the installation guide thoroughly both times. I can't really explain it. This is the issue I was having https://github.com/robbyrussell/oh-my-zsh/issues/3436 and adding locale.sh to my .xinitrc was what solved the issue. It's now commented out and locale still is loaded. I can't explain it. Archies (talk) 16:38, 13 September 2016 (UTC)

Default tty method

Regarding Xinit#Autostart_X_at_login, you could allow comparison with -le and tty if you first store the result in a variable, then use parameter expansion (this is functional with POSIX shells like dash [2]).

tty=$(tty)
if [ -z "$DISPLAY" ] && [ "${tty##*/}" -le 3 ]; then
  exec startx
fi

Maybe a bit clunky to use in the note, so we could swap places with $XDG_VTNR (which unlike tty depends on a functional logind session). -- Alad (talk) 10:02, 16 October 2016 (UTC)

I'm pretty sure you don't want to start X from /dev/pts/2 etc. This could be either graphical terminal, which is excluded by the $DISPLAY test, or screen or tmux or SSH session. -- Lahwaacz (talk) 10:20, 16 October 2016 (UTC)
Good point, I hadn't considered that. Closing then -- Alad (talk) 10:23, 16 October 2016 (UTC)