blob: 4e5535020166061dcd8ea6377653c7c325b8c831 [file] [log] [blame] [edit]
# Copyright 2022 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Keep this file in sync with ippusb-bridge.conf
description "IPP-USB bridge daemon"
author "chromium-os-dev@chromium.org"
import BUS
import DEV
import VID
import PID
instance $BUS:$DEV
env IPPUSB_SOCKET_DIR="/run/ippusb"
# ippusb_bridge can recover by restarting.
oom score -100
expect fork
kill signal INT
respawn
tmpfiles /usr/lib/tmpfiles.d/on-demand/ippusb-bridge.conf
pre-stop script
# Remove the socket before stopping ippusb_bridge so that
# processes can't make new connections while it is draining
# the existing requests.
rm -f "${IPPUSB_SOCKET_DIR}/${VID}-${PID}.sock" # croslint: disable:
end script
pre-start script
# DEV and BUS must be numeric values matching an entry in /dev/bus/usb.
if [ -z "${BUS}" ] || [ -z "${DEV}" ]; then
logger -p err -t "${UPSTART_JOB}" "BUS and DEV are required"
stop
exit 1
fi
if [ $(expr "${BUS}" : "^[0-9]\+$") -eq 0 ]; then
logger -p err -t "${UPSTART_JOB}" "Invalid USB BUS: ${BUS}"
stop
exit 1
fi
if [ $(expr "${DEV}" : "^[0-9]\+$") -eq 0 ]; then
logger -p err -t "${UPSTART_JOB}" "Invalid USB DEV: ${DEV}"
stop
exit 1
fi
if ! [ -c "/dev/bus/usb/${BUS}/${DEV}" ]; then
logger -p err -t "${UPSTART_JOB}" "USB device ${BUS}/${DEV} does not exist"
stop
exit 1
fi
# VID and PID must be 4 hex characters that correspond to the $BUS:DEV device.
if [ $(expr "${VID}" : "^[0-9a-fA-F]\{4\}$") -eq 0 ]; then
logger -p err -t "${UPSTART_JOB}" "Invalid USB VID: ${VID}"
stop
exit 1
fi
if [ $(expr "${PID}" : "^[0-9a-fA-F]\{4\}$") -eq 0 ]; then
logger -p err -t "${UPSTART_JOB}" "Invalid USB PID: ${PID}"
stop
exit 1
fi
if ! lsusb -d "${VID}:${PID}" -s "${BUS}:${DEV}" >/dev/null; then
logger -p err -t "${UPSTART_JOB}" \
"USB device ${VID}:${PID} does not correspond to ${BUS}/${DEV}"
stop
exit 1
fi
end script
exec minijail0 --config /usr/share/minijail/ippusb-bridge.conf \
-b /dev/bus/usb/$BUS/$DEV \
-- /usr/bin/ippusb_bridge --upstart \
-v -d $BUS:$DEV -s $IPPUSB_SOCKET_DIR/$VID-$PID.sock