diff options
author | William Roberts <william.c.roberts@intel.com> | 2015-07-31 13:11:19 -0700 |
---|---|---|
committer | William C Roberts <william.c.roberts@intel.com> | 2015-10-22 22:52:35 +0000 |
commit | e509980542f36dd1ecbbcc4afb6e9e7d2d536c12 (patch) | |
tree | cad857f761b27959f126a8de8a1a1aa776e61523 /sdcard/sdcard.c | |
parent | c52b3c08fa5ea3680ffcd68c2a1d0542d09f0509 (diff) | |
download | core-e509980542f36dd1ecbbcc4afb6e9e7d2d536c12.tar.gz core-e509980542f36dd1ecbbcc4afb6e9e7d2d536c12.tar.bz2 core-e509980542f36dd1ecbbcc4afb6e9e7d2d536c12.zip |
sdcard: use libpackageparser
Switch from the internal packages.list file parser
implementation to a common parser library.
See Change-Id: I87a406802f95d8e7bfd8ee85f723f80e9e6b6c0c
for all of the details.
Change-Id: I98924dce406b322e0d402bca7fdac51f6a1e6a4b
Signed-off-by: William Roberts <william.c.roberts@intel.com>
Diffstat (limited to 'sdcard/sdcard.c')
-rw-r--r-- | sdcard/sdcard.c | 50 |
1 files changed, 21 insertions, 29 deletions
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; |