[前][次][番号順一覧][スレッド一覧]

ruby-changes:64606

From: Nobuyoshi <ko1@a...>
Date: Sat, 26 Dec 2020 09:45:24 +0900 (JST)
Subject: [ruby-changes:64606] dc13bd22bb (master): Ignore failure on unsupported fcntl to drop non-blocking mode

https://git.ruby-lang.org/ruby.git/commit/?id=dc13bd22bb

From dc13bd22bbdbde39332d30930f688205e6a2b4eb Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 15 Dec 2020 23:17:23 +0900
Subject: Ignore failure on unsupported fcntl to drop non-blocking mode

Fixes https://github.com/ruby/ruby/pull/3723

diff --git a/ruby.c b/ruby.c
index fa65c16..949b4b4 100644
--- a/ruby.c
+++ b/ruby.c
@@ -2214,6 +2214,26 @@ load_file_internal(VALUE argp_v) https://github.com/ruby/ruby/blob/trunk/ruby.c#L2214
     return (VALUE)ast;
 }
 
+/* disabling O_NONBLOCK, and returns 0 on success, otherwise errno */
+static inline int
+disable_nonblock(int fd)
+{
+#if defined(HAVE_FCNTL) && defined(F_SETFL)
+    if (fcntl(fd, F_SETFL, 0) < 0) {
+        const int e = errno;
+        ASSUME(e != 0);
+# if defined ENOTSUP
+        if (e == ENOTSUP) return 0;
+# endif
+# if defined B_UNSUPPORTED
+        if (e == B_UNSUPPORTED) return 0;
+# endif
+        return e;
+    }
+#endif
+    return 0;
+}
+
 static VALUE
 open_load_file(VALUE fname_v, int *xflag)
 {
@@ -2263,18 +2283,10 @@ open_load_file(VALUE fname_v, int *xflag) https://github.com/ruby/ruby/blob/trunk/ruby.c#L2283
 	}
 	rb_update_max_fd(fd);
 
-#if defined HAVE_FCNTL && MODE_TO_LOAD != O_RDONLY
-# ifdef ENOTSUP
-#   define IS_SUPPORTED_OP(e) ((e) != ENOTSUP)
-# else
-#   define IS_SUPPORTED_OP(e) ((void)(e), 1)
-# endif
-	/* disabling O_NONBLOCK */
-	if (fcntl(fd, F_SETFL, 0) < 0 && IS_SUPPORTED_OP(e = errno)) {
+	if (MODE_TO_LOAD != O_RDONLY && (e = disable_nonblock(fd)) != 0) {
 	    (void)close(fd);
 	    rb_load_fail(fname_v, strerror(e));
 	}
-#endif
 
 	e = ruby_is_fd_loadable(fd);
 	if (!e) {
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]