This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libfortran/31299] Use getpwuid(geteuid()) instead of getlogin() for GETLOG()



------- Comment #13 from fxcoudert at gcc dot gnu dot org  2007-03-26 10:33 -------
Below is a patch to use geteuid() and getpwuid(). One minor thing is that
linking with glibc now warns at compile time for static linking:

../../../../trunk/libgfortran/intrinsics/getlog.c:97: warning: Using 'getpwuid'
in statically linked applications requires at runtime the shared libraries from
the glibc version used for linking

I find this warning a bit annoying, as it's not clear for users where it comes
from. Anyway, the patch itself is:

Index: intrinsics/getlog.c
===================================================================
--- intrinsics/getlog.c (revision 123093)
+++ intrinsics/getlog.c (working copy)
@@ -37,8 +37,13 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif

-
 /* Windows32 version */
 #if defined __MINGW32__ && !defined  HAVE_GETLOGIN
 #define WIN32_LEAN_AND_MEAN
@@ -66,7 +71,18 @@
    process.
    CHARACTER(len=*), INTENT(OUT) :: LOGIN  */

-#ifdef HAVE_GETLOGIN
+#if (defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)) ||
defined(HAVE_GETLOGIN)
+
+#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
+# define GETLOG (getpwuid(geteuid())->pw_name)
+#else
+# ifdef HAVE_GETLOGIN
+#  define GETLOG (getlogin())
+# else
+#  error "How on earth did we get here?"
+# endif
+#endif
+
 void PREFIX(getlog) (char *, gfc_charlen_type);
 export_proto_np(PREFIX(getlog));

@@ -78,7 +94,7 @@

   memset (login, ' ', login_len); /* Blank the string.  */

-  p = getlogin ();
+  p = GETLOG;
   if (p == NULL)
     return;

Index: configure.ac
===================================================================
--- configure.ac        (revision 123094)
+++ configure.ac        (working copy)
@@ -164,7 +164,7 @@
 AC_HAVE_HEADERS(stdlib.h stdio.h string.h stddef.h math.h unistd.h signal.h)
 AC_CHECK_HEADERS(time.h sys/params.h sys/time.h sys/times.h sys/resource.h)
 AC_CHECK_HEADERS(sys/types.h sys/stat.h sys/wait.h floatingpoint.h ieeefp.h)
-AC_CHECK_HEADERS(fenv.h fptrap.h float.h execinfo.h)
+AC_CHECK_HEADERS(fenv.h fptrap.h float.h execinfo.h pwd.h)
 AC_CHECK_HEADER([complex.h],[AC_DEFINE([HAVE_COMPLEX_H], [1], [complex.h
exists])])
 GCC_HEADER_STDINT(gstdint.h)

@@ -177,7 +177,7 @@
 AC_CHECK_FUNCS(chdir strerror getlogin gethostname kill link symlink perror)
 AC_CHECK_FUNCS(sleep time ttyname signal alarm ctime clock access fork execl)
 AC_CHECK_FUNCS(wait setmode execvp pipe dup2 close fdopen strcasestr
getrlimit)
-AC_CHECK_FUNCS(gettimeofday)
+AC_CHECK_FUNCS(gettimeofday getpwuid)

 # Check for glibc backtrace functions
 AC_CHECK_FUNCS(backtrace backtrace_symbols)
@@ -190,6 +190,7 @@
 AC_CHECK_LIB([c],[getpid],[AC_DEFINE([HAVE_GETPID],[1],[libc includes
getpid])])
 AC_CHECK_LIB([c],[getppid],[AC_DEFINE([HAVE_GETPPID],[1],[libc includes
getppid])])
 AC_CHECK_LIB([c],[getuid],[AC_DEFINE([HAVE_GETUID],[1],[libc includes
getuid])])
+AC_CHECK_LIB([c],[geteuid],[AC_DEFINE([HAVE_GETEUID],[1],[libc includes
geteuid])])

 # Check for C99 (and other IEEE) math functions
 # ??? This list seems awful long. Is there a better way to test for these?


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31299


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]