2015-05-26 23:57:13 +02:00
|
|
|
#! /system/bin/sh
|
2016-04-12 23:35:27 +02:00
|
|
|
# logpersist cat, start and stop handlers
|
2015-09-21 19:45:10 +02:00
|
|
|
progname="${0##*/}"
|
2016-02-10 00:49:29 +01:00
|
|
|
case `getprop ro.debuggable` in
|
|
|
|
1) ;;
|
2015-09-21 19:45:10 +02:00
|
|
|
*) echo "${progname} - Permission denied"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2016-04-12 23:35:27 +02:00
|
|
|
|
2015-05-26 23:57:13 +02:00
|
|
|
property=persist.logd.logpersistd
|
2016-07-07 18:24:51 +02:00
|
|
|
|
|
|
|
case `getprop ${property#persist.}.enable` in
|
|
|
|
true) ;;
|
|
|
|
*) echo "${progname} - Disabled"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2016-08-04 00:13:51 +02:00
|
|
|
log_uid=logd
|
2016-07-21 23:00:30 +02:00
|
|
|
log_tag_property=persist.log.tag
|
2016-08-04 00:13:51 +02:00
|
|
|
data=/data/misc/logd/logcat
|
2015-05-26 23:57:13 +02:00
|
|
|
service=logcatd
|
2016-04-12 23:35:27 +02:00
|
|
|
size_default=256
|
|
|
|
buffer_default=all
|
|
|
|
args="${@}"
|
|
|
|
|
|
|
|
size=${size_default}
|
|
|
|
buffer=${buffer_default}
|
|
|
|
clear=false
|
|
|
|
while [ ${#} -gt 0 ]; do
|
|
|
|
case ${1} in
|
|
|
|
-c|--clear) clear=true ;;
|
|
|
|
--size=*) size="${1#--size=}" ;;
|
|
|
|
--rotate-count=*) size="${1#--rotate-count=}" ;;
|
|
|
|
-n|--size|--rotate-count) size="${2}" ; shift ;;
|
|
|
|
--buffer=*) buffer="${1#--buffer=}" ;;
|
|
|
|
-b|--buffer) buffer="${2}" ; shift ;;
|
|
|
|
-h|--help|*)
|
|
|
|
LEAD_SPACE_="`echo ${progname%.*} | tr '[ -~]' ' '`"
|
2016-06-02 00:35:41 +02:00
|
|
|
echo "${progname%.*}.cat - dump current ${service} logs"
|
2016-04-12 23:35:27 +02:00
|
|
|
echo "${progname%.*}.start [--size=<size_in_kb>] [--buffer=<buffers>] [--clear]"
|
|
|
|
echo "${LEAD_SPACE_} - start ${service} service"
|
|
|
|
echo "${progname%.*}.stop [--clear] - stop ${service} service"
|
|
|
|
case ${1} in
|
|
|
|
-h|--help) exit 0 ;;
|
|
|
|
*) echo ERROR: bad argument ${@} >&2 ; exit 1 ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "${size}" -o "${size_default}" = "${size}" ]; then
|
|
|
|
unset size
|
2015-05-26 23:57:13 +02:00
|
|
|
fi
|
2016-04-12 23:35:27 +02:00
|
|
|
if [ -n "${size}" ] &&
|
|
|
|
! ( [ 0 -lt "${size}" ] && [ 2048 -ge "${size}" ] ) >/dev/null 2>&1; then
|
|
|
|
echo ERROR: Invalid --size ${size} >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "${buffer}" -o "${buffer_default}" = "${buffer}" ]; then
|
|
|
|
unset buffer
|
|
|
|
fi
|
|
|
|
if [ -n "${buffer}" ] && ! logcat -b ${buffer} -g >/dev/null 2>&1; then
|
|
|
|
echo ERROR: Invalid --buffer ${buffer} >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-07-21 23:00:30 +02:00
|
|
|
log_tag="`getprop ${log_tag_property}`"
|
|
|
|
logd_logpersistd="`getprop ${property}`"
|
|
|
|
|
2015-05-26 23:57:13 +02:00
|
|
|
case ${progname} in
|
|
|
|
*.cat)
|
2016-04-12 23:35:27 +02:00
|
|
|
if [ -n "${size}${buffer}" -o "true" = "${clear}" ]; then
|
|
|
|
echo WARNING: Can not use --clear, --size or --buffer with ${progname%.*}.cat >&2
|
|
|
|
fi
|
2016-08-04 00:13:51 +02:00
|
|
|
su ${log_uid} ls "${data%/*}" |
|
2015-05-26 23:57:13 +02:00
|
|
|
tr -d '\r' |
|
|
|
|
sort -ru |
|
2016-08-04 00:13:51 +02:00
|
|
|
sed "s#^#${data%/*}/#" |
|
|
|
|
grep "${data}[.]*[0-9]*\$" |
|
|
|
|
su ${log_uid} xargs cat
|
2015-05-26 23:57:13 +02:00
|
|
|
;;
|
|
|
|
*.start)
|
2016-07-07 18:24:51 +02:00
|
|
|
current_buffer="`getprop ${property#persist.}.buffer`"
|
|
|
|
current_size="`getprop ${property#persist.}.size`"
|
|
|
|
if [ "${service}" = "`getprop ${property#persist.}`" ]; then
|
2016-04-12 23:35:27 +02:00
|
|
|
if [ "true" = "${clear}" ]; then
|
2016-07-07 18:24:51 +02:00
|
|
|
setprop ${property#persist.} "clear"
|
2016-04-12 23:35:27 +02:00
|
|
|
elif [ "${buffer}|${size}" != "${current_buffer}|${current_size}" ]; then
|
|
|
|
echo "ERROR: Changing existing collection parameters from" >&2
|
|
|
|
if [ "${buffer}" != "${current_buffer}" ]; then
|
|
|
|
a=${current_buffer}
|
|
|
|
b=${buffer}
|
|
|
|
if [ -z "${a}" ]; then a="${default_buffer}"; fi
|
|
|
|
if [ -z "${b}" ]; then b="${default_buffer}"; fi
|
|
|
|
echo " --buffer ${a} to ${b}" >&2
|
|
|
|
fi
|
|
|
|
if [ "${size}" != "${current_size}" ]; then
|
|
|
|
a=${current_size}
|
|
|
|
b=${size}
|
|
|
|
if [ -z "${a}" ]; then a="${default_size}"; fi
|
|
|
|
if [ -z "${b}" ]; then b="${default_size}"; fi
|
|
|
|
echo " --size ${a} to ${b}" >&2
|
|
|
|
fi
|
|
|
|
echo " Are you sure you want to do this?" >&2
|
|
|
|
echo " Suggest add --clear to erase data and restart with new settings." >&2
|
|
|
|
echo " To blindly override and retain data, ${progname%.*}.stop first." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-06-06 20:22:13 +02:00
|
|
|
elif [ "true" = "${clear}" ]; then
|
2016-07-07 18:24:51 +02:00
|
|
|
setprop ${property#persist.} "clear"
|
2016-04-12 23:35:27 +02:00
|
|
|
fi
|
|
|
|
if [ -n "${buffer}${current_buffer}" ]; then
|
2016-06-06 20:22:13 +02:00
|
|
|
setprop ${property}.buffer "${buffer}"
|
2016-07-07 18:24:51 +02:00
|
|
|
if [ -z "${buffer}" ]; then
|
|
|
|
# deal with trampoline for empty properties
|
|
|
|
setprop ${property#persist.}.buffer ""
|
|
|
|
fi
|
2016-04-12 23:35:27 +02:00
|
|
|
fi
|
|
|
|
if [ -n "${size}${current_size}" ]; then
|
2016-06-06 20:22:13 +02:00
|
|
|
setprop ${property}.size "${size}"
|
2016-07-07 18:24:51 +02:00
|
|
|
if [ -z "${size}" ]; then
|
|
|
|
# deal with trampoline for empty properties
|
|
|
|
setprop ${property#persist.}.size ""
|
|
|
|
fi
|
2016-04-12 23:35:27 +02:00
|
|
|
fi
|
2016-07-07 18:24:51 +02:00
|
|
|
while [ "clear" = "`getprop ${property#persist.}`" ]; do
|
2016-06-06 20:22:13 +02:00
|
|
|
continue
|
|
|
|
done
|
2016-07-21 23:00:30 +02:00
|
|
|
# Tell Settings that we are back on again if we turned logging off
|
|
|
|
tag="${log_tag#Settings}"
|
|
|
|
if [ X"${log_tag}" != X"${tag}" ]; then
|
|
|
|
echo "WARNING: enabling logd service" >&2
|
|
|
|
setprop ${log_tag_property} "${tag#,}"
|
|
|
|
fi
|
2016-04-12 23:35:27 +02:00
|
|
|
# ${service}.rc does the heavy lifting with the following trigger
|
2016-06-06 20:22:13 +02:00
|
|
|
setprop ${property} ${service}
|
2016-04-12 23:35:27 +02:00
|
|
|
# 20ms done, to permit process feedback check
|
2015-05-26 23:57:13 +02:00
|
|
|
sleep 1
|
2016-07-07 18:24:51 +02:00
|
|
|
getprop ${property#persist.}
|
2016-06-02 00:35:41 +02:00
|
|
|
# also generate an error return code if not found running
|
2016-08-04 00:13:51 +02:00
|
|
|
pgrep -u ${log_uid} ${service%d}
|
2015-05-26 23:57:13 +02:00
|
|
|
;;
|
|
|
|
*.stop)
|
2016-04-12 23:35:27 +02:00
|
|
|
if [ -n "${size}${buffer}" ]; then
|
|
|
|
echo "WARNING: Can not use --size or --buffer with ${progname%.*}.stop" >&2
|
|
|
|
fi
|
2016-06-06 20:22:13 +02:00
|
|
|
if [ "true" = "${clear}" ]; then
|
2019-10-30 22:52:01 +01:00
|
|
|
setprop ${property#persist.} "clear"
|
2016-06-06 20:22:13 +02:00
|
|
|
else
|
2019-10-30 22:52:01 +01:00
|
|
|
setprop ${property#persist.} "stop"
|
2016-06-06 20:22:13 +02:00
|
|
|
fi
|
2016-07-07 18:24:51 +02:00
|
|
|
if [ -n "`getprop ${property#persist.}.buffer`" ]; then
|
2016-06-06 20:22:13 +02:00
|
|
|
setprop ${property}.buffer ""
|
2016-07-07 18:24:51 +02:00
|
|
|
# deal with trampoline for empty properties
|
|
|
|
setprop ${property#persist.}.buffer ""
|
2016-04-12 23:35:27 +02:00
|
|
|
fi
|
2016-07-07 18:24:51 +02:00
|
|
|
if [ -n "`getprop ${property#persist.}.size`" ]; then
|
2016-06-06 20:22:13 +02:00
|
|
|
setprop ${property}.size ""
|
2016-07-07 18:24:51 +02:00
|
|
|
# deal with trampoline for empty properties
|
|
|
|
setprop ${property#persist.}.size ""
|
2016-04-12 23:35:27 +02:00
|
|
|
fi
|
2016-07-07 18:24:51 +02:00
|
|
|
while [ "clear" = "`getprop ${property#persist.}`" ]; do
|
2016-06-06 20:22:13 +02:00
|
|
|
continue
|
|
|
|
done
|
2015-05-26 23:57:13 +02:00
|
|
|
;;
|
|
|
|
*)
|
2016-04-12 23:35:27 +02:00
|
|
|
echo "ERROR: Unexpected command ${0##*/} ${args}" >&2
|
2015-05-26 23:57:13 +02:00
|
|
|
exit 1
|
|
|
|
esac
|
2016-07-21 23:00:30 +02:00
|
|
|
|
|
|
|
if [ X"${log_tag}" != X"`getprop ${log_tag_property}`" ] ||
|
|
|
|
[ X"${logd_logpersistd}" != X"`getprop ${property}`" ]; then
|
2016-08-04 17:39:52 +02:00
|
|
|
echo "WARNING: killing Settings application to pull in new values" >&2
|
2016-07-21 23:00:30 +02:00
|
|
|
am force-stop com.android.settings
|
|
|
|
fi
|