[solved] Bad return value upon login ?

If none of the more specific forums is the right place to ask

[solved] Bad return value upon login ?

Postby DoubleHP » 2019-02-11 16:33

Hello.

I have modified my bashrc to add to my prompt the return value of last command. This works fine on most machines, but one.

Upon login, most machines report 0 (true). But one machine reports false. Login process is fine; but inside the tasget host, the prompt reports 1 just at login time.

After digging, I have to this:

Code: Select all
# head /etc/profile
echo 4
return 5


And during login:

Code: Select all
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Feb 11 18:15:26 2019 from 2a01:e35:xx
4
-bash-4.4# echo $?
1
-bash-4.4# echo $?
0
-bash-4.4#


As you see, I was expecting 5, but got 1. How to dig deeper than profile ? who loads profile ? What represents $? on the very first execution of prompt ? Is there a way to force $? to 0 ? for example, ending bashrc with true did not help.
Last edited by DoubleHP on 2019-02-11 20:16, edited 2 times in total.
DoubleHP
 
Posts: 37
Joined: 2016-10-09 08:55

Re: Bed return value upon login ?

Postby bw123 » 2019-02-11 16:54

...but login hasn't exited, so there wouldn't be a value yet? Probably the return/exit code from the last command preceding login...?

Strange issue, not sure where I'd look. Probably syslog, or the journal? Could it be motd? lastlog? just guessing. Anything executed in a startup like ~.bashrc might be another guess.

too busy to look it up...
https://duckduckgo.com/html/?q=linux+pid+last+command
User avatar
bw123
 
Posts: 3787
Joined: 2011-05-09 06:02

Re: Bed return value upon login ?

Postby DoubleHP » 2019-02-11 17:12

So, when logging via ssh, what is run before the bash shell ? And what's the parent ?

I have found that the parent of bash is sshd (user cession).

Is it sshd which prints motd and reads password to know which shell to execute ?
DoubleHP
 
Posts: 37
Joined: 2016-10-09 08:55

Re: Bed return value upon login ?

Postby Head_on_a_Stick » 2019-02-11 19:02

Not sure about ssh but check the FILES section of the bash man page, Debian uses ~/.profile instead of ~/.bash_profile though.

Reserved exit codes are listed here: https://www.tldp.org/LDP/abs/html/exitcodes.html
User avatar
Head_on_a_Stick
 
Posts: 8900
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Bad return value upon login ?

Postby DoubleHP » 2019-02-11 20:16

You are just right.

~/.bashrc was ending with "mesg n", and adding a new line with "true" fixed my issue.

For some reason, this command produces various return values on various machines.

Issue fixed for me. Thanks.

Machines where "mesg n" returns 0 :

Code: Select all
# mesg --help
Usage: mesg [y|n]


Where it returns 1:
Code: Select all
# mesg -V
mesg from util-linux 2.29.2
DoubleHP
 
Posts: 37
Joined: 2016-10-09 08:55


Return to General Questions

Who is online

Users browsing this forum: debianos, YaCy [Bot] and 9 guests

fashionable