LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Dumb question about .xinitrc (https://www.linuxquestions.org/questions/linux-desktop-74/dumb-question-about-xinitrc-889261/)

Shark82 06-30-2011 04:55 PM

Dumb question about .xinitrc
 
Hi
I have Arch Linux and everything works fine:)
I have been googling around but i can't figure it out if .xinitrc should have executive rights. My .xinitrc works fine with executive rights or without but i am asking this "stupid" qustion just to be sure and to have a calm sleep :)

thx for your answer

frieza 06-30-2011 05:56 PM

not really a stupid question, but you sorta answered your own question without knowing it.

if it works without, then it doesn't need it, in fact i would avoid giving exec privs to anything that works without them (security ya know)

David the H. 06-30-2011 06:02 PM

Configuration files do not generally need to be executable. The programs that import the settings from them just need to be able to read the file.

Shark82 07-01-2011 01:18 AM

Ok, thank you both for answers. For test i have created a new user and the file in new user's home hasn't got executive permission. So i conclude that doesn't need them :)

But he Ubuntu page have somewhat confused :
Quote:

Now make your X session script executable. To do this, type the following command into your terminal:

chmod +x ~/.xinitrc
https://wiki.ubuntu.com/CustomXSession

Karl Godt 07-01-2011 08:30 AM

The security contains also the way a script gets executed I think :
In bash any "exit" inside a "source"ed script can make the parent exit , too .
Sourced scripts need a "return" if needed to not kill the parent (xinit) .

I think I read somewhere it would be "canonical" to make such configuration files executable and put a "#!/bin/sh" on top to make it possible to either execute the script or to source it .

Configuration files are also read by C-command(s) as described here :
http://www.suite101.com/content/c-tu...ommands-a20756

DavidMcCann 07-01-2011 11:49 AM

I've just had a quick look at .bashrc and that's not executable. The question is, how is the file going to be used? If it just contains information that some script is going to utilise, then it doesn't need to be executable; if it is a script, it does. In general, I think the suffix -rc shows that a file isn't a script. You can't judge by the contents; my .bashrc contains commands like "export EDITOR=nano".

MTK358 07-01-2011 12:14 PM

Quote:

Originally Posted by DavidMcCann (Post 4401529)
If it just contains information that some script is going to utilise, then it doesn't need to be executable; if it is a script, it does.

By "script" you mean "executed directly by the OS, without explicitly specifying an interpreter"?

Because I always thought that even if you don't give it executable priveleges, and explicitly pass it to an interpreter, than it's still called a script.

Shark82 07-01-2011 01:08 PM

It is interesting, because i have copied .xinitrc from the /etc/skel and at the beggining it has #!/bin/sh so i tgought that has to have executive permission.
.xinitrc from skel:
Quote:

#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)

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

# exec gnome-session
# exec startkde
# exec startxfce4
# ...or the Window Manager of your choice

DavidMcCann 07-02-2011 11:44 AM

Quote:

Originally Posted by MTK358 (Post 4401555)
By "script" you mean "executed directly by the OS, without explicitly specifying an interpreter"?

By a script, I mean a simple program that runs with an interpreter, and that is a utility (or quick fix) rather than an application. Of course, the OS does not execute scripts; if you don't specify an interpreter, it passes them to your default shell interpreter.

MTK358 07-02-2011 12:55 PM

Quote:

Originally Posted by DavidMcCann (Post 4402570)
By a script, I mean a simple program that runs with an interpreter, and that is a utility (or quick fix) rather than an application.

According to that definition of scripts, the idea that "scripts" need exe permissions and non-scripts don't is wrong.

Executable permissions are needed if the program is a true executable file or if the program is a script with a shebang line and is to be given directly to the OS as if it was an executable file, like this (using the exec system call):
Code:

execl("path/to/script-with-shebang-line", "script-with-shebang-line", NULL);
, or like this (from the shell):
Code:

$ path/to/script-with-shebang-line
.

Executable permissions are not needed if the file is passed as an argument to an interpreter executable, like this (using the exec system call):
Code:

execl("path/to/interpreter", "interpreter", "path/to/script", NULL);
, or like this (in the shell):
Code:

$ path/to/interpreter path/to/script
. Interpreters don't care if their source files are executable.

Shark82 07-02-2011 01:07 PM

So, what about .xinitrc? Is executive permission needed?

ButterflyMelissa 07-02-2011 01:18 PM

Ehrm... xinitrc is your start-up file for X, as the name says x-init-rc...

But, where does that question come from? And...(more importantly) where do you want to get with that question? It is an init file, something else reads it. Arch uses (or better: the X) it to start up the DE (Gnome, XFCE,...), it is started at startx, in turn nudged by whatever is in inittab, mine is set to init3 - the inittab, however has a last line that starts (and sets it to respawn) the XDM for login. As this goes into "graphical" mode - the subsequent startx makes the info in xinitrc relevant, it gets read out and used to go into the required session, it says "exec gnome-session"

In short, xinitrc is read (not executed - so only read rights are needed, for the processes that need this info) by the X11 server, that gets started up by a line in inittab where a graphical login is requested.

Any X-troubles by the way??? :D

Thor

Shark82 07-02-2011 01:23 PM

Hi Thor. It is just a question out of curiousity. I have copied my file from /etc/skel. As you can see above skeleton file has #!/bin/sh so that is why i automatically thought of the need for execution permission.

Beside this i am not experiencing any problem with X.

MTK358 07-02-2011 01:41 PM

Quote:

Originally Posted by Thor_2.0 (Post 4402660)
In short, xinitrc is read (not executed - so only read rights are needed, for the processes that need this info)

I doubt that startx itself reads .xinitrc directly. It's impossible to know if it's read or executed without looking at the startx source code, to see if it's executing .xinitrc or starting a shell instance and passing .xinitrc as an argument to it. Since it works without a shebang line, I bet that the latter is true (and thus executable permissions are not needed).

Shark82 07-02-2011 01:49 PM

Actually when i do startx a do have some errors. The error is:

Quote:

xauth: (stdin):2: unknown command "1cadab1f1b0d45a75624788cdf44254d"


All times are GMT -5. The time now is 05:41 AM.