blob: 897570f52c188312aa6bb4e646d921de5d605eec [file] [log] [blame]
# Copyright (c) 2012 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.
description "Start the Chromium OS power daemon"
author "chromium-os-dev@chromium.org"
# Note, the 'start on' line is modified by chromeos-factoryinstall ebuild.
# Please do not change it without also changing that reference.
start on started boot-services
stop on stopping boot-services
respawn
respawn limit 3 10 # if the job respawns 3 times in 10 seconds, stop trying.
env LOG_DIR=/var/log/power_manager
env POWER_RUN_DIR=/var/run/power_manager/power
env PREFS_DIR=/var/lib/power_manager
env ROOT_RUN_DIR=/var/run/power_manager/root
env ROOT_SPOOL_DIR=/var/spool/power_manager/root
env DEFAULT_PREFS_DIR=/usr/share/power_manager
env VPD_CACHE_FILE=/mnt/stateful_partition/unencrypted/cache/vpd/filtered.txt
env MAX_NITS_PREF=internal_backlight_max_nits
env PM_TEST_DELAY_FILE=/sys/power/pm_test_delay
# Add modules here in --vmodule format for debugging.
env VMODULE_ARG=
pre-start script
mkdir -p ${LOG_DIR} ${POWER_RUN_DIR} ${PREFS_DIR}
chown -R power:power ${LOG_DIR} ${POWER_RUN_DIR} ${PREFS_DIR}
chmod 755 ${LOG_DIR} ${POWER_RUN_DIR} ${PREFS_DIR}
mkdir -p ${ROOT_RUN_DIR} ${ROOT_SPOOL_DIR}
# Read the real maximum backlight luminance (i.e. not the value reported by
# the driver) from VPD and pass it to powerd via a pref file.
if [ -e "${VPD_CACHE_FILE}" ]; then
MAX_NITS=$(sed -nre 's/^"panel_backlight_max_nits"="(.+)"$/\1/p' \
<"${VPD_CACHE_FILE}")
if [ -n "${MAX_NITS}" ]; then
TEMP_FILE="$(mktemp --tmpdir powerd_nits.XXXXXXXXXX)"
echo "${MAX_NITS}" >"${TEMP_FILE}"
PREF_FILE="${PREFS_DIR}/${MAX_NITS_PREF}"
mv "${TEMP_FILE}" "${PREF_FILE}"
chown power:power "${PREF_FILE}"
chmod 644 "${PREF_FILE}"
fi
fi
# Change ownership of files used by powerd.
for FILE in \
/sys/power/pm_test \
/sys/power/state \
/proc/acpi/wakeup \
/sys/class/backlight/*/* \
/sys/class/leds/*:kbd_backlight/* \
/sys/class/power_supply/*/charge_control_limit_max \
$(find /sys/devices/ -name "dark_resume_active" -o \
-name "dark_resume_source" -o \
-name "wakeup_type" -o \
-path "*/power/wakeup"); do
# Test for existence to skip over wildcards that didn't match anything.
if [ -e "${FILE}" ]; then
chown power:power "${FILE}" || true
fi
done
# Prepare for recovery from dark resume to a full resume. TODO(chirantan):
# Remove this when selective resume is ready.
if [ -e "${PM_TEST_DELAY_FILE}" ]; then
# Wait for 5 milliseconds before starting the resume.
echo 5 > "${PM_TEST_DELAY_FILE}"
fi
end script
# Note that we need the full path to powerd because minijail doesn't look
# at $PATH. Also, do not set capabilities here using minijail0's -c flag;
# doing so will prevent powerd_setuid_helper from running correctly when
# executed by powerd.
exec minijail0 -u power -g power -G -- \
/usr/bin/powerd \
--prefs_dir=${PREFS_DIR} \
--default_prefs_dir=${DEFAULT_PREFS_DIR} \
--log_dir=${LOG_DIR} \
--run_dir=${POWER_RUN_DIR} \
--vmodule="${VMODULE_ARG}" \
>/var/log/powerd.out 2>&1