Merge "logd: use libpackageparser"

This commit is contained in:
Daniel Cashman 2015-10-22 23:03:51 +00:00 committed by Gerrit Code Review
commit 89065609c9
2 changed files with 18 additions and 27 deletions

View File

@ -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 \

View File

@ -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.
packagelist_parse(package_list_parser_cb, NULL);
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);
}
uid = 0;
sem_post(&uidName);
continue;