diff options
-rw-r--r-- | sdcard/Android.mk | 3 | ||||
-rw-r--r-- | sdcard/sdcard.c | 50 |
2 files changed, 22 insertions, 31 deletions
diff --git a/sdcard/Android.mk b/sdcard/Android.mk index cb3a8fb93..c5f3d1d4f 100644 --- a/sdcard/Android.mk +++ b/sdcard/Android.mk @@ -5,7 +5,6 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := sdcard.c LOCAL_MODULE := sdcard LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror - -LOCAL_SHARED_LIBRARIES := libcutils +LOCAL_SHARED_LIBRARIES := libcutils libpackagelistparser include $(BUILD_EXECUTABLE) diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c index d2d231571..b6bbe7efd 100644 --- a/sdcard/sdcard.c +++ b/sdcard/sdcard.c @@ -24,6 +24,7 @@ #include <limits.h> #include <linux/fuse.h> #include <pthread.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -34,6 +35,7 @@ #include <sys/stat.h> #include <sys/statfs.h> #include <sys/time.h> +#include <sys/types.h> #include <sys/uio.h> #include <unistd.h> @@ -41,6 +43,7 @@ #include <cutils/hashmap.h> #include <cutils/log.h> #include <cutils/multiuser.h> +#include <packagelistparser/packagelistparser.h> #include <private/android_filesystem_config.h> @@ -103,9 +106,6 @@ * or that a reply has already been written. */ #define NO_STATUS 1 -/* Path to system-provided mapping of package name to appIds */ -static const char* const kPackagesListFile = "/data/system/packages.list"; - /* Supplementary groups to execute with */ static const gid_t kGroups[1] = { AID_PACKAGE_INFO }; @@ -1636,35 +1636,27 @@ static bool remove_str_to_int(void *key, void *value, void *context) { return true; } -static int read_package_list(struct fuse_global* global) { - pthread_mutex_lock(&global->lock); - - hashmapForEach(global->package_to_appid, remove_str_to_int, global->package_to_appid); +static bool package_parse_callback(pkg_info *info, void *userdata) { + struct fuse_global *global = (struct fuse_global *)userdata; - FILE* file = fopen(kPackagesListFile, "r"); - if (!file) { - ERROR("failed to open package list: %s\n", strerror(errno)); - pthread_mutex_unlock(&global->lock); - return -1; - } + char* name = strdup(info->name); + hashmapPut(global->package_to_appid, name, (void*) (uintptr_t) info->uid); + packagelist_free(info); + return true; +} - char buf[512]; - while (fgets(buf, sizeof(buf), file) != NULL) { - char package_name[512]; - int appid; - char gids[512]; +static bool read_package_list(struct fuse_global* global) { + pthread_mutex_lock(&global->lock); - if (sscanf(buf, "%s %d %*d %*s %*s %s", package_name, &appid, gids) == 3) { - char* package_name_dup = strdup(package_name); - hashmapPut(global->package_to_appid, package_name_dup, (void*) (uintptr_t) appid); - } - } + hashmapForEach(global->package_to_appid, remove_str_to_int, global->package_to_appid); + bool rc = packagelist_parse(package_parse_callback, global); TRACE("read_package_list: found %zu packages\n", hashmapSize(global->package_to_appid)); - fclose(file); + pthread_mutex_unlock(&global->lock); - return 0; + + return rc; } static void watch_package_list(struct fuse_global* global) { @@ -1680,11 +1672,11 @@ static void watch_package_list(struct fuse_global* global) { bool active = false; while (1) { if (!active) { - int res = inotify_add_watch(nfd, kPackagesListFile, IN_DELETE_SELF); + int res = inotify_add_watch(nfd, PACKAGES_LIST_FILE, IN_DELETE_SELF); if (res == -1) { if (errno == ENOENT || errno == EACCES) { /* Framework may not have created yet, sleep and retry */ - ERROR("missing packages.list; retrying\n"); + ERROR("missing \"%s\"; retrying\n", PACKAGES_LIST_FILE); sleep(3); continue; } else { @@ -1695,8 +1687,8 @@ static void watch_package_list(struct fuse_global* global) { /* Watch above will tell us about any future changes, so * read the current state. */ - if (read_package_list(global) == -1) { - ERROR("read_package_list failed: %s\n", strerror(errno)); + if (read_package_list(global) == false) { + ERROR("read_package_list failed\n"); return; } active = true; |