Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 1 | #! /system/bin/sh |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 2 | # logpersist cat, start and stop handlers |
Mark Salyzyn | 1b9456a | 2015-09-21 10:45:10 -0700 | [diff] [blame] | 3 | progname="${0##*/}" |
Mark Salyzyn | d1f41d6 | 2016-02-09 15:49:29 -0800 | [diff] [blame] | 4 | case `getprop ro.debuggable` in |
| 5 | 1) ;; |
Mark Salyzyn | 1b9456a | 2015-09-21 10:45:10 -0700 | [diff] [blame] | 6 | *) echo "${progname} - Permission denied" |
| 7 | exit 1 |
| 8 | ;; |
| 9 | esac |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 10 | |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 11 | property=persist.logd.logpersistd |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 12 | |
| 13 | case `getprop ${property#persist.}.enable` in |
| 14 | true) ;; |
| 15 | *) echo "${progname} - Disabled" |
| 16 | exit 1 |
| 17 | ;; |
| 18 | esac |
| 19 | |
| 20 | data=/data/misc/logd |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 21 | service=logcatd |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 22 | size_default=256 |
| 23 | buffer_default=all |
| 24 | args="${@}" |
| 25 | |
| 26 | size=${size_default} |
| 27 | buffer=${buffer_default} |
| 28 | clear=false |
| 29 | while [ ${#} -gt 0 ]; do |
| 30 | case ${1} in |
| 31 | -c|--clear) clear=true ;; |
| 32 | --size=*) size="${1#--size=}" ;; |
| 33 | --rotate-count=*) size="${1#--rotate-count=}" ;; |
| 34 | -n|--size|--rotate-count) size="${2}" ; shift ;; |
| 35 | --buffer=*) buffer="${1#--buffer=}" ;; |
| 36 | -b|--buffer) buffer="${2}" ; shift ;; |
| 37 | -h|--help|*) |
| 38 | LEAD_SPACE_="`echo ${progname%.*} | tr '[ -~]' ' '`" |
Mark Salyzyn | 1d94511 | 2016-06-01 15:35:41 -0700 | [diff] [blame] | 39 | echo "${progname%.*}.cat - dump current ${service} logs" |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 40 | echo "${progname%.*}.start [--size=<size_in_kb>] [--buffer=<buffers>] [--clear]" |
| 41 | echo "${LEAD_SPACE_} - start ${service} service" |
| 42 | echo "${progname%.*}.stop [--clear] - stop ${service} service" |
| 43 | case ${1} in |
| 44 | -h|--help) exit 0 ;; |
| 45 | *) echo ERROR: bad argument ${@} >&2 ; exit 1 ;; |
| 46 | esac |
| 47 | ;; |
| 48 | esac |
| 49 | shift |
| 50 | done |
| 51 | |
| 52 | if [ -z "${size}" -o "${size_default}" = "${size}" ]; then |
| 53 | unset size |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 54 | fi |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 55 | if [ -n "${size}" ] && |
| 56 | ! ( [ 0 -lt "${size}" ] && [ 2048 -ge "${size}" ] ) >/dev/null 2>&1; then |
| 57 | echo ERROR: Invalid --size ${size} >&2 |
| 58 | exit 1 |
| 59 | fi |
| 60 | if [ -z "${buffer}" -o "${buffer_default}" = "${buffer}" ]; then |
| 61 | unset buffer |
| 62 | fi |
| 63 | if [ -n "${buffer}" ] && ! logcat -b ${buffer} -g >/dev/null 2>&1; then |
| 64 | echo ERROR: Invalid --buffer ${buffer} >&2 |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 68 | case ${progname} in |
| 69 | *.cat) |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 70 | if [ -n "${size}${buffer}" -o "true" = "${clear}" ]; then |
| 71 | echo WARNING: Can not use --clear, --size or --buffer with ${progname%.*}.cat >&2 |
| 72 | fi |
| 73 | su logd ls "${data}" | |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 74 | tr -d '\r' | |
| 75 | sort -ru | |
| 76 | sed "s#^#${data}/#" | |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 77 | su logd xargs cat |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 78 | ;; |
| 79 | *.start) |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 80 | current_buffer="`getprop ${property#persist.}.buffer`" |
| 81 | current_size="`getprop ${property#persist.}.size`" |
| 82 | if [ "${service}" = "`getprop ${property#persist.}`" ]; then |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 83 | if [ "true" = "${clear}" ]; then |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 84 | setprop ${property#persist.} "clear" |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 85 | elif [ "${buffer}|${size}" != "${current_buffer}|${current_size}" ]; then |
| 86 | echo "ERROR: Changing existing collection parameters from" >&2 |
| 87 | if [ "${buffer}" != "${current_buffer}" ]; then |
| 88 | a=${current_buffer} |
| 89 | b=${buffer} |
| 90 | if [ -z "${a}" ]; then a="${default_buffer}"; fi |
| 91 | if [ -z "${b}" ]; then b="${default_buffer}"; fi |
| 92 | echo " --buffer ${a} to ${b}" >&2 |
| 93 | fi |
| 94 | if [ "${size}" != "${current_size}" ]; then |
| 95 | a=${current_size} |
| 96 | b=${size} |
| 97 | if [ -z "${a}" ]; then a="${default_size}"; fi |
| 98 | if [ -z "${b}" ]; then b="${default_size}"; fi |
| 99 | echo " --size ${a} to ${b}" >&2 |
| 100 | fi |
| 101 | echo " Are you sure you want to do this?" >&2 |
| 102 | echo " Suggest add --clear to erase data and restart with new settings." >&2 |
| 103 | echo " To blindly override and retain data, ${progname%.*}.stop first." >&2 |
| 104 | exit 1 |
| 105 | fi |
Mark Salyzyn | cd5118b | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 106 | elif [ "true" = "${clear}" ]; then |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 107 | setprop ${property#persist.} "clear" |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 108 | fi |
| 109 | if [ -n "${buffer}${current_buffer}" ]; then |
Mark Salyzyn | 8d2a655 | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 110 | setprop ${property}.buffer "${buffer}" |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 111 | if [ -z "${buffer}" ]; then |
| 112 | # deal with trampoline for empty properties |
| 113 | setprop ${property#persist.}.buffer "" |
| 114 | fi |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 115 | fi |
| 116 | if [ -n "${size}${current_size}" ]; then |
Mark Salyzyn | 8d2a655 | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 117 | setprop ${property}.size "${size}" |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 118 | if [ -z "${size}" ]; then |
| 119 | # deal with trampoline for empty properties |
| 120 | setprop ${property#persist.}.size "" |
| 121 | fi |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 122 | fi |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 123 | while [ "clear" = "`getprop ${property#persist.}`" ]; do |
Mark Salyzyn | cd5118b | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 124 | continue |
| 125 | done |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 126 | # ${service}.rc does the heavy lifting with the following trigger |
Mark Salyzyn | 8d2a655 | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 127 | setprop ${property} ${service} |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 128 | # 20ms done, to permit process feedback check |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 129 | sleep 1 |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 130 | getprop ${property#persist.} |
Mark Salyzyn | 1d94511 | 2016-06-01 15:35:41 -0700 | [diff] [blame] | 131 | # also generate an error return code if not found running |
| 132 | pgrep -u ${data##*/} ${service%d} |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 133 | ;; |
| 134 | *.stop) |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 135 | if [ -n "${size}${buffer}" ]; then |
| 136 | echo "WARNING: Can not use --size or --buffer with ${progname%.*}.stop" >&2 |
| 137 | fi |
Mark Salyzyn | cd5118b | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 138 | if [ "true" = "${clear}" ]; then |
| 139 | setprop ${property} "clear" |
| 140 | else |
| 141 | setprop ${property} "stop" |
| 142 | fi |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 143 | if [ -n "`getprop ${property#persist.}.buffer`" ]; then |
Mark Salyzyn | 8d2a655 | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 144 | setprop ${property}.buffer "" |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 145 | # deal with trampoline for empty properties |
| 146 | setprop ${property#persist.}.buffer "" |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 147 | fi |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 148 | if [ -n "`getprop ${property#persist.}.size`" ]; then |
Mark Salyzyn | 8d2a655 | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 149 | setprop ${property}.size "" |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 150 | # deal with trampoline for empty properties |
| 151 | setprop ${property#persist.}.size "" |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 152 | fi |
Mark Salyzyn | 2591d48 | 2016-07-07 09:24:51 -0700 | [diff] [blame^] | 153 | while [ "clear" = "`getprop ${property#persist.}`" ]; do |
Mark Salyzyn | cd5118b | 2016-06-06 11:22:13 -0700 | [diff] [blame] | 154 | continue |
| 155 | done |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 156 | ;; |
| 157 | *) |
Mark Salyzyn | 2e210e4 | 2016-04-12 14:35:27 -0700 | [diff] [blame] | 158 | echo "ERROR: Unexpected command ${0##*/} ${args}" >&2 |
Mark Salyzyn | 100658c | 2015-05-26 14:57:13 -0700 | [diff] [blame] | 159 | exit 1 |
| 160 | esac |