From: Alexander Turenko <alexander.turenko@tarantool.org> To: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Alexander Turenko <alexander.turenko@tarantool.org>, tarantool-patches@freelists.org Subject: [PATCH 2/2] lua: fix error handling in getpwall and getgrall Date: Sun, 2 Dec 2018 18:57:32 +0300 [thread overview] Message-ID: <41e2e4cf352718091a8f5c3b7b09537ea4723dd3.1543765908.git.alexander.turenko@tarantool.org> (raw) In-Reply-To: <cover.1543765908.git.alexander.turenko@tarantool.org> This commit fixes app-tap/pwd.test.lua test. It seems that the problem appears after updating to glibc-2.28. Related to #3766. --- src/lua/pwd.lua | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/lua/pwd.lua b/src/lua/pwd.lua index 8f17951df..0a6b73395 100644 --- a/src/lua/pwd.lua +++ b/src/lua/pwd.lua @@ -158,22 +158,52 @@ local function getpw(uid) return user end +-- It seems glibc developers threat POSIX in the following way. +-- {set,get,end}pwent() and {set,get,end}grent() functions can set +-- errno to non-zero value that is not listed in the standard in +-- case of success. Errno should be checked after get{pw,gr}ent +-- only when it returns a non-NULL value. +-- +-- https://sourceware.org/bugzilla/show_bug.cgi?id=1969 +-- https://sourceware.org/bugzilla/show_bug.cgi?id=23737 + +local pwent_grent_errno_list = { + errno.EINTR, + errno.EIO, + errno.EMFILE, + errno.ENFILE, +} + +local function is_pwent_grent_errno(e) + for _, v in ipairs(pwent_grent_errno_list) do + if e == v then + return true + end + end + return false +end + local function getpwall() errno(0) ffi.C.setpwent() - if errno() ~= 0 then + if is_pwent_grent_errno(errno()) then return nil end local pws = {} while true do + errno(0) local pw = ffi.C.getpwent() if pw == nil then + if is_pwent_grent_errno(errno()) then + return nil + end break end table.insert(pws, getpw(pw.pw_uid)) end + errno(0) ffi.C.endpwent() - if errno() ~= 0 then + if is_pwent_grent_errno(errno()) then return nil end return pws @@ -182,19 +212,24 @@ end local function getgrall() errno(0) ffi.C.setgrent() - if errno() ~= 0 then + if is_pwent_grent_errno(errno()) then return nil end local grs = {} while true do + errno(0) local gr = ffi.C.getgrent() if gr == nil then + if is_pwent_grent_errno(errno()) then + return nil + end break end table.insert(grs, getpw(gr.gr_gid)) end + errno(0) ffi.C.endgrent() - if errno() ~= 0 then + if is_pwent_grent_errno(errno()) then return nil end return grs -- 2.19.2
next prev parent reply other threads:[~2018-12-02 15:57 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-12-02 15:57 [PATCH 0/2] Glibc 2.28 fixes Alexander Turenko 2018-12-02 15:57 ` [PATCH 1/2] Remove deprecated getaddrinfo() flags Alexander Turenko 2018-12-02 15:57 ` Alexander Turenko [this message] 2018-12-03 8:33 ` [PATCH 2/2] lua: fix error handling in getpwall and getgrall Vladimir Davydov 2018-12-03 15:19 ` Alexander Turenko 2018-12-03 15:29 ` Vladimir Davydov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=41e2e4cf352718091a8f5c3b7b09537ea4723dd3.1543765908.git.alexander.turenko@tarantool.org \ --to=alexander.turenko@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH 2/2] lua: fix error handling in getpwall and getgrall' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox