#!/bin/sh
PATH=/usr/bin:/bin:/usr/sbin:/sbin

# Helper program to ensure buxton databases are already opened
#
# This program is needed because buxton2ctl as launched via dump_systemstate,
# via crash-manager, has high enough permissions to create sqlite journal files
# in /var/lib/buxton2. (The files are created internally via libsqlite logic and
# client has no control over it).
#
# By waiting for buxton2 service to start we want to ensure the needed sqlite
# files are already created with correct permissions.


WAIT_SEC=30
BUXTON_SERVICE=buxton2.service

for i in $(seq 1 $WAIT_SEC); do
	if systemctl is-active "$BUXTON_SERVICE"; then
		exec buxton2ctl "$@"
		break
	fi
	sleep 1
done

echo "Unable to contact buxton - vconf logs not available."

exit 0
