# Setting it to `true` makes the script more verbose, making debugging easier.
VERBOSE=
-# Default value of waiting time (in seconds) for the completion of the
-# add/remove subsession operation.
-DELAYVAL=0.1
-
-# Default value of the number of times the waiting loop for the completion of
-# the add/remove subsession operation is repeated.
-# 5 x 0.1s = 0.5s which should be enough even on a moderately loaded system,
-# but if it's not, one can always increase it with the `-m` parameter.
-MAXTRIES=5
-
verbose_echo()
{
if [ "$VERBOSE" = "true" ]; then
fi
}
+wait_for_user()
+{
+ # Return from the DBus call does not necessarily mean the completion of
+ # the AddUser operation. Since we're not listening to the AddUserCompletion
+ # signal here, the easiest way is to poll and check for the existence of
+ # the subsession directory. `sessiond` guarantees atomicity by copying
+ # subsession files and subdirectories to a temporary directory and
+ # renaming it after the copying operation is completed.
+ local action="$1"
+ local subsession="$2"
+ local subsession_dir="$homedir/subsession/$subsession/apps_rw"
+
+ local elapsed_secs=0
+ local wait_secs=1
+
+ while : ; do
+ echo "waiting for subsession dir to be ${action}-d ($subsession_dir): ${elapsed_secs} seconds"
+ if test "${action}" = "create"; then
+ if test -d "$subsession_dir"; then break; fi
+ else
+ if ! test -d "$subsession_dir"; then break; fi
+ fi
+
+ elapsed_secs=$(($elapsed_secs + $wait_secs))
+ sleep $wait_secs
+ done
+}
+
create_test_users()
{
for subsession in "${TEST_SUBSESSIONS[@]}"; do
echo "Creating test user (regular dir): $subsession"
# Make a direct request to the server for adding a subsession.
- busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager AddUser "is" "$userid" "$subsession"
-
- # Return from the DBus call does not necessarily mean the completion of
- # the AddUser operation. Since we're not listening to the AddUserCompletion
- # signal here, the easiest way is to poll and check for the existence of
- # the subsession directory. `sessiond` guarantees atomicity by copying
- # subsession files and subdirectories to a temporary directory and
- # renaming it after the copying operation is completed.
- delay=0
- created=
- subsession_dir="$homedir/subsession/$subsession/apps_rw"
- while [ $delay -lt $MAXTRIES ]
- do
- if [ -d "$subsession_dir" ]; then
- created=true
- break
- fi
- ((delay=delay+1))
- sleep "$DELAYVAL"
- done
-
- if [ "$1" == "true" ] && [ "$created" != "true" ]; then
- echo "Creating user $subsession (regular dir) failed. Bailing out!"
- exit 1
- fi
+ busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager AddUser "is" "$userid" "$subsession"
+ wait_for_user "create" "$subsession"
done
for subsession in "${TEST_SUBSESSIONS_FIXED[@]}"; do
echo "Creating test user (fixed size): $subsession"
- busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager AddUserFixedSize "isu" "$userid" "$subsession" 10240
- sleep $delay
- echo "Switching into user: $subsession"
- busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager SwitchUser "is" "$userid" "$subsession"
- sleep $delay
-
-
- delay=0
- created=
- subsession_dir="$homedir/subsession/$subsession/apps_rw"
- while [ $delay -lt $MAXTRIES ]
- do
- if [ -d "$subsession_dir" ]; then
- created=true
- break
- fi
- ((delay=delay+1))
- sleep "$DELAYVAL"
- done
+ busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager AddUserFixedSize "isu" "$userid" "$subsession" 10240
+ wait_for_user "create" "$subsession"
- if [ "$1" == "true" ] && [ "$created" != "true" ]; then
- echo "Creating user $subsession (fixed size) failed. Bailing out!"
- exit 1
- fi
+ echo "Switching into user: $subsession"
+ busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager SwitchUser "is" "$userid" "$subsession"
+ # waiting not needed as add_user will leaver subsession mounted anyway
done
}
for subsession in "${TEST_SUBSESSIONS[@]}"; do
echo "Removing user (regular dir): $subsession"
# Make a direct request to the server for removing a subsession.
- busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager RemoveUser "is" "$userid" "$subsession"
-
- # See the remark to the `create_test_users()` function above.
- delay=0
- removed=
- subsession_dir="$homedir/subsession/$subsession/apps_rw"
- while [ $delay -lt $MAXTRIES ]
- do
- if [ ! -d "$subsession_dir" ]; then
- removed=true
- break
- fi
- ((delay=delay+1))
- sleep "$DELAYVAL"
- done
-
- if [ "$1" == "true" ] && [ "$removed" != "true" ]; then
- echo "Removing user $subsession failed (regular dir). Bailing out!"
- exit 1
- fi
+ busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager RemoveUser "is" "$userid" "$subsession"
+ wait_for_user "remove" "$subsession"
done
for subsession in "${TEST_SUBSESSIONS_FIXED[@]}"; do
echo "Removing user (fixed size): $subsession"
- busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager RemoveUser "is" "$userid" "$subsession"
-
- delay=0
- removed=
- subsession_dir="$homedir/subsession/$subsession/apps_rw"
- while [ $delay -lt $MAXTRIES ]
- do
- if [ ! -d "$subsession_dir" ]; then
- removed=true
- break
- fi
- ((delay=delay+1))
- sleep "$DELAYVAL"
- done
-
- if [ "$1" == "true" ] && [ "$removed" != "true" ]; then
- echo "Removing user $subsession failed (fixed size). Bailing out!"
- exit 1
- fi
+ busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager RemoveUser "is" "$userid" "$subsession"
+ wait_for_user "remove" "$subsession"
done
}
while [ $# -gt 0 ]
do
case $1 in
- -h) printf "Usage: %s [-d delay_value] [-m max_delay] [-v verbose]\n" "$0"
+ -h) printf "Usage: %s [-v verbose]\n" "$0"
exit 1
;;
- -d) DELAYVAL=$2
- shift
- ;;
- -m) MAXTRIES=$2
- shift
- ;;
-v) VERBOSE=true
shift
;;
subsession_dir="$homedir/subsession/$subsession/apps_rw"
totalfiles=0
+ echo "Checking file and directory permissions: $subsession"
while IFS= read -r -d '' f
do
verbose_echo "Checking $f..."