diff options
| author | William Roberts <william.c.roberts@intel.com> | 2015-07-31 13:10:36 -0700 |
|---|---|---|
| committer | William Roberts <william.c.roberts@intel.com> | 2015-10-14 20:22:44 -0700 |
| commit | aeca97ba1cb6fdc028dd2f1f984eebb40c85b1fc (patch) | |
| tree | 15726ffcda0a1f3dfe7c72da4d3d57a85d083cf0 /logd | |
| parent | defbd39cebb0aa9a982d91a9900cebfbcd0d59ae (diff) | |
| download | core-aeca97ba1cb6fdc028dd2f1f984eebb40c85b1fc.tar.gz core-aeca97ba1cb6fdc028dd2f1f984eebb40c85b1fc.tar.bz2 core-aeca97ba1cb6fdc028dd2f1f984eebb40c85b1fc.zip | |
logd: use libpackageparser
Switch from the internal packages.list file parser
implementation to a common parser library.
Change-Id: I87a406802f95d8e7bfd8ee85f723f80e9e6b6c0c
Signed-off-by: William Roberts <william.c.roberts@intel.com>
Diffstat (limited to 'logd')
| -rw-r--r-- | logd/Android.mk | 5 | ||||
| -rw-r--r-- | logd/main.cpp | 42 |
2 files changed, 19 insertions, 28 deletions
diff --git a/logd/Android.mk b/logd/Android.mk index c00061b21..f1ea29f5a 100644 --- a/logd/Android.mk +++ b/logd/Android.mk @@ -4,8 +4,6 @@ include $(CLEAR_VARS) LOCAL_MODULE:= logd -LOCAL_INIT_RC := logd.rc - LOCAL_SRC_FILES := \ main.cpp \ LogCommand.cpp \ @@ -27,7 +25,8 @@ LOCAL_SHARED_LIBRARIES := \ libsysutils \ liblog \ libcutils \ - libbase + libbase \ + libpackagelistparser # This is what we want to do: # event_logtags = $(shell \ diff --git a/logd/main.cpp b/logd/main.cpp index 60262e9ff..13dda787a 100644 --- a/logd/main.cpp +++ b/logd/main.cpp @@ -33,12 +33,14 @@ #include <syslog.h> #include <unistd.h> +#include <cstdbool> #include <memory> #include <cutils/properties.h> #include <cutils/sched_policy.h> #include <cutils/sockets.h> #include <log/event_tag_map.h> +#include <packagelistparser/packagelistparser.h> #include <private/android_filesystem_config.h> #include <utils/threads.h> @@ -166,6 +168,19 @@ static sem_t reinit; static bool reinit_running = false; static LogBuffer *logBuf = NULL; +static bool package_list_parser_cb(pkg_info *info, void * /* userdata */) { + + bool rc = true; + if (info->uid == uid) { + name = strdup(info->name); + // false to stop processing + rc = false; + } + + packagelist_free(info); + return rc; +} + static void *reinit_thread_start(void * /*obj*/) { prctl(PR_SET_NAME, "logd.daemon"); set_sched_policy(0, SP_BACKGROUND); @@ -180,31 +195,8 @@ static void *reinit_thread_start(void * /*obj*/) { if (uid) { name = NULL; - FILE *fp = fopen("/data/system/packages.list", "r"); - if (fp) { - // This simple parser is sensitive to format changes in - // frameworks/base/services/core/java/com/android/server/pm/Settings.java - // A dependency note has been added to that file to correct - // this parser. - - char *buffer = NULL; - size_t len; - while (getline(&buffer, &len, fp) > 0) { - char *userId = strchr(buffer, ' '); - if (!userId) { - continue; - } - *userId = '\0'; - unsigned long value = strtoul(userId + 1, NULL, 10); - if (value != uid) { - continue; - } - name = strdup(buffer); - break; - } - free(buffer); - fclose(fp); - } + packagelist_parse(package_list_parser_cb, NULL); + uid = 0; sem_post(&uidName); continue; |
