Roxysteve
Posts: 7
Joined: Sun Feb 17, 2013 3:09 pm

.profile not being read on login

Mon Mar 18, 2013 7:35 pm

I've been searching the forum for about 30 minutes but can't find this issue discussed anywhere. Apologies if there's a thread I missed - just point me thattaway if that's the case.

Briefly, I have added a bin directory to my home directory (the pi account) and added the path to the c++ include libraries to my .profile but neither the path to the bin directory (which should be added to the PATH env variable by legacy code in the .profile) nor the library path (which I added myself to the PATH setting in that .profile) are being appended/prepended to the PATH variable until I manually source the .profile, at which point everything works as expected.

I have none of the conditions laid out in the comments in the .profile that would preclude its not being run at login.

This problem manifests on boot and upon logging out and logging back in. It is as though the .profile in my home directory just doesn't exist.

The Pi is an early run model B with 256 MB memory (all but 16 meg given to the CPU), a wheezy distro running on a good quality (they claim 30MB/s) 8GB card. The power supply is purpose bought from a Pi supplier, well able to supply the needs of the motherboard, and I'm using a Logitech wired keyboard and wireless mouse which seem to work (though the mouse double click sensitivity needs to be adjusted; like many I'm under-impressed with the mouse characteristics of the Pi).

The whole thing is rather bizarre, and any insights people could offer would be welcome.

Thanks.

User avatar
terrycarlin
Posts: 70
Joined: Thu Jun 14, 2012 10:42 pm

Re: .profile not being read on login

Mon Mar 18, 2013 9:10 pm

The PATH variable is used for searching for executable programs, and shell scripts and usually not for searching libraries.

If you are using the standard GNU c++ compiler, then the include library path is built in. Do a

Code: Select all

g++ -v
to see where they are located.

If you want to include external include libraries you normally put the path to the directory following a -I argument in the g++ command line.
If it ain't broke, take it apart and see how it works.

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: .profile not being read on login

Mon Mar 18, 2013 10:11 pm

Roxysteve wrote:Briefly, I have added a bin directory to my home directory (the pi account) and added the path to the c++ include libraries to my .profile but neither the path to the bin directory (which should be added to the PATH env variable by legacy code in the .profile) nor the library path (which I added myself to the PATH setting in that .profile) are being appended/prepended to the PATH variable until I manually source the .profile, at which point everything works as expected.
How are you logging in? (Text console or GUI, manual or automatic, SSH, VNC.) Does the command "ps $$" show the COMMAND as "-bash", with a leading hyphen to denote a login shell?

Roxysteve
Posts: 7
Joined: Sun Feb 17, 2013 3:09 pm

Re: .profile not being read on login

Mon Mar 18, 2013 10:18 pm

I fear I have not made myself clear.

I understand the role of the PATH variable. What I don't understand is why the .profile defined in $HOME/.profile isn't being sourced at login as it should be.

I do not have the files that would cause the .profile to be ignored defined under any account on the system, so that can't be the issue.

I *looks* like /etc/profile has been executed but not $HOME/.profile

my additions to .profile are two lines, underneath the if clause that checks for the presence of a $HOME/bin directory, and they read:

PATH=$PATH:/usr/include/c++/4.6
export PATH

when this code, along with the legacy code in $HOME/.profile is sourced, it works as expected and I see the bin directory and the library directory properly listed as part of the PATH variable, but the code never seems to execute as part of the login process as it should do.

Thanks.

Roxysteve
Posts: 7
Joined: Sun Feb 17, 2013 3:09 pm

Re: .profile not being read on login

Mon Mar 18, 2013 10:24 pm

jojopi wrote:How are you logging in? (Text console or GUI, manual or automatic, SSH, VNC.) Does the command "ps $$" show the COMMAND as "-bash", with a leading hyphen to denote a login shell?
I am logging in as part of the boot process at first (the pi boots into the GUI as "pi") but also I've tried logging out and logging in again. No dice. I am not allowed to connect to the network here so I'm using the console.

ps $$ shows the command as /bin/bash

Thanks

User avatar
terrycarlin
Posts: 70
Joined: Thu Jun 14, 2012 10:42 pm

Re: .profile not being read on login

Mon Mar 18, 2013 10:35 pm

Try adding your code to ~/.bashrc and see if that works.
If it ain't broke, take it apart and see how it works.

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: .profile not being read on login

Mon Mar 18, 2013 10:47 pm

Roxysteve wrote:ps $$ shows the command as /bin/bash
That is not a login shell, so it does not source .profile. If you had logged in in text mode and run startx, then the parent shell would already have sourced .profile, but a GUI login may not include any login shells.

The Foundation's recent Raspbian images contain a workaround for this issue. Check if you have the file /etc/X11/Xsession.d/75source-profile and if not create it as root with these contents:

Code: Select all

[ -f /etc/profile ] && . /etc/profile
[ -f "$HOME/.profile" ] && . "$HOME/.profile"

Roxysteve
Posts: 7
Joined: Sun Feb 17, 2013 3:09 pm

Re: .profile not being read on login

Tue Mar 19, 2013 9:48 pm

Hmm, well now I cannot log in at all. I give the account name, the password, I get a black screen for a bit and we come full circle to the login screen.

I tried an alternate account I set up but that was showing the same symptom.

Not having another Linux box to hand and not having much worth keeping but a few C noodles, I reimaged the SD card.

That was fun.

Roxysteve
Posts: 7
Joined: Sun Feb 17, 2013 3:09 pm

Re: .profile not being read on login

Mon Mar 25, 2013 7:44 pm

More interesting yet.

I rebuilt the pi and reedited the .profile. Naturally I was still seeing no .profile source aftereffects and not seeing the evidence that bash was a login shell.

So I ran raspi-config and changed the startup behaviour such that startx is now a manual step.

Rebooted and logged in as "pi" - lo and behold I have my .profile modified PATH variable and echo $0 reports "-bash".

I type "startx", open lxterminal and echo $PATH to see...the non-modified PATH variable and echo $0 reports "/bin/bash".

I double check for lunacy, absence of "export PATH" or anything else that occurs to me, but nothing seems obviously wrong. I ran exec startx in the futile hope it would change things but no.

C'est bizarre! It looks for all the world like the startx is provoking a fork that resources the PATH from the system rather than the user account no matter how the process is instructed to come into being. That can't be true, can it? 8o\

Roxysteve
Posts: 7
Joined: Sun Feb 17, 2013 3:09 pm

Re: .profile not being read on login

Tue Mar 26, 2013 9:03 pm

I would just like to thank everyone for supplying the know-how. The modification to 75source-profile worked beautifully once I had removed a line in the existing file properly (ahem).

Thanks for giving me much needed help. I am now in the process of reading the manuals, and I want to thank you all for clearing my immediate problem for me so I could actually begin to get a handle on the X technology. So much more helpful than in many other forums I've participated in over the years.

The only real reason I need the X desktop is that my poor old eyes, burned out from looking at Univac greenscreens for Lo! these many years, need the benefit of 18 point type and black type on white background.

Thank you for giving me back my development environment. I live for the day I can pay this forward.

Steve Mann aka Roxysteve. Old, tired, but far from past it dammit!

BerryPicker
Posts: 177
Joined: Tue Oct 16, 2012 3:03 pm
Location: The East of England

Re: .profile not being read on login

Sat Nov 12, 2016 1:33 pm

My Pi has the workaround identified by jojopi, and X desktop terminals do pick up the PATH environment variable from ~/.profile. But X desktop terminals do not pick up my GOPATH environment variable which is also defined in ~/.profile. I would like each desktop terminal to be aware of GOPATH upon opening.

Edit: A solution I've found is to export the definition of GOPATH in ~/.bashrc. Each new X terminal window I open then already knows of GOPATH.

Return to “Troubleshooting”