retry reading session keyring if it grows

This commit is contained in:
Ilya Priven
2026-10-14 00:19:57 +00:00
parent cef1b2f5dc
commit b85e4988b5

View File

@@ -35,18 +35,18 @@ void
fork_session_keyring(void) fork_session_keyring(void)
{ {
int32_t *keys = NULL; int32_t *keys = NULL;
long size, n = 0, i; long size = 0, n, i;
size = syscall(SYS_keyctl, KEYCTL_READ, KEY_SPEC_SESSION_KEYRING, NULL, /* KEYCTL_READ returns the full size; retry if keys were added. */
0); for (;;) {
if (size > 0) {
keys = xmalloc(size);
n = syscall(SYS_keyctl, KEYCTL_READ, KEY_SPEC_SESSION_KEYRING, n = syscall(SYS_keyctl, KEYCTL_READ, KEY_SPEC_SESSION_KEYRING,
keys, size); keys, size);
if (n > size) if (n <= size)
n = size; break;
n = n > 0 ? n / sizeof *keys : 0; size = n;
keys = xrealloc(keys, size);
} }
n = n > 0 ? n / sizeof *keys : 0;
/* /*
* Link the current session keyring into the thread keyring so we still * Link the current session keyring into the thread keyring so we still