Skip to content

fix(service,{invoke,update}-rc.d): fix regressions and refactor - #1653

Merged
scop merged 4 commits into
scop:mainfrom
akinomyoga:services
Jun 28, 2026
Merged

fix(service,{invoke,update}-rc.d): fix regressions and refactor#1653
scop merged 4 commits into
scop:mainfrom
akinomyoga:services

Conversation

@akinomyoga

@akinomyoga akinomyoga commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

I'm sorry, I noticed regressions I introduced in #1035 and #1553. This PR contains the fixes and related refactorings.

This is a fix for a regression I introduced in commit da26178
(2023-08-13) with a *too* early return.  Even when `_comp_sysvdirs`
returns no service directories, the `services` array had gotten
additional completions from the results of `systemctl`.  The
conditional for the result of `_comp_sysvdirs` should only apply to
the completion generation based on the `sysvdirs` array.
"_comp_compgen_services" (bash_completion) and "{invoke,update}-rc.d"
have similar logics to generate the service names based on the
directory structures for SysV init services.  This patch provides a
single function "_comp_compgen_sysv_services" for the common logic.

There have been some differences in the excluded filenames between
"_comp_compgen_services" and "{invoke,update}-rc.d":

* The function "_comp_compgen_services" exclude the file "functions",
  which contains utilities that are used by other service scripts.
  The completions for "{invoke,update}-rc.d" exclude "*.sh" and also
  the files starting with "README*".  In the new generator
  "_comp_compgen_sysv_services", we exclude all "*.sh", "functions",
  and "README*".

* Another difference is the extraction of the SysV directory.  The
  completions for "{invoke,update}-rc.d" only checked /etc/rc.d/init.d
  and /etc/init.d, but "_comp_compgen_services" based on
  "_comp_sysvdirs" checked also /etc/slackware-version when neither
  /etc/rc.d/init.d nor /etc/init.d is found.  In the new generator, we
  use "_comp_sysvdirs" to identify a SysV service directory.
We can also use "_comp_sysvdirs" in identifying the service script for
the completion of an action name.
This is a regression by Ref. [1].  In Ref. [1], I have replaced the
combination of "_comp_expand_glob" and "_comp_compgen -- -W" with
"_comp_compgen -C -- -f".  However, I realized that this strategy
would cause generation of the filenames in subdirectories when $cur
contains "/" [2].  To avoid this, one can exclude candidates
containing a slash by -X '*/*'.

[1] scop#1553
[2] scop#1639 (comment)

@scop scop left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@scop
scop merged commit 1ee269f into scop:main Jun 28, 2026
9 checks passed
@akinomyoga
akinomyoga deleted the services branch June 28, 2026 10:15
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.

2 participants