aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/getlogin.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2010-03-24 17:02:57 -0700
committerUlrich Drepper <drepper@redhat.com>2010-03-24 17:02:57 -0700
commitc8727fa6e5073d28ed6d0eb40a006ac2c1b9f9f3 (patch)
tree23369e9301bb60abd73e4384e7974fa32acd6e57 /sysdeps/unix/getlogin.c
parentfd8ccb0427569ffdfbb70c8828029122f3459160 (diff)
downloadglibc-c8727fa6e5073d28ed6d0eb40a006ac2c1b9f9f3.zip
glibc-c8727fa6e5073d28ed6d0eb40a006ac2c1b9f9f3.tar.gz
glibc-c8727fa6e5073d28ed6d0eb40a006ac2c1b9f9f3.tar.bz2
Fix Linux getlogin{_r,} implementation
The old implementation uses fd 0 to determine the login TTY. This was needed because using /dev/tty it is not possible to deduce the login TTY. For some time now there is the pseudo-file /proc/self/loginuid which directly helps us to find the user. Prefer using this file. It also works if stdin is closed, redirected, or re-opened.
Diffstat (limited to 'sysdeps/unix/getlogin.c')
-rw-r--r--sysdeps/unix/getlogin.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/sysdeps/unix/getlogin.c b/sysdeps/unix/getlogin.c
index 4752685..b0ad97c 100644
--- a/sysdeps/unix/getlogin.c
+++ b/sysdeps/unix/getlogin.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1996, 1997, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,16 +25,20 @@
#include <utmp.h>
+static char name[UT_NAMESIZE + 1];
+
/* Return the login name of the user, or NULL if it can't be determined.
The returned pointer, if not NULL, is good only until the next call. */
+#ifdef STATIC
+STATIC
+#endif
char *
getlogin (void)
{
char tty_pathname[2 + 2 * NAME_MAX];
char *real_tty_path = tty_pathname;
char *result = NULL;
- static char name[UT_NAMESIZE + 1];
struct utmp *ut, line, buffer;
/* Get name of tty connected to fd 0. Return NULL if not a tty or