Loading sdcard/Android.mk +1 −2 Original line number Diff line number Diff line Loading @@ -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) sdcard/sdcard.c +21 −29 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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> Loading @@ -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> Loading Loading @@ -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 }; Loading Loading @@ -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) { Loading @@ -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 { Loading @@ -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; Loading Loading
sdcard/Android.mk +1 −2 Original line number Diff line number Diff line Loading @@ -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)
sdcard/sdcard.c +21 −29 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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> Loading @@ -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> Loading Loading @@ -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 }; Loading Loading @@ -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) { Loading @@ -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 { Loading @@ -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; Loading