[#98621] Re: Function getlogin_r()'s protoype] — Bertram Scharpf <lists@...>
FYI,
3 messages
2020/06/02
[#98947] [Ruby master Feature#16986] Anonymous Struct literal — ko1@...
Issue #16986 has been reported by ko1 (Koichi Sasada).
66 messages
2020/06/26
[#98962] [Ruby master Bug#16988] Kernel.load loads file from current directory without '.' in path — misharinn@...
Issue #16988 has been reported by TheSmartnik (Nikita Misharin).
5 messages
2020/06/26
[#98969] [Ruby master Feature#16994] Sets: shorthand for frozen sets of symbols / strings — marcandre-ruby-core@...
Issue #16994 has been reported by marcandre (Marc-Andre Lafortune).
7 messages
2020/06/26
[#100117] [Ruby master Feature#16994] Sets: shorthand for frozen sets of symbols / strings
— matz@...
2020/09/25
Issue #16994 has been updated by matz (Yukihiro Matsumoto).
[ruby-core:98622] Re: Function getlogin_r()'s protoype]
From:
"Urabe, Shyouhei" <shyouhei@...>
Date:
2020-06-02 06:55:18 UTC
List:
ruby-core #98622
I don't have a FreeBSD box so not sure if this works but... Here you
are a proposed fix:
---
configure.ac | 16 ++++++++++++++++
process.c | 17 ++++++++++++++++-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 71e71dd47a..f96606494f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2618,6 +2618,22 @@ main(int argc, char *argv[])
rb_cv_fork_with_pthread=yes)])
test x$rb_cv_fork_with_pthread = xyes ||
AC_DEFINE(CANNOT_FORK_WITH_PTHREAD)
])
+
+AS_IF([test "$ac_cv_func_getlogin_r" = "yes"], [
+ AC_CACHE_CHECK([if getlogin_r is POSIX compliant],
rb_cv_getlogin_r_is_posix, [
+ RUBY_WERROR_FLAG([
+ AC_TRY_COMPILE([
+@%:@include <unistd.h>
+static int (*conftest)(char *, size_t) = getlogin_r;
+ ], [],
+ [rb_cv_getlogin_r_is_posix=yes],
+ [rb_cv_getlogin_r_is_posix=no])
+ ])
+ ])
+ AS_IF([test "$rb_cv_getlogin_r_is_posix" = yes], [
+ AC_DEFINE(HAVE_POSIX_COMPLIANT_GETLOGIN_R)
+ ])
+])
}
: "runtime section" && {
diff --git a/process.c b/process.c
index e8a786d55e..9ccf8a2db4 100644
--- a/process.c
+++ b/process.c
@@ -5560,6 +5560,21 @@ check_gid_switch(void)
#if defined(HAVE_PWD_H)
+#if HAVE_GETLOING_R
+static inline int
+wrap_getlogin_r(char *ptr, long passed_len)
+{
+#ifdef HAVE_POSIX_COMPLIANT_GETLOGIN_R
+ size_t len = passed_len;
+#else
+ int len = rb_long2int(len);
+#endif
+
+ RUBY_ASSERT(passed_len >= 0);
+ return getlogin_r(ptr, len);
+}
+#endif
+
/**
* Best-effort attempt to obtain the name of the login user, if any,
* associated with the process. Processes not descended from login(1) (or
@@ -5588,7 +5603,7 @@ rb_getlogin(void)
int gle;
errno = 0;
- while ((gle = getlogin_r(login, loginsize)) != 0) {
+ while ((gle = wrap_getlogin_r(login, loginsize)) != 0) {
if (gle == ENOTTY || gle == ENXIO || gle == ENOENT) {
rb_str_resize(maybe_result, 0);
--
2.17.1
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>