Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 295561 - su - login -c "cmd" does not run "cmd" with a login shell
Summary: su - login -c "cmd" does not run "cmd" with a login shell
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: High normal
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-03 16:34 UTC by Alexey Vlasov
Modified: 2010-01-12 23:43 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Vlasov 2009-12-03 16:34:24 UTC
su - login -c cmd ignores variable environments from rc user files.

Reproducible: Always

Steps to Reproduce:
1. Adding to ~/.bashrc a some user:
echo "export AAA=bbb" >> ~/.bashrc
Contents of the user's catalogue: 
$ ln -s ~/.bashrc .bash_login
$ ln -s ~/.bashrc .profile
$ ls -la
$ ls -l .bash*
Dec  3 19:15 .bash_login -> .bashrc
Dec  3 19:15 .profile -> .bashrc
Nov 13  2008 .bash_logout
Nov 13  2008 .bash_profile
Nov 13  2008 .bashrc
 
$ cat .bash_profile
# /etc/skel/.bash_profile

# This file is sourced by bash for login shells.  The following line
# runs your .bashrc and is recommended by the bash info pages.
[[ -f ~/.bashrc ]] && . ~/.bashrc

Checking:
$ source .bashrc
$ env | grep AAA
AAA=bbb
Here is OK.

2. Run from root:
# su - support -c "env"
SHELL=/bin/bash
TERM=screen
USER=support
PATH=/bin:/usr/bin
PWD=/home/staff/support
SHLVL=1
HOME=/home/staff/support
LOGNAME=support
_=/bin/env

Variable AAA isn't seen anywhere.


Expected Results:  
# su - support -c "env"
SHELL=/bin/bash
TERM=screen
USER=support
PATH=/bin:/usr/bin
PWD=/home/staff/support
SHLVL=1
HOME=/home/staff/support
LOGNAME=support
AAA=bbb
_=/bin/env
Comment 1 Alex Brandt (RETIRED) gentoo-dev 2009-12-18 20:15:27 UTC
Isn't it .bash_profile that gets sourced by a login terminal rather than .bashrc?  What's in the .bash_profile you have laying in that home directory?
Comment 2 Alexey Vlasov 2009-12-28 07:45:32 UTC
I don't know what goes first sourced but wherever I put variables they are ignored. As for .bash_profile contents I wrote it in my initial message.

$ cat .bash_profile
# /etc/skel/.bash_profile

# This file is sourced by bash for login shells.  The following line
# runs your .bashrc and is recommended by the bash info pages.
[[ -f ~/.bashrc ]] && . ~/.bashrc
Comment 3 SpanKY gentoo-dev 2009-12-31 18:17:32 UTC
this is done on purpose.  a login shell implies interactivity, but the -c option implies no interactivity.  you cant have it both ways.

it's trivial to change in the source:
src/su.c:
        /*
         * Use the shell and create an argv
         * with the rest of the command line included.
         */
-       argv[-1] = shellstr;
+       argv[-1] = cp;

feel free to e-mail upstream with your concerns, but i dont believe the current behavior to be a bug
Comment 4 Alexey Vlasov 2010-01-12 13:00:37 UTC
Thank you, the patch solves my problem.

But in case of login non-interactivity should the environment variables be sourced from ~/.bash_profile?
Comment 5 SpanKY gentoo-dev 2010-01-12 23:43:14 UTC
but .bash_profile should be able to assume an interactive shell, which is bad