blob: e9982e2b7ee5c37e73e6758f5cdbf166c8567343 [file] [log] [blame]
Mark Salyzyn100658c2015-05-26 14:57:13 -07001#! /system/bin/sh
Mark Salyzyn2e210e42016-04-12 14:35:27 -07002# logpersist cat, start and stop handlers
Mark Salyzyn1b9456a2015-09-21 10:45:10 -07003progname="${0##*/}"
Mark Salyzynd1f41d62016-02-09 15:49:29 -08004case `getprop ro.debuggable` in
51) ;;
Mark Salyzyn1b9456a2015-09-21 10:45:10 -07006*) echo "${progname} - Permission denied"
7 exit 1
8 ;;
9esac
Mark Salyzyn2e210e42016-04-12 14:35:27 -070010
Mark Salyzyn100658c2015-05-26 14:57:13 -070011property=persist.logd.logpersistd
Mark Salyzyn2591d482016-07-07 09:24:51 -070012
13case `getprop ${property#persist.}.enable` in
14true) ;;
15*) echo "${progname} - Disabled"
16 exit 1
17 ;;
18esac
19
20data=/data/misc/logd
Mark Salyzyn100658c2015-05-26 14:57:13 -070021service=logcatd
Mark Salyzyn2e210e42016-04-12 14:35:27 -070022size_default=256
23buffer_default=all
24args="${@}"
25
26size=${size_default}
27buffer=${buffer_default}
28clear=false
29while [ ${#} -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 Salyzyn1d945112016-06-01 15:35:41 -070039 echo "${progname%.*}.cat - dump current ${service} logs"
Mark Salyzyn2e210e42016-04-12 14:35:27 -070040 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
50done
51
52if [ -z "${size}" -o "${size_default}" = "${size}" ]; then
53 unset size
Mark Salyzyn100658c2015-05-26 14:57:13 -070054fi
Mark Salyzyn2e210e42016-04-12 14:35:27 -070055if [ -n "${size}" ] &&
56 ! ( [ 0 -lt "${size}" ] && [ 2048 -ge "${size}" ] ) >/dev/null 2>&1; then
57 echo ERROR: Invalid --size ${size} >&2
58 exit 1
59fi
60if [ -z "${buffer}" -o "${buffer_default}" = "${buffer}" ]; then
61 unset buffer
62fi
63if [ -n "${buffer}" ] && ! logcat -b ${buffer} -g >/dev/null 2>&1; then
64 echo ERROR: Invalid --buffer ${buffer} >&2
65 exit 1
66fi
67
Mark Salyzyn100658c2015-05-26 14:57:13 -070068case ${progname} in
69*.cat)
Mark Salyzyn2e210e42016-04-12 14:35:27 -070070 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 Salyzyn100658c2015-05-26 14:57:13 -070074 tr -d '\r' |
75 sort -ru |
76 sed "s#^#${data}/#" |
Mark Salyzyn2e210e42016-04-12 14:35:27 -070077 su logd xargs cat
Mark Salyzyn100658c2015-05-26 14:57:13 -070078 ;;
79*.start)
Mark Salyzyn2591d482016-07-07 09:24:51 -070080 current_buffer="`getprop ${property#persist.}.buffer`"
81 current_size="`getprop ${property#persist.}.size`"
82 if [ "${service}" = "`getprop ${property#persist.}`" ]; then
Mark Salyzyn2e210e42016-04-12 14:35:27 -070083 if [ "true" = "${clear}" ]; then
Mark Salyzyn2591d482016-07-07 09:24:51 -070084 setprop ${property#persist.} "clear"
Mark Salyzyn2e210e42016-04-12 14:35:27 -070085 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 Salyzyncd5118b2016-06-06 11:22:13 -0700106 elif [ "true" = "${clear}" ]; then
Mark Salyzyn2591d482016-07-07 09:24:51 -0700107 setprop ${property#persist.} "clear"
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700108 fi
109 if [ -n "${buffer}${current_buffer}" ]; then
Mark Salyzyn8d2a6552016-06-06 11:22:13 -0700110 setprop ${property}.buffer "${buffer}"
Mark Salyzyn2591d482016-07-07 09:24:51 -0700111 if [ -z "${buffer}" ]; then
112 # deal with trampoline for empty properties
113 setprop ${property#persist.}.buffer ""
114 fi
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700115 fi
116 if [ -n "${size}${current_size}" ]; then
Mark Salyzyn8d2a6552016-06-06 11:22:13 -0700117 setprop ${property}.size "${size}"
Mark Salyzyn2591d482016-07-07 09:24:51 -0700118 if [ -z "${size}" ]; then
119 # deal with trampoline for empty properties
120 setprop ${property#persist.}.size ""
121 fi
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700122 fi
Mark Salyzyn2591d482016-07-07 09:24:51 -0700123 while [ "clear" = "`getprop ${property#persist.}`" ]; do
Mark Salyzyncd5118b2016-06-06 11:22:13 -0700124 continue
125 done
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700126 # ${service}.rc does the heavy lifting with the following trigger
Mark Salyzyn8d2a6552016-06-06 11:22:13 -0700127 setprop ${property} ${service}
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700128 # 20ms done, to permit process feedback check
Mark Salyzyn100658c2015-05-26 14:57:13 -0700129 sleep 1
Mark Salyzyn2591d482016-07-07 09:24:51 -0700130 getprop ${property#persist.}
Mark Salyzyn1d945112016-06-01 15:35:41 -0700131 # also generate an error return code if not found running
132 pgrep -u ${data##*/} ${service%d}
Mark Salyzyn100658c2015-05-26 14:57:13 -0700133 ;;
134*.stop)
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700135 if [ -n "${size}${buffer}" ]; then
136 echo "WARNING: Can not use --size or --buffer with ${progname%.*}.stop" >&2
137 fi
Mark Salyzyncd5118b2016-06-06 11:22:13 -0700138 if [ "true" = "${clear}" ]; then
139 setprop ${property} "clear"
140 else
141 setprop ${property} "stop"
142 fi
Mark Salyzyn2591d482016-07-07 09:24:51 -0700143 if [ -n "`getprop ${property#persist.}.buffer`" ]; then
Mark Salyzyn8d2a6552016-06-06 11:22:13 -0700144 setprop ${property}.buffer ""
Mark Salyzyn2591d482016-07-07 09:24:51 -0700145 # deal with trampoline for empty properties
146 setprop ${property#persist.}.buffer ""
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700147 fi
Mark Salyzyn2591d482016-07-07 09:24:51 -0700148 if [ -n "`getprop ${property#persist.}.size`" ]; then
Mark Salyzyn8d2a6552016-06-06 11:22:13 -0700149 setprop ${property}.size ""
Mark Salyzyn2591d482016-07-07 09:24:51 -0700150 # deal with trampoline for empty properties
151 setprop ${property#persist.}.size ""
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700152 fi
Mark Salyzyn2591d482016-07-07 09:24:51 -0700153 while [ "clear" = "`getprop ${property#persist.}`" ]; do
Mark Salyzyncd5118b2016-06-06 11:22:13 -0700154 continue
155 done
Mark Salyzyn100658c2015-05-26 14:57:13 -0700156 ;;
157*)
Mark Salyzyn2e210e42016-04-12 14:35:27 -0700158 echo "ERROR: Unexpected command ${0##*/} ${args}" >&2
Mark Salyzyn100658c2015-05-26 14:57:13 -0700159 exit 1
160esac