Add sgetXXent_r() thread-safe variant functions#1363
Draft
alejandro-colomar wants to merge 26 commits into
Draft
Add sgetXXent_r() thread-safe variant functions#1363alejandro-colomar wants to merge 26 commits into
sgetXXent_r() thread-safe variant functions#1363alejandro-colomar wants to merge 26 commits into
Conversation
*get*ent_r() thread-safe variant functions
alejandro-colomar
force-pushed
the
shadow_r
branch
10 times, most recently
from
September 29, 2025 15:37
c6713c5 to
db2f315
Compare
alejandro-colomar
force-pushed
the
shadow_r
branch
3 times, most recently
from
September 29, 2025 20:08
593c73f to
5124f13
Compare
|
|
||
| int e; | ||
| char *p, *end; | ||
| size_t n, lssize, size; |
Check warning
Code scanning / CodeQL
Expression has no effect
|
|
||
| struct group *sgetgrent(const char *s); | ||
| int sgetgrent_r(size_t size; | ||
| const char *restrict s, struct group *restrict grent, |
Check notice
Code scanning / CodeQL
Short global name
| static struct passwd pwent = {}; | ||
|
|
||
| int e; | ||
| size_t size; |
Check warning
Code scanning / CodeQL
Expression has no effect
|
|
||
| struct passwd *sgetpwent(const char *s); | ||
| int sgetpwent_r(size_t size; | ||
| const char *restrict s, struct passwd *restrict pwent, |
Check notice
Code scanning / CodeQL
Short global name
alejandro-colomar
force-pushed
the
shadow_r
branch
5 times, most recently
from
September 30, 2025 07:39
e5f4e87 to
ab412ac
Compare
| sgetgrent(const char *s) | ||
| { | ||
| static char *buf = NULL; | ||
| static struct group grent = {}; |
Check notice
Code scanning / CodeQL
Local variable hides global variable
| static struct subordinate_range sient = {}; | ||
|
|
||
| int e; | ||
| size_t size; |
Check warning
Code scanning / CodeQL
Expression has no effect
| #ifdef ENABLE_SUBIDS | ||
| struct subordinate_range *sgetsient(const char *s); | ||
| int sgetsient_r(size_t size; | ||
| const char *restrict s, struct subordinate_range *restrict sient, |
Check notice
Code scanning / CodeQL
Short global name
*get*ent_r() thread-safe variant functionssgetXXent_r() thread-safe variant functions
alejandro-colomar
force-pushed
the
shadow_r
branch
7 times, most recently
from
October 2, 2025 10:42
2d1b76a to
12b5f03
Compare
alejandro-colomar
force-pushed
the
shadow_r
branch
from
March 4, 2026 16:27
5965d87 to
cdfa384
Compare
alejandro-colomar
force-pushed
the
shadow_r
branch
from
April 12, 2026 08:04
cdfa384 to
05dab1f
Compare
alejandro-colomar
force-pushed
the
shadow_r
branch
from
May 15, 2026 14:08
05dab1f to
ff2ba7e
Compare
This is for consistency with how this is done in sgetsgent(). Now we need to make sure that the list is NULL before the first call, which means that the 'grent' structure must be cleared. Since it's a static object, it's already true, but let's be explicit about it. Since we remember the address of the list in grent.gr_mem (which is static), we don't need to keep 'members' being static too, so we get rid of one static thing. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Imitate how this is done in sgetgrent(). BE CAREFUL: The NULL check needs to be performed after *both* build_list() calls, since we need to make sure that either a NULL or a valid pointer is stored in both .sg_adm and .sg_mem, since we'll call free(3) next time sgetsgent() is called. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Move build_list() to "lib/list.c", where we can reuse it. Signed-off-by: Alejandro Colomar <alx@kernel.org>
In some places we call comma_to_list(), and in others build_list(), and they're essentially the same thing: they transform a comma-separated list into an array of strings. Both of them consider an empty list to have 0 members instead of one. However, they differ in how they treat trailing commas: - comma_to_list() interprets that as an empty field. - build_list() ignores the trailing comma. The behavior of build_list() seems more appropriate, since it allows tools to generate the CSVs more easily. Also, these lists are used to represent user names or group names, so an empty user name makes no sense. This patch makes both functions be more consistent, which will eventually allow us to de-duplicate code. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
get_gid() will fail to parse a number if the field is empty. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This name tells better what this API does. The name has a leading 'a', as it allocates memory, and then 'csv2ls' because it parses a CSV into a list. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
We already use many GNU extensions, so it makes no sense to try to conform to ISO C in this regard. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
The a2i() family of APIs (called a few lines later) already fails for an empty string. We don't need to explicitly reject it. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Remove obvious comments, and improve (or make more consistent) the useful ones. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This will allow compacting the two buffers into one, which in turn, will allow implementing a re-entrant variant of the function. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This is in preparation for a following commit. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This will allow compacting the two buffers into one, which in turn, will allow implementing a re-entrant variant of the function. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This makes this function consistent with the other sgetXXent() functions. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This will allow implementing a re-entrant variant of the function. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This will reduce the diff when adding re-entrant variants of these functions. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This is not guaranteed to work by the C standard, but it's the only thing we can do to have reasonable confidence that a pointer is aligned. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
That change was temporary to allow adding a re-entrant variant of the function with a small diff. Remove it now that it's done. Signed-off-by: Alejandro Colomar <alx@kernel.org>
alejandro-colomar
force-pushed
the
shadow_r
branch
from
July 20, 2026 21:15
ff2ba7e to
54b0543
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Suggested-by: @blm768
Queued after #1272.