[review] Use getpwuid_r instead of getpwuid when available
Commit Message
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/485
......................................................................
Use getpwuid_r instead of getpwuid when available
Change-Id: I587359267f8963ef1da6ba0223a1525807a721de
---
M gdb/config.in
M gdb/configure
M gdb/gdbserver/config.in
M gdb/gdbserver/configure
M gdb/gdbsupport/common.m4
M gdb/nat/linux-osdata.c
6 files changed, 17 insertions(+), 4 deletions(-)
Comments
Tom Tromey has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/485
......................................................................
Patch Set 2:
(1 comment)
Thank you for this and the other "_r" patches.
I think this one can be hugely simplified, see below.
| --- gdb/nat/linux-osdata.c
| +++ gdb/nat/linux-osdata.c
| @@ -204,11 +204,18 @@ /* Finds the user name for the user UID and copies it into USER. At
|
| static void
| user_from_uid (char *user, int maxlen, uid_t uid)
| {
| - struct passwd *pwentry = getpwuid (uid);
| + struct passwd *pwentry;
| +#ifdef HAVE_GETPWUID_R
| + char buf[1024];
| + struct passwd pwd;
| + getpwuid_r (uid, &pwd, buf, sizeof (buf), &pwentry);
PS2, Line 212:
I think that, because the only use is in a "nat" file,
and because we know this is always available on Linux,
then there's no need for the configury. We can just call
this unconditionally.
| +#else
| + pwentry = getpwuid (uid);
| +#endif
|
| if (pwentry)
| {
| strncpy (user, pwentry->pw_name, maxlen);
| /* Ensure that the user name is null-terminated. */
| user[maxlen - 1] = '\0';
Christian Biesinger has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/485
......................................................................
Patch Set 3:
(1 comment)
| --- gdb/nat/linux-osdata.c
| +++ gdb/nat/linux-osdata.c
| @@ -204,11 +204,18 @@ /* Finds the user name for the user UID and copies it into USER. At
|
| static void
| user_from_uid (char *user, int maxlen, uid_t uid)
| {
| - struct passwd *pwentry = getpwuid (uid);
| + struct passwd *pwentry;
| +#ifdef HAVE_GETPWUID_R
| + char buf[1024];
| + struct passwd pwd;
| + getpwuid_r (uid, &pwd, buf, sizeof (buf), &pwentry);
PS2, Line 212:
Oh good point! Done.
| +#else
| + pwentry = getpwuid (uid);
| +#endif
|
| if (pwentry)
| {
| strncpy (user, pwentry->pw_name, maxlen);
| /* Ensure that the user name is null-terminated. */
| user[maxlen - 1] = '\0';
Tom Tromey has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/485
......................................................................
Patch Set 3: Code-Review+2
Looks good! Thanks.
@@ -186,6 +186,9 @@
/* Define to 1 if you have the `getpgid' function. */
#undef HAVE_GETPGID
+/* Define to 1 if you have the `getpwuid_r' function. */
+#undef HAVE_GETPWUID_R
+
/* Define to 1 if you have the `getrlimit' function. */
#undef HAVE_GETRLIMIT
@@ -13480,7 +13480,7 @@
for ac_func in fdwalk getrlimit pipe pipe2 socketpair sigaction \
- sigprocmask strerror_r
+ sigprocmask strerror_r getpwuid_r
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -114,6 +114,9 @@
/* Define to 1 if you have the `getauxval' function. */
#undef HAVE_GETAUXVAL
+/* Define to 1 if you have the `getpwuid_r' function. */
+#undef HAVE_GETPWUID_R
+
/* Define to 1 if you have the `getrlimit' function. */
#undef HAVE_GETRLIMIT
@@ -6822,7 +6822,7 @@
for ac_func in fdwalk getrlimit pipe pipe2 socketpair sigaction \
- sigprocmask strerror_r
+ sigprocmask strerror_r getpwuid_r
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -33,7 +33,7 @@
dlfcn.h)
AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 socketpair sigaction \
- sigprocmask strerror_r])
+ sigprocmask strerror_r getpwuid_r])
AC_CHECK_DECLS([strerror, strstr])
@@ -205,7 +205,14 @@
static void
user_from_uid (char *user, int maxlen, uid_t uid)
{
- struct passwd *pwentry = getpwuid (uid);
+ struct passwd *pwentry;
+#ifdef HAVE_GETPWUID_R
+ char buf[1024];
+ struct passwd pwd;
+ getpwuid_r (uid, &pwd, buf, sizeof (buf), &pwentry);
+#else
+ pwentry = getpwuid (uid);
+#endif
if (pwentry)
{