Repository navigation
fix(compgen): -A service reads the system services database - #1188
Merged
Merged
Conversation
…044) GNU bashline.c:2668 bash_servicename_completion_function walks getservent() entries in database order; the only files-backed database was read under cfg(unix) (/etc/services), so on Windows the candidate list fell through to an invented SERVICE/SERVICENAME env-var fallback that never produced real service names and the action was always empty. The Windows resolver's services database lives at %SystemRoot%\System32\drivers\etc\services in the same IANA layout (name / port-proto / aliases / # comments), so services_db_path() selects the platform file and shares the parse: primary name on prefix match else a matching alias, duplicates (tcp/udp pairs) kept. With no readable database the list is empty, matching getservent yielding nothing; the env-var fallback is removed (unpopulated and not a GNU semantic). Verified: compgen -A service -> 277 entries in DB order on this host; prefix/alias filtering and duplicate retention match GNU. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Fixes #1044
Root cause
compgen -A servicewas always empty on Windows. GNUbashline.c:2668bash_servicename_completion_functionwalksgetservent()entries; rubash only read the files-backed database under#[cfg(unix)](/etc/services) and fell through to an inventedSERVICE/SERVICENAME/__RUBASH_SERVICE_NAMESenv-var fallback that nothing ever populates — so the action returned zero candidates.Fix
service_completion_candidatesnow reads the platform services database viaservices_db_path():/etc/serviceson unix,%SystemRoot%\System32\drivers\etc\serviceson Windows — the file the OS resolver itself consults, in the same IANA layout. The parse is shared and keeps GNU's rule: primary name on prefix match, else a matching alias, database order, tcp/udp duplicates kept. With no readable database the list is empty (whatgetserventyields); the env-var fallback is removed.Before / after (this host, Windows services DB, 287-line file)
WSL GNU 5.3.20 on the same repro gives 318 entries from its own
/etc/services— the count is database-dependent; the ordering/duplicate/alias semantics are identical. WSL cannot adjudicate absolute counts (per-host DB), so parity is claimed on the getservent contract, not on line count. The issue's "545-entry fallback DB" on Android is likewise that host's services database, not a compiled-in table — glibc'sgetserventreads/etc/services(or NSS equivalent); there is no built-in fallback list in GNU source.Tests
tests/issue1044_service_completion.rsre-derives the expected list from the on-disk DB under the getservent rule and asserts byte-order equality plus prefix/alias filtering.cargo test --release --test issue1044_service_completion: 2/2 green;cargo test --release --test regression: 78/78 green.Generated with Devin