ovs-pki: Create log directory if it does not exist.
authorBen Pfaff <blp@nicira.com>
Fri, 6 Aug 2010 20:32:47 +0000 (13:32 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 6 Aug 2010 20:32:47 +0000 (13:32 -0700)
Otherwise "ovs-pki init" can create the pkidir and then fail when it tries
to create the log file, if it is in a directory that does not exist.

utilities/ovs-pki.in

index b91d061..cbdb43d 100755 (executable)
@@ -176,6 +176,15 @@ case $log in
     *) $log="$PWD/$log" ;;
 esac
 
+logdir=$(dirname "$log")
+if test ! -d "$logdir"; then
+    mkdir -p -m755 "$logdir" 2>/dev/null || true
+    if test ! -d "$logdir"; then
+        echo "$0: log directory $logdir does not exist and cannot be created" >&2
+        exit 1
+    fi
+fi
+
 if test "$command" = "init"; then
     if test -e "$pkidir" && test "$force" != "yes"; then
         echo "$0: $pkidir already exists and --force not specified" >&2