Page MenuHomeFreeBSD

common/funcs/tst.basename.d*: make it compatible with basename(1)
ClosedPublic

Authored by lwhsu on Jul 23 2017, 11:43 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Oct 19, 12:36 AM
Unknown Object (File)
Oct 12 2024, 8:23 PM
Unknown Object (File)
Oct 3 2024, 9:29 AM
Unknown Object (File)
Oct 2 2024, 6:10 AM
Unknown Object (File)
Oct 1 2024, 3:11 PM
Unknown Object (File)
Sep 30 2024, 2:36 AM
Unknown Object (File)
Sep 29 2024, 8:20 AM
Unknown Object (File)
Sep 28 2024, 10:35 PM
Subscribers

Details

Summary

In Solaris, basename(1) and basename(3) both return "." while given an empty
string (""), while in BSD (and Linux) basename(1) returns "" and basename(3)
returns "."

This patch accepts basename() in D script returns "" or "."

While here, also:

  • change #!/usr/bin/ksh to #!/usr/bin/env ksh to find ksh in $PATH
  • fix quotation inconsistency
Test Plan

sudo kyua test -k /usr/tests/cddl/usr.sbin/dtrace/common/funcs/Kyuafile t_dtrace_contrib:tst_basename_d

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

lwhsu edited the summary of this revision. (Show Details)

Thanks.

cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/funcs/tst.basename.d
60 ↗(On Diff #31111)

POSIX says that either output is valid, so both Solaris and FreeBSD are behaving correctly. I would phrase the comment this way: "basename(3) and basename(1) return different results for the empty string on FreeBSD, so we need special handling."

ngie retitled this revision from common/funcs/tst.basename.d*: make it compatiable with basename(1) to common/funcs/tst.basename.d*: make it compatible with basename(1).Jul 24 2017, 5:13 PM
ngie edited the summary of this revision. (Show Details)
ngie added inline comments.
cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/funcs/tst.basename.d.out
4 ↗(On Diff #31111)

While I agree with what you're trying to do below, they're unnecessary stylistic divergences from upstream:

$ echo "\"foo"\"
"foo"
$ echo "\"foo\""
"foo"

Could you please revert all of the style changes in the file?

lwhsu edited edge metadata.
  • Update comments
  • Revert unnecessary quotation changes
cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/funcs/tst.basename.d.out
155 ↗(On Diff #31140)

"." != "." is always false.

cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/funcs/tst.basename.d.out
155 ↗(On Diff #31140)

Yes, and it guarantees the warning in the next line won't be issued. This line is generated by tst.basename.d D script:

printf("if [ \"`basename \"%s\"`\" != \"%s\" -a \".\" != \"%s\" ]; then\n",
    dir[i], basename(dir[i]), basename(dir[i]));

Where we add another acceptable output of basename(1,3) in POSIX.

This revision is now accepted and ready to land.Jul 25 2017, 10:25 AM
This revision was automatically updated to reflect the committed changes.