Module Name: src
Committed By: riastradh
Date: Sun Mar 3 15:53:55 UTC 2024
Modified Files:
src/usr.sbin/certctl: certctl.sh
Log Message:
certctl(8): Avoid basename(1).
Saves some time running subprocesses. Since this is only used for
non-directories (i.e., there's never trailing / on the inputs), it
suffices to delete the longest prefix matching glob `*/' with shell
parameter expansion -- much cheaper than spawning a subprocess.
Shaves off about 1/3 of the time spent in `certctl list' on an
aarch64 VM in qemu.
PR bin/57993
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/certctl/certctl.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/certctl/certctl.sh
diff -u src/usr.sbin/certctl/certctl.sh:1.5 src/usr.sbin/certctl/certctl.sh:1.6
--- src/usr.sbin/certctl/certctl.sh:1.5 Tue Sep 5 12:32:30 2023
+++ src/usr.sbin/certctl/certctl.sh Sun Mar 3 15:53:55 2024
@@ -1,6 +1,6 @@
#!/bin/sh
-# $NetBSD: certctl.sh,v 1.5 2023/09/05 12:32:30 riastradh Exp $
+# $NetBSD: certctl.sh,v 1.6 2024/03/03 15:53:55 riastradh Exp $
#
# Copyright (c) 2023 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -30,7 +30,7 @@
set -o pipefail
set -Ceu
-progname=$(basename -- "$0")
+progname=${0##*/}
### Options and arguments
@@ -276,8 +276,7 @@ list_default_trusted()
# Print the vis-encoded absolute path to the
# certificate and base name on a single line.
- vbase=$(basename -- "$vcert.")
- vbase=${vbase%.}
+ vbase=${vcert##*/}
printf '%s %s\n' "$vcert" "$vbase"
done
done
@@ -339,8 +338,7 @@ list_distrusted()
# Print the vis-encoded absolute path to the
# certificate and base name on a single line.
vcert=$(printf '%s' "$cert" | vis -M)
- vbase=$(basename -- "$vcert.")
- vbase=${vbase%.}
+ vbase=${vcert##*/}
printf '%s %s\n' "$vcert" "$vbase"
done
@@ -562,8 +560,7 @@ cmd_trust()
fi
# Verify we currently distrust a certificate by this base name.
- certbase=$(basename -- "$cert.")
- certbase=${certbase%.}
+ certbase=${cert##*/}
if [ ! -h "$distrustdir/$certbase" ]; then
error "not currently distrusted: $vcert"
return 1
@@ -574,7 +571,7 @@ cmd_trust()
target=$(readlink -n -- "$distrustdir/$certbase" && printf .)
target=${target%.}
if [ "$cert" != "$target" ]; then
- vcertbase=$(basename -- "$vcert")
+ vcertbase=${vcert##*/}
error "distrusted $vcertbase does not point to $vcert"
return 1
fi
@@ -617,8 +614,7 @@ cmd_untrust()
# Check whether this certificate is already distrusted.
# - If the same base name points to the same path, stop here.
# - Otherwise, fail noisily.
- certbase=$(basename "$cert.")
- certbase=${certbase%.}
+ certbase=${cert##*/}
if [ -h "$distrustdir/$certbase" ]; then
target=$(readlink -n -- "$distrustdir/$certbase" && printf .)
target=${target%.}