acme: simplify flock usage
authorGlen Huang <i@glenhuang.com>
Fri, 11 Nov 2022 11:16:53 +0000 (19:16 +0800)
committerGlen Huang <i@glenhuang.com>
Fri, 11 Nov 2022 11:19:02 +0000 (19:19 +0800)
Signed-off-by: Glen Huang <i@glenhuang.com>
net/acme-common/files/acme.sh

index bcf3d84518061a46421dda51b23c6f6d8c7ec545..582575f89658ec558211e0d621d8259ae6d6c630 100644 (file)
@@ -117,15 +117,6 @@ load_globals() {
        return 1
 }
 
-cmd_get() {
-       trap cleanup EXIT
-
-       config_load acme
-       config_foreach load_globals acme
-
-       config_foreach get_cert cert
-}
-
 usage() {
        cat <<EOF
 Usage: acme <command> [arguments]
@@ -143,13 +134,18 @@ fi
 case $1 in
 get)
        mkdir -p $run_dir
-       {
-               if ! flock -n 200; then
-                       log err "Another ACME instance is already running."
-                       exit 1
-               fi
-               cmd_get "$@"
-       } 200>$run_dir/lock
+       exec 200>$run_dir/lock
+       if ! flock -n 200; then
+               log err "Another ACME instance is already running."
+               exit 1
+       fi
+
+       trap cleanup EXIT
+
+       config_load acme
+       config_foreach load_globals acme
+
+       config_foreach get_cert cert
        ;;
 *)
        usage