Bug 222370

Summary: Wrong $PS1 expansion in auto-started konsole
Product: [Applications] konsole Reporter: Vadym Krevs <vkrevs>
Component: generalAssignee: Konsole Developer <konsole-devel>
Status: RESOLVED WORKSFORME    
Severity: normal CC: adaptee
Priority: NOR    
Version: 2.3.3   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Vadym Krevs 2010-01-12 13:49:01 UTC
Version:           2.3.3 (using 4.3.4 (KDE 4.3.4) "release 2", KDE:KDE4:STABLE:Desktop / openSUSE_11.2)
Compiler:          gcc
OS:                Linux (x86_64) release 2.6.31.8-0.1-default

For various reasons, my system has two users with the same UID, say user1 and user2. Both users use bash, and and the PS1 variable is set to "\n\[\033]0;\w\007\033[32m\]\u@\h \[\033[33m\w\033[0m\]\n$ ". 

I always login into KDE as user1. However, when Konsole is automatically started after login, the prompt in all KOnsole tabs displays "user2@hostname /some/path" not "user1@hostname /some/path". 

Both "id" and "whoami" confirm that I am user1. All other KDE programs see me as user1 not user2. If I start xterm or another konsole instance, then they use user1 as expected.

So the question is: why does the auto-started konsole pick user2 instead of user1?
Comment 1 Kurt Hindenburg 2011-01-23 23:25:32 UTC
On Linux, getpwuid_r is used to get the user name.

What distribution are you using?
Comment 2 Vadym Krevs 2011-01-23 23:31:05 UTC
At the time of bug reporting, opensuse 11.2. Now 11.3. Only the auto-started konsole is affected by this issue. Any subsequently started konsole uses "user1". All other applications also use/display "user1".
Comment 3 Jekyll Wu 2011-08-27 06:00:13 UTC
Maybe I did not set it up correctly, but I could not reproduce this problem.

I created two new accounts 'user1' and 'user2' which are identical except name. 'user1' comes before 'user2' in /etc/passwd. The result was no mater which account was used to log into KDE/GNOMG/XFCE/console, whoami and PS1 always show 'user1', including the session-restored konsole.

I think that is quite rational. getpwuid_r() is used by programs to find the username matching the uid. The manpage does not mention what will happen when multilple names match one uid, but 'returning the first match' seems the natural and actual way.

And even the reported problem can be reproduced, that $PS1 is generated by bash. So the real problem is although bash has the right uid(the uid shared by user1 and user2), it reports the wrong username.