blob: 08887dd27a09e8550af95ea7c7a4c927edfa1253 [file] [log] [blame]
#!/bin/sh
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script starts brltty in a minijail sandbox.
BRLTTY_RUNDIR=/var/run/brltty
BRLAPI_SOCKETDIR=/var/lib/BrlAPI
# The number (0) must be kept in sync with the Host api parameter in
# brltty.conf.
BRLAPI_SOCKETFILE="${BRLAPI_SOCKETDIR}/0"
log() {
logger -t brltty_udev "$@"
}
# Kill any stale brltty processes that might be holding on to the
# BrlAPI socket. We try hard, because failure to free up the socket will lock
# the braille user out from the machine!
kill_stale_brltty() {
local SIGTERM_MAX_TRIES=5
if fuser -s -k -TERM "${BRLAPI_SOCKETFILE}"; then
log "Waiting for stale brltty process to terminate"
local i=0
while [ ${i} -lt ${SIGTERM_MAX_TRIES} ]; do
sleep .1
if ! fuser -s -k -TERM "${BRLAPI_SOCKETFILE}"; then
return
fi
: $(( i += 1 ))
done
log "Sending SIGKILL to stale brltty process"
fuser -s -k -KILL "${BRLAPI_SOCKET_FILE}"
fi
}
kill_stale_brltty
# Ensure that the directories exist and have the right permissions.
mkdir -p -m 0750 "${BRLTTY_RUNDIR}" "${BRLAPI_SOCKETDIR}"
chown -R brltty:brltty "${BRLTTY_RUNDIR}" "${BRLAPI_SOCKETDIR}"
chmod 755 "${BRLTTY_RUNDIR}" "${BRLAPI_SOCKETDIR}"
# Files created by the daemon shouldn't be accessible by users not in the
# brltty group.
umask 0007
log "Starting brltty, device: ${BRLTTY_DEVICE}, driver: ${BRLTTY_DRIVER}"
# Start brltty in the jail.
# The options are:
# - -q: No startup announcement of brltty's version on the braille display.
# - -E: Get some arguments (driver, device, etc) from the environment.
exec /sbin/minijail0 -u brltty -g brltty -G -- \
/bin/brltty -q -E -P${BRLTTY_PID_FILE}