#!/bin/bash

ok=0
lastdate1=0
lastdate0=0
while [ "$ok" == 0 -a ! -s /var/run/rebootctl ]; do
    lastdate2=$lastdate1
    lastdate1=$lastdate0
    lastdate0=`date +%s`
    if [ `expr $lastdate0 - $lastdate2` -lt 40 ]; then
        echo "X server respawning too fast :(, dropping to a shell"
        bash
    fi
    X $@
    ok=$?
done