#!/bin/bash

## Copyright (C) 2012 - 2023 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

folder_init() {
   msgcollector_run_dir="/run/user/$(id -u)/msgcollector"
   if ! test -d "${msgcollector_run_dir}" ; then
      mkdir --parents "${msgcollector_run_dir}"
   fi
}

loop_protection() {
   if [ "$loop_counter_protection" = "" ]; then
      loop_counter_protection="0"
      ## Do not wait on first run of this function.
      return 0
   fi
   loop_counter_protection="$(( $loop_counter_protection + 1 ))"
   if [ "$loop_counter_protection" -gt "60" ]; then
      ## Timeout reached.
      exit 2
   fi
   sleep 1 &
   wait "$!"
}
