From: Krzysztof Malysa Date: Tue, 9 Jul 2024 11:16:32 +0000 (+0200) Subject: Make test/smack_rule_test/checksmackrule.sh more robust X-Git-Tag: accepted/tizen/unified/dev/20240722.073455~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9a1d9432c0254291e4da727982f620f7e07e38d;p=platform%2Fcore%2Fsecurity%2Fsecurity-config.git Make test/smack_rule_test/checksmackrule.sh more robust Change-Id: I88a9c0a756264d1676768b33ea3c3c9236545053 --- diff --git a/test/smack_rule_test/checksmackrule.sh b/test/smack_rule_test/checksmackrule.sh index 32bff94..b01bbfc 100755 --- a/test/smack_rule_test/checksmackrule.sh +++ b/test/smack_rule_test/checksmackrule.sh @@ -19,10 +19,50 @@ then rm $log_file fi +function kill_all_apps { + echo "Killing all apps..." + sqlite3 /opt/dbspace/.security-manager.db "select name from app" | xargs -i sh -c 'app_launcher -k {} | true' + echo "... done." +} + +function run_apps { + apps_to_run=("$@") + # Applications may depend on other apps, so try starting unstarted applications until no new application starts + while true; do + next_apps_to_run=() + for app in "${apps_to_run[@]}"; do + printf "Trying to run app ${app}: " + if app_launcher --is-running="${app}" > /dev/null; then + echo "... already running." + elif ! app_launcher --start="${app}"; then + next_apps_to_run+=("${app}") + fi + done + if [ "${#next_apps_to_run[@]}" == "${#apps_to_run[@]}" ]; then + break; # No new app started, we reached a point where we assume that no new application will start + fi + apps_to_run=("${next_apps_to_run[@]}") + done +} + +function run_all_apps { + run_apps $(sqlite3 /opt/dbspace/.security-manager.db "select name from app") +} + +function get_running_apps { + for app in $(sqlite3 /opt/dbspace/.security-manager.db "select name from app"); do + if app_launcher --is-running="${app}" > /dev/null; then + echo "${app}" + fi + done +} + +# Restore apps upon script exit or termination by a signal +apps_running_before_the_test=($(get_running_apps)) +trap 'kill_all_apps; run_apps "${apps_running_before_the_test[@]}"' EXIT + # Run all apps to load all SMACK rules -# Some applications may have dependencies on other apps, so double execution is required at first. -sqlite3 /opt/dbspace/.security-manager.db "select name from app" | xargs -i sh -c 'app_launcher -s {} | true' -sqlite3 /opt/dbspace/.security-manager.db "select name from app" | xargs -i sh -c 'app_launcher -s {} | true' +run_all_apps # Copy original SMACK rules cat /sys/fs/smackfs/load2 | sort > $tmp_current_rule @@ -42,8 +82,8 @@ smackctl apply security-manager-rules-loader # Re-run all apps -sqlite3 /opt/dbspace/.security-manager.db "select name from app" | xargs -i sh -c 'app_launcher -k {} | true' -sqlite3 /opt/dbspace/.security-manager.db "select name from app" | xargs -i sh -c 'app_launcher -s {} | true' +kill_all_apps +run_all_apps # Copy calculated SMACK rules cat /sys/fs/smackfs/load2 | sort > $tmp_calculated_rule