comparison sbin/ftjail @ 656:a8052a57a921

ftjail: Use "zfs get" instead of "zfs list" to get just some properties; also explicitly check some return codes for code "1" also
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 28 Sep 2024 14:53:14 +0200
parents 5ba31e3748ca
children db22766df6a4
comparison
equal deleted inserted replaced
655:5ba31e3748ca 656:a8052a57a921
901 901
902 [ -z "${_directory}" ] && { echo "ERROR: no directory given" 1>&2; return 2; } 902 [ -z "${_directory}" ] && { echo "ERROR: no directory given" 1>&2; return 2; }
903 [ -d "${_directory}" ] || { echo "ERROR: directory \`${_directory}' does not exist" 1>&2; return 1; } 903 [ -d "${_directory}" ] || { echo "ERROR: directory \`${_directory}' does not exist" 1>&2; return 1; }
904 904
905 [ -z "${_new_origin}" ] && { echo "ERROR: no new origin given" 1>&2; return 2; } 905 [ -z "${_new_origin}" ] && { echo "ERROR: no new origin given" 1>&2; return 2; }
906 zfs list -H -o name -t snapshot "${_new_origin}" >/dev/null || { echo "ERROR: new origin does not exist" 1>&2; return 1; } 906 zfs list -H -o name -t snapshot "${_new_origin}" >/dev/null || { echo "ERROR: ZFS dataset for the new origin \`${_new_origin}' does not exist" 1>&2; return 1; }
907 if [ -n "${_etcupdate_tarball}" ]; then 907 if [ -n "${_etcupdate_tarball}" ]; then
908 [ -r "${_etcupdate_tarball}" ] || { echo "ERROR: given etcupdate tarball does not exist and/or is not readable" 1>&2; return 1; } 908 [ -r "${_etcupdate_tarball}" ] || { echo "ERROR: given etcupdate tarball does not exist and/or is not readable" 1>&2; return 1; }
909 fi 909 fi
910 910
911 _dir_basename="$(basename "${_directory}")" 911 _dir_basename="$(basename "${_directory}")"
915 _res=$? 915 _res=$?
916 set -e 916 set -e
917 case ${_res} in 917 case ${_res} in
918 0) 918 0)
919 err "Please stop the \`${_jailname}' jail" 919 err "Please stop the \`${_jailname}' jail"
920 return 1
921 ;;
922 1)
920 return 1 923 return 1
921 ;; 924 ;;
922 2) 925 2)
923 err "Jail \`${_jailname}' is currently yet dying" 926 err "Jail \`${_jailname}' is currently yet dying"
924 return 1 927 return 1
928 ;; 931 ;;
929 *) 932 *)
930 return ${_res} 933 return ${_res}
931 ;; 934 ;;
932 esac 935 esac
933 936
934 # 937 #
935 # Check whether additional log sockets are opened at their default 938 # Check whether additional log sockets are opened at their default
936 # locations. Because they hinder proper unmounting of filesystems. 939 # locations. Because they hinder proper unmounting of filesystems.
937 # 940 #
938 for _add_log_sock in /var/run/log /var/run/logpriv ; do 941 for _add_log_sock in /var/run/log /var/run/logpriv ; do
960 IFS=$'\t' read -r _root_dataset _root_mountpoint _root_type _root_options _line <<EOF4tHGCSSf5d7d9cf 963 IFS=$'\t' read -r _root_dataset _root_mountpoint _root_type _root_options _line <<EOF4tHGCSSf5d7d9cf
961 ${_dir_mounts} 964 ${_dir_mounts}
962 EOF4tHGCSSf5d7d9cf 965 EOF4tHGCSSf5d7d9cf
963 [ "${_root_mountpoint}" != "${_directory}" ] && { echo "ERROR: found root mountpoint does not match given directory" 1>&2; return 1; } 966 [ "${_root_mountpoint}" != "${_directory}" ] && { echo "ERROR: found root mountpoint does not match given directory" 1>&2; return 1; }
964 [ "${_root_type}" != "zfs" ] && { echo "ERROR: root mountpoint is not from a ZFS dataset" 1>&2; return 1; } 967 [ "${_root_type}" != "zfs" ] && { echo "ERROR: root mountpoint is not from a ZFS dataset" 1>&2; return 1; }
965 _root_readonly="$(zfs list -H -o readonly "${_root_dataset}")" 968 _root_readonly="$(zfs get -H -o value readonly "${_root_dataset}")"
966 [ "${_root_readonly}" != "on" ] && { echo "ERROR: the root dataset is not mounted read-only" 1>&2; return 1; } 969 [ "${_root_readonly}" != "on" ] && { echo "ERROR: the root dataset is not mounted read-only" 1>&2; return 1; }
967 _root_origin="$(zfs list -H -o origin "${_root_dataset}")" 970 _root_origin="$(zfs get -H -o value origin "${_root_dataset}")"
968 if [ -n "${_opt_old_origin}" ]; then 971 if [ -n "${_opt_old_origin}" ]; then
969 [ "${_opt_old_origin}" != "${_root_origin}" ] && { echo "ERROR: origin mismatch" 1>&2; return 1; } 972 [ "${_opt_old_origin}" != "${_root_origin}" ] && { echo "ERROR: origin mismatch" 1>&2; return 1; }
970 else 973 else
971 [ "${_root_origin}" = '-' ] && { echo "ERROR: the root dataset is not a ZFS clone" 1>&2; return 1; } 974 [ "${_root_origin}" = '-' ] && { echo "ERROR: the root dataset is not a ZFS clone" 1>&2; return 1; }
972 fi 975 fi