Skip to content

Fix/man page - #11

Merged
ThatStasGuy merged 2 commits into
amazonlinux:mainfrom
VinzSpring:fix/man-page
Aug 18, 2026
Merged

Fix/man page#11
ThatStasGuy merged 2 commits into
amazonlinux:mainfrom
VinzSpring:fix/man-page

Conversation

@VinzSpring

@VinzSpring VinzSpring commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Fix man page naming and clean up restart hook discovery

Problem

man smart-restart fails with "No manual entry for smart-restart" on
systems with the package installed. Man pages must be named
<name>.<section> (e.g. smart-restart.1), but the page ships and
installs as smart-restart.man1, which man(1) cannot locate.

Additionally, every dnf transaction prints harmless but noisy errors
when no optional hook files are installed (the default):

post-transaction-actions: ls: cannot access '/etc/smart-restart-conf.d/*pre-restart': No such file or directory
ls: cannot access '/etc/smart-restart-conf.d/*post-restart': No such file or directory

Changes

Commit 1 — Fix man page naming so man smart-restart works

  • Rename doc/smart-restart.man1 to doc/smart-restart.1
  • Update MAN_FILE and the sources tarball path in the Makefile
  • Update the spec %files entry to %{_mandir}/man1/smart-restart.1*
    (the glob covers compressed and uncompressed installs)
  • Bump the stale MINOR in the Makefile from 2 to 3 to match the
    v0.3 tag

Commit 2 — Make restart hook discovery quiet and deterministic

  • Replace the ls-parsing hook discovery with nullglob array
    assignment. An unmatched glob now yields a cleanly empty array with
    no stderr output, and filenames containing whitespace no longer
    word-split into bogus entries (shellcheck SC2207).
  • Pin GLOBSORT=name before the globs. Since bash 5.3, an exported
    GLOBSORT in the caller's environment changes pathname expansion
    order (e.g. by mtime, or reversed); setting it to name explicitly
    keeps hook execution order deterministic. This is a harmless no-op
    on older bash.
  • Hook ordering is unchanged: glob expansion sorts by name, and the
    previous ls | sort -n was effectively name-sorted too (sort -n
    never found a leading number in absolute paths and fell back to
    byte-wise comparison).

Background on the previous hook discovery

The previous implementation built the hook arrays from
$(ls ... | sort -n). A few subtleties there motivated the change:

  • When no hook files are installed (the default), the unmatched glob
    reaches ls literally, producing the stderr noise above on every
    dnf transaction, while the arrays stay empty via ls's empty
    stdout.
  • Building arrays by word-splitting command substitution output means
    a hook filename containing whitespace splits into multiple entries
    (the pattern shellcheck SC2207 describes).
  • The -n had no observable effect: every line shares the same
    directory prefix ($CONF_PATH/), so sort -n parses the identical
    leading numeric key from all lines, every comparison ties, and
    ordering falls back to byte-wise whole-line comparison — i.e. the
    resulting order was already name order. That's why the nullglob
    replacement preserves ordering exactly.

The glob-array form gets the same result with fewer moving parts and
no per-transaction subprocesses.

Testing

  • make test passes (all 17 tests)
  • bash -n bin/smart-restart.sh passes
  • With an empty /etc/smart-restart-conf.d, the script produces no
    output and the hook arrays are empty
  • With tests/conf, hooks are discovered in the expected order
    (0001-* before 0002-*)
  • make DEST_DIR=$(mktemp -d) install stages
    usr/share/man/man1/smart-restart.1 and no *.man1 file
  • End-to-end on an EC2 instance: the 0.3 RPM built from this tree
    installs cleanly, rpm -V passes, and the dnf post-transaction hook
    fires and runs the script on a dnf reinstall transaction

Man pages must be named <name>.<section>; the file shipped and
installed as smart-restart.man1, which man(1) cannot locate. Rename
doc/smart-restart.man1 to doc/smart-restart.1, update MAN_FILE and
the sources tarball path in the Makefile, and match the new name in
the spec %files entry with a smart-restart.1* glob.

Also bump the stale Makefile MINOR to 3 to match the v0.3 tag.
Hook discovery parsed ls output, printing "ls: cannot access ..."
to stderr on every dnf transaction when no optional hook files exist,
and word-splitting broke on filenames containing whitespace (SC2207).
Use nullglob array assignment instead, and set GLOBSORT=name so hook
ordering stays name-sorted even if the caller's environment sets a
different glob sort order (bash >= 5.3).

@ThatStasGuy ThatStasGuy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ThatStasGuy
ThatStasGuy merged commit 364bd80 into amazonlinux:main Aug 18, 2026
3 checks passed
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