Repository navigation
logname: add Windows support via WTSQuerySessionInformationW - #15703
Open
armadavalor wants to merge 3 commits into
Open
armadavalor wants to merge 3 commits into
armadavalor wants to merge 3 commits into
Conversation
Fixes uutils#11056 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment was marked as resolved.
This comment was marked as resolved.
Use WTSQuerySessionInformationW(WTSUserName) instead of GetUserNameW so logname reports the user logged on to the session, not the process token's user, matching getlogin on Unix and differing from whoami. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
armadavalor
force-pushed
the
logname-windows
branch
from
October 24, 2026 08:49
bde77b4 to
9dc8bd0
Compare
sylvestre
reviewed
Oct 24, 2026
| let len = (bytes as usize / 2).saturating_sub(1); | ||
| // SAFETY: `buffer` is valid for `len` u16s and is freed right after copying. | ||
| let name = OsString::from_wide(unsafe { std::slice::from_raw_parts(buffer, len) }); | ||
| unsafe { WTSFreeMemory(buffer.cast()) }; |
Contributor
There was a problem hiding this comment.
please add a SAFETY comment here too
This branch has not been deployed
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.
lognamewas Unix-only (libc::getlogin) and listed infeat_require_unix_core, so it was absent from Windows builds.#[cfg(windows)]get_userlogin()usingWTSQuerySessionInformationW(..., WTS_CURRENT_SESSION, WTSUserName): the user logged on to the current session, likegetloginon Unix, rather than the process token's user thatwhoami(GetUserNameW) reports. Session 0 (services) returns an empty name, treated as "no login name".lognamefromfeat_require_unix_coretofeat_Tier1;libcis now a unix-only dependency,windows-sys(Win32_System_RemoteDesktop) a windows-only one.test_output_format: the regex was^\w+\n$, which rejects Windows names likeARMADA-L5-PRO; relaxed to a single non-empty line.Fixes #11056
Verified (Windows 10, local)
cargo test --features logname --no-default-features test_logname:test result: ok. 4 passed; 0 failedcargo clippy -p uu_logname --all-targets -- -D warnings: cleancargo fmt --check: cleanNot verified
runas/ another user, and from a service (session 0).use CStrinside the fn andlibcto a cfg(unix) dep).