https://github.com/systemd/systemd/pull/33252 From 85277a97b222ce19cf951d2c99b1693e8c34fc45 Mon Sep 17 00:00:00 2001 From: Mike Gilbert Date: Fri, 7 Jun 2024 12:28:41 -0400 Subject: [PATCH] user-util: fix fgetxxent_sane on musl musl's implementation does not set errno to ENOENT when the end of file is reached. It returns NULL and leaves errno unchanged. --- src/basic/user-util.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/basic/user-util.c b/src/basic/user-util.c index b3df413be6b06..6bdf5bf1cdc9a 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -977,8 +977,8 @@ int fgetpwent_sane(FILE *stream, struct passwd **pw) { errno = 0; struct passwd *p = fgetpwent(stream); - if (!p && errno != ENOENT) - return errno_or_else(EIO); + if (!p && !IN_SET(errno, 0, ENOENT)) + return -errno; *pw = p; return !!p; @@ -990,8 +990,8 @@ int fgetspent_sane(FILE *stream, struct spwd **sp) { errno = 0; struct spwd *s = fgetspent(stream); - if (!s && errno != ENOENT) - return errno_or_else(EIO); + if (!s && !IN_SET(errno, 0, ENOENT)) + return -errno; *sp = s; return !!s; @@ -1003,8 +1003,8 @@ int fgetgrent_sane(FILE *stream, struct group **gr) { errno = 0; struct group *g = fgetgrent(stream); - if (!g && errno != ENOENT) - return errno_or_else(EIO); + if (!g && !IN_SET(errno, 0, ENOENT)) + return -errno; *gr = g; return !!g; @@ -1017,8 +1017,8 @@ int fgetsgent_sane(FILE *stream, struct sgrp **sg) { errno = 0; struct sgrp *s = fgetsgent(stream); - if (!s && errno != ENOENT) - return errno_or_else(EIO); + if (!s && !IN_SET(errno, 0, ENOENT)) + return -errno; *sg = s; return !!s;