diff mbox

policycoreutils/chcat: Add a fallback in case os.getlogin() returns nothing

Message ID 1450046440-25449-1-git-send-email-bigon@bigon.be (mailing list archive)
State Accepted
Headers show

Commit Message

Laurent Bigonville Dec. 13, 2015, 10:40 p.m. UTC
From: Laurent Bigonville <bigon@bigon.be>

Some teminal emulators (like the latest version of gnome-terminal) are
not setting entries in the utmp file, this leads getlogin() to return an
empty string.

Fallback to the name of the user running the chcat process.
---
 policycoreutils/scripts/chcat | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Steve Lawrence Dec. 17, 2015, 2:16 p.m. UTC | #1
On 12/13/2015 05:40 PM, Laurent Bigonville wrote:
> From: Laurent Bigonville <bigon@bigon.be>
> 
> Some teminal emulators (like the latest version of gnome-terminal) are
> not setting entries in the utmp file, this leads getlogin() to return an
> empty string.
> 
> Fallback to the name of the user running the chcat process.

Applied. Thanks.

Also, in the future, please add a Signed-off-by line.

> ---
>  policycoreutils/scripts/chcat | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/policycoreutils/scripts/chcat b/policycoreutils/scripts/chcat
> index ec527e5..472785c 100755
> --- a/policycoreutils/scripts/chcat
> +++ b/policycoreutils/scripts/chcat
> @@ -372,7 +372,10 @@ def listcats():
>  
>  def listusercats(users):
>      if len(users) == 0:
> -        users.append(os.getlogin())
> +        try:
> +            users.append(os.getlogin())
> +        except:
> +            users.append(pwd.getpwuid(os.getuid()).pw_name)
>  
>      verify_users(users)
>      for u in users:
>
diff mbox

Patch

diff --git a/policycoreutils/scripts/chcat b/policycoreutils/scripts/chcat
index ec527e5..472785c 100755
--- a/policycoreutils/scripts/chcat
+++ b/policycoreutils/scripts/chcat
@@ -372,7 +372,10 @@  def listcats():
 
 def listusercats(users):
     if len(users) == 0:
-        users.append(os.getlogin())
+        try:
+            users.append(os.getlogin())
+        except:
+            users.append(pwd.getpwuid(os.getuid()).pw_name)
 
     verify_users(users)
     for u in users: