From 49ed105fd91677f7c87417890bf7441146953fff Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 26 May 2015 14:57:13 -0700 Subject: [PATCH] init.rc: logd: Add logpersistd (nee logcatd) (cherry pick from commit 100658c303919d8f69c76f6f25eac376795712f0) - logpersistd is defined as a thread or process in the context of the logd domain. Here we define logpersistd as logcat -f in logd domain and call it logcatd to represent its service mechanics. - Use logcatd to manage content in /data/misc/logd/ directory. - Only turn on for persist.logd.logpersistd = logcatd. - Add logpersist.start, logpersist.stop and logpersist.cat debug class executables, thus only in the eng and userdebug builds. ToDo: Wish to add Developer Options menu to turn this feature on or off, complicated by the fact that user builds have no tools with access rights to /data/misc/logd. Bug: 19608716 Change-Id: I57ad757f121c473d04f9fabe9d4820a0eca06f31 --- logd/Android.mk | 11 +++++++++++ logd/README.property | 2 ++ logd/logpersist | 36 ++++++++++++++++++++++++++++++++++++ rootdir/init.rc | 14 ++++++++++++++ 4 files changed, 63 insertions(+) create mode 100755 logd/logpersist diff --git a/logd/Android.mk b/logd/Android.mk index 73da8dc61..615d03048 100644 --- a/logd/Android.mk +++ b/logd/Android.mk @@ -41,4 +41,15 @@ LOCAL_CFLAGS := -Werror $(event_flag) include $(BUILD_EXECUTABLE) +include $(CLEAR_VARS) + +LOCAL_MODULE := logpersist.start +LOCAL_MODULE_TAGS := debug +LOCAL_MODULE_CLASS := EXECUTABLES +LOCAL_MODULE_PATH := $(bin_dir) +LOCAL_SRC_FILES := logpersist +ALL_TOOLS := logpersist.start logpersist.stop logpersist.cat +LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(filter-out $(LOCAL_MODULE),$(ALL_TOOLS)),ln -sf $(LOCAL_MODULE) $(TARGET_OUT)/bin/$(t);) +include $(BUILD_PREBUILT) + include $(call first-makefiles-under,$(LOCAL_PATH)) diff --git a/logd/README.property b/logd/README.property index ad7d0cd3e..a472efde9 100644 --- a/logd/README.property +++ b/logd/README.property @@ -10,6 +10,8 @@ ro.config.low_ram bool false if true, logd.statistics & logd.klogd default false ro.build.type string if user, logd.statistics & logd.klogd default false +persist.logd.logpersistd string Enable logpersist daemon, "logcatd" + turns on logcat -f in logd context persist.logd.size number 256K default size of the buffer for all log ids at initial startup, at runtime use: logcat -b all -G diff --git a/logd/logpersist b/logd/logpersist new file mode 100755 index 000000000..215e1e2d9 --- /dev/null +++ b/logd/logpersist @@ -0,0 +1,36 @@ +#! /system/bin/sh +# logpersist cat start and stop handlers +data=/data/misc/logd +property=persist.logd.logpersistd +service=logcatd +progname="${0##*/}" +if [ X"${1}" = "-h" -o X"${1}" = X"--help" ]; then + echo "${progname%.*}.cat - dump current ${service%d} logs" + echo "${progname%.*}.start - start ${service} service" + echo "${progname%.*}.stop [--clear] - stop ${service} service" + exit 0 +fi +case ${progname} in +*.cat) + su 1036 ls "${data}" | + tr -d '\r' | + sort -ru | + sed "s#^#${data}/#" | + su 1036 xargs cat + ;; +*.start) + su 0 setprop ${property} ${service} + getprop ${property} + sleep 1 + ps -t | grep "${data##*/}.*${service%d}" + ;; +*.stop) + su 0 stop ${service} + su 0 setprop ${property} "" + [ X"${1}" != X"-c" -a X"${1}" != X"--clear" ] || + ( sleep 1 ; su 1036,9998 rm -rf "${data}" ) + ;; +*) + echo "Unexpected command ${0##*/} ${@}" >&2 + exit 1 +esac diff --git a/rootdir/init.rc b/rootdir/init.rc index a3cf6f13b..d0768b2a6 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -668,3 +668,17 @@ service perfprofd /system/xbin/perfprofd class late_start user root oneshot + +on property:persist.logd.logpersistd=logcatd + # all exec/services are called with umask(077), so no gain beyond 0700 + mkdir /data/misc/logd 0700 logd log + # logd for write to /data/misc/logd, log group for read from pstore (-L) + exec - logd log -- /system/bin/logcat -L -b all -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 64 -n 256 + start logcatd + +service logcatd /system/bin/logcat -b all -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 64 -n 256 + class late_start + disabled + # logd for write to /data/misc/logd, log group for read from log daemon + user logd + group log