enable file caching in OpenSC#8799
Conversation
There was a problem hiding this comment.
Code Review
This pull request sets the XDG_CACHE_HOME environment variable to SSS_STATEDIR in both p11_child_common.c and krb5_child.c. However, the error handling for setenv is incorrect because setenv returns -1 on failure rather than a positive errno value. Comparing its return value directly against EOK or assigning it to ret (which expects a valid positive error code in SSSD) is improper. The reviewer suggests checking if the return value is non-zero and setting ret to errno on failure.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the setting of the XDG_CACHE_HOME environment variable to SSS_STATEDIR in both p11_child_common.c and krb5_child.c. The review feedback correctly identifies that the return value of setenv is being compared against EOK instead of standard POSIX return values (where setenv returns 0 on success and -1 on failure). Additionally, the feedback highlights code style inconsistencies, such as 3-space indentation instead of 4-space indentation and missing spaces after commas in function arguments, and provides code suggestions to fix these issues.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| ret = setenv("XDG_CACHE_HOME",SSS_STATEDIR,1); | ||
| if (ret != EOK) { | ||
| ret = errno; | ||
| DEBUG(SSSDBG_MINOR_FAILURE, "Cannot set XDG_CACHE_HOME (%s).\n",strerror(ret)); | ||
| goto done; | ||
| } |
There was a problem hiding this comment.
The return value of setenv should be checked against 0 (or != 0) rather than EOK, as setenv is a standard POSIX function that returns -1 on failure, not an SSSD-specific function returning an errno.
Additionally, please fix the code style issues:
- Use 4-space indentation for the body of the
ifstatement (currently it uses 3 spaces). - Add spaces after commas in function calls (
setenvandstrerror).
ret = setenv("XDG_CACHE_HOME", SSS_STATEDIR, 1);
if (ret != 0) {
ret = errno;
DEBUG(SSSDBG_MINOR_FAILURE, "Cannot set XDG_CACHE_HOME (%s).\n", strerror(ret));
goto done;
}| ret = setenv("XDG_CACHE_HOME",SSS_STATEDIR,1); | ||
| if (ret != EOK) { | ||
| ret = errno; | ||
| DEBUG(SSSDBG_MINOR_FAILURE, "Cannot set XDG_CACHE_HOME (%s).\n",strerror(ret)); | ||
| goto done; | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
The return value of setenv should be checked against 0 (or != 0) rather than EOK, as setenv is a standard POSIX function that returns -1 on failure, not an SSSD-specific function returning an errno.
Additionally, please fix the code style issues:
- Use 4-space indentation for the body of the
ifstatement (currently it uses 3 spaces). - Add spaces after commas in function calls (
setenvandstrerror). - Remove the extra empty line added after the
ifblock.
ret = setenv("XDG_CACHE_HOME", SSS_STATEDIR, 1);
if (ret != 0) {
ret = errno;
DEBUG(SSSDBG_MINOR_FAILURE, "Cannot set XDG_CACHE_HOME (%s).\n", strerror(ret));
goto done;
}
sssd-bot
left a comment
There was a problem hiding this comment.
Review done using Claude Code / claude-opus-4-6
Functional Issues
-
Fatal abort on a non-critical optimization (
p11_child_common.c:323,krb5_child.c:4410): Both call sites usegoto donewhensetenvfails, which aborts the entire child process. SettingXDG_CACHE_HOMEis purely a performance optimization — without it, OpenSC falls back to uncached operation (the current behavior). Asetenvfailure should log a warning and continue, not prevent authentication from working at all. -
Cache location mixes with SSSD state data:
SSS_STATEDIRresolves to/var/lib/sss, which contains LDB caches, keytabs, and other critical SSSD state. OpenSC will write its file cache directly into this directory tree (e.g.,/var/lib/sss/.cache/opensc/), co-mingling third-party cache files with SSSD internal data. Issue 8743 specifically recommends a dedicated directory. Consider using a subdirectory likeSSS_STATEDIR"/opensc_cache"or a path under/var/cache/, and creating it at startup if it doesn't exist. -
Missing SELinux policy: Issue 8743 notes that
p11_childruns in thesssd_tSELinux context, and OpenSC file caching requires write access to the cache directory. On SELinux-enforcing systems (RHEL/Fedora — the primary deployment targets), OpenSC cache writes will be denied by default, silently negating the intended speedup. The PR should include an SELinux policy update or at minimum document that one is needed. -
Unconditional
setenvinkrb5_child(krb5_child.c:4406):krb5_childhandles all Kerberos authentication, not just PKINIT/smart card flows. SettingXDG_CACHE_HOMEfor every Kerberos authentication is unnecessary. This should be conditioned on PKINIT being active (e.g., checkingIS_SC_AUTHTOK(kr->pd->authtok)), or at minimum placed closer to the PKINIT-specific code path to clarify intent. -
Commit message missing
Resolves:and:relnote:: The commit message ("enable file caching in OpenSC") does not reference issue 8743 and is missing a:relnote:tag. This is a user-visible performance improvement for smart card authentication and warrants a release note.
Nits & Non-functional Issues
-
3-space indentation instead of 4 (
p11_child_common.c:321-323,krb5_child.c:4408-4410): The lines inside theifblock use 3-space indentation. The SSSD coding style requires 4 spaces. -
Missing spaces after commas (
p11_child_common.c:319,krb5_child.c:4406):setenv("XDG_CACHE_HOME",SSS_STATEDIR,1)should besetenv("XDG_CACHE_HOME", SSS_STATEDIR, 1). Similarly, the DEBUG format string argumentstrerror(ret))atp11_child_common.c:322andkrb5_child.c:4409is missing a space after the comma separating the format string fromstrerror(ret). -
Extra blank line (
krb5_child.c:4412-4413): There are two consecutive blank lines after the closing brace of theifblock. Only one is needed. -
Semantic mismatch in return value check (
p11_child_common.c:320,krb5_child.c:4407):setenvreturns 0 on success and -1 on error (POSIX convention). Comparing againstEOK(an SSSD error code macro that happens to equal 0) works numerically but is semantically misleading —ret != 0would be more appropriate for a POSIX return value. The subsequentret = errnoassignment is correct.
Review of Existing Review Comments
-
gemini-code-assist comments on
setenvreturn value: These correctly identify that comparingsetenv's return againstEOKis non-idiomatic. However, the claim that the check is "incorrect" overstates the issue — sinceEOKis 0 andsetenvreturns 0 on success, the check functions correctly. Theret = errnoassignment on the error path is also correct. The real concern is semantic clarity, not a bug. -
alexey-tikhonov comment on
strerror(errno)vsstrerror(ret): The current code already usesstrerror(ret)after assigningret = errno, so this appears to have been addressed. The request to "squash into a single patch" is already satisfied — the PR contains a single commit. -
gemini-code-assist style comments (indentation, comma spacing, extra blank line): All valid and confirmed above. These should be fixed.
-
None of the existing comments address the most significant issue: the
goto donecausing a fatal abort for what should be a non-critical optimization failure. This is the highest-priority item to fix.
| "Running with real IDs [%"SPRIuid"][%"SPRIgid"].\n", | ||
| getuid(), getgid()); | ||
|
|
||
| ret = setenv("XDG_CACHE_HOME",SSS_STATEDIR,1); |
There was a problem hiding this comment.
Hi,
thank you for the patch. I think it would be beneficial for future readers to add a short comment here and in krb5_child.c because the connection to OpenSC caching is not obvious.
bye,
Sumit
|
When reading the gemini comments:
So the
If the |
|
I will have a look for a better place for Q: How can I prepare such pull request better in the future? The Gemini and Claude suggestions adds some noise here, I didn't know that they are that chatty. Any way to resolve this (in advance) in my fork? |
Perhaps you can setup Gemini code review in your fork - see https://developers.google.com/gemini-code-assist/resources/faqs |
OpenSC sets
use_file_cachingto public. The speedup by file caching is around the factor of 10. Current sssd does not benefit from this speedup, leading to poor performance for smartcards.This patch:
Issue #8743