Page MenuHomeFreeBSD

periodic(8): Improve error messaging
Needs ReviewPublic

Authored by yzhong_freebsdfoundation.org on Sep 30 2020, 3:38 PM.
Tags
None
Referenced Files
F138685800: D26609.diff
Thu, Dec 4, 4:29 AM
Unknown Object (File)
Thu, Nov 6, 1:14 AM
Unknown Object (File)
Nov 4 2025, 1:13 AM
Unknown Object (File)
Oct 30 2025, 4:03 PM
Unknown Object (File)
Oct 9 2025, 6:02 AM
Unknown Object (File)
Sep 27 2025, 9:27 PM
Unknown Object (File)
Sep 25 2025, 5:34 PM
Unknown Object (File)
Sep 20 2025, 10:14 AM
Subscribers
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

From https://bugs.freebsd.org/248536: if you try to use a directory base name with a hyphen in it, you get a confusing error message. The man page for periodic says:

Since one specifies information about a directory using shell variables
containing the string, <basedir>, <basedir> must only contain characters
that are valid within a sh(1) variable name, alphanumerics and
underscores, and the first character may not be numeric.

This patch adds an explicit check of the directory name, so you'll get a sensible error message if you try to do this.

Additionally, periodic gives an error if it can't find a directory passed in with an absolute path, but it does not give an error if it was passed in with a relative path. This patch adds an error for that.

Finally, this patch replaces ${x##*/}, which removes everything before and including the last slash in a path x, with $(basename x). The old version works for paths like a/b/c, but not ones like a/b/c/.

Test Plan

1: call periodic on a directory with hyphens in its name, or any name that's not a valid sh(1) variable
2: call periodic on a non-existent directory, with a relative path
3: call periodic on a directory, with a path that ends with a slash

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

BTW, is it necessary to use basename instead of ${XXX##*/}? It seems to work fine:

$ sh -c 'abs=/a/b/c; echo ${abs##*/}'
c
$ sh -c 'rel=a/b/c; echo ${rel##*/}'
c

I might be missing the point though. I'm not against the change, I'm just curious :)

usr.sbin/periodic/periodic.sh
83

basename $arg might be problematic if $arg starts with -.

This comment applies to other basename invocations.

${abs##*/} doesn't work if you enter a path that looks like a/b/c/ - it just gives the empty string back if I remember correctly. I see the problem with basename as well, now.