Skip to content

fix(compgen): -A service reads the system services database - #1188

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/1044-compgen-service
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/1044-compgen-service

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1044

Root cause

compgen -A service was always empty on Windows. GNU bashline.c:2668 bash_servicename_completion_function walks getservent() entries; rubash only read the files-backed database under #[cfg(unix)] (/etc/services) and fell through to an invented SERVICE/SERVICENAME/__RUBASH_SERVICE_NAMES env-var fallback that nothing ever populates — so the action returned zero candidates.

Fix

service_completion_candidates now reads the platform services database via services_db_path(): /etc/services on unix, %SystemRoot%\System32\drivers\etc\services on 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 (what getservent yields); the env-var fallback is removed.

Before / after (this host, Windows services DB, 287-line file)

compgen -A service | wc -l
# before: 0
# after:  277
compgen -A service | head -8
# after:  echo / echo / discard / discard / systat / systat / daytime / daytime   (DB order, dup pairs kept)
compgen -A service ftp   ->  ftp-data / ftp / ftps-data / ftps / tftp

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's getservent reads /etc/services (or NSS equivalent); there is no built-in fallback list in GNU source.

Tests

tests/issue1044_service_completion.rs re-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

…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>
@caomengxuan666
caomengxuan666 merged commit 0a44ff3 into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1044-compgen-service branch October 23, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] compgen -A service always empty

1 participant