Skip to content
Snippets Groups Projects
Commit efccac69 authored by Alexander Turenko's avatar Alexander Turenko Committed by Vladimir Davydov
Browse files

lua: fix error handling in getpwall and getgrall

This commit fixes app-tap/pwd.test.lua test. It seems that the problem
appears after updating to glibc-2.28.

It seems that usual way to handle errors in Unix is to check errno only
when a return value indicates possibility of an error.

Related to #3766.
parent b601d0be
No related branches found
No related tags found
No related merge requests found
......@@ -159,44 +159,37 @@ local function getpw(uid)
end
local function getpwall()
errno(0)
ffi.C.setpwent()
if errno() ~= 0 then
return nil
end
local pws = {}
while true do
errno(0)
local pw = ffi.C.getpwent()
if pw == nil then
if errno() ~= 0 then
return nil
end
break
end
table.insert(pws, getpw(pw.pw_uid))
end
ffi.C.endpwent()
if errno() ~= 0 then
return nil
end
return pws
end
local function getgrall()
errno(0)
ffi.C.setgrent()
if errno() ~= 0 then
return nil
end
local grs = {}
while true do
local gr = ffi.C.getgrent()
if gr == nil then
if errno() ~= 0 then
return nil
end
break
end
table.insert(grs, getpw(gr.gr_gid))
end
ffi.C.endgrent()
if errno() ~= 0 then
return nil
end
return grs
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment