#!/bin/sh
# --------------------------------------------------------------
# Copyright (c) 2012 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Qualcomm Technologies Proprietary and Confidential.
# --------------------------------------------------------------
# restart_mbimd: Simple script to restart mbimd if it crashes

# Bail out if this script is already running
if [ $(ps aux | grep restart_mbimd | wc -l) -gt 3 ]; then
   return 0
fi

# Restart mbimd if it exits, but place a limit on the number of
# times it is restarted to avoid an infinite loop if the mbimd
# binary is missing, etc. This upper bound should not be
# triggered by valid mbimd crashes, because mbimd will reboot the
# system if it crashed while an MBIM session was open.
count=0
while [ $count -lt 100 ]
do
  # Note that mbimd currently runs as root to allow it access to the
  # device files it requires. Would need to be reevaluated if QBI is
  # ported to LA.
  /usr/bin/mbimd
  sleep 2
  count=$(($count + 1))
done
