Loading sdcard/Android.mk +1 −2 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,6 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := sdcard.c LOCAL_SRC_FILES := sdcard.c LOCAL_MODULE := sdcard LOCAL_MODULE := sdcard LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror LOCAL_SHARED_LIBRARIES := libcutils libpackagelistparser LOCAL_SHARED_LIBRARIES := libcutils include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE) sdcard/sdcard.c +21 −29 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <limits.h> #include <limits.h> #include <linux/fuse.h> #include <linux/fuse.h> #include <pthread.h> #include <pthread.h> #include <stdbool.h> #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include <stdlib.h> #include <string.h> #include <string.h> Loading @@ -34,6 +35,7 @@ #include <sys/stat.h> #include <sys/stat.h> #include <sys/statfs.h> #include <sys/statfs.h> #include <sys/time.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/uio.h> #include <unistd.h> #include <unistd.h> Loading @@ -41,6 +43,7 @@ #include <cutils/hashmap.h> #include <cutils/hashmap.h> #include <cutils/log.h> #include <cutils/log.h> #include <cutils/multiuser.h> #include <cutils/multiuser.h> #include <packagelistparser/packagelistparser.h> #include <private/android_filesystem_config.h> #include <private/android_filesystem_config.h> Loading Loading @@ -103,9 +106,6 @@ * or that a reply has already been written. */ * or that a reply has already been written. */ #define NO_STATUS 1 #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 */ /* Supplementary groups to execute with */ static const gid_t kGroups[1] = { AID_PACKAGE_INFO }; 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; return true; } } static int read_package_list(struct fuse_global* global) { static bool package_parse_callback(pkg_info *info, void *userdata) { pthread_mutex_lock(&global->lock); struct fuse_global *global = (struct fuse_global *)userdata; hashmapForEach(global->package_to_appid, remove_str_to_int, global->package_to_appid); FILE* file = fopen(kPackagesListFile, "r"); char* name = strdup(info->name); if (!file) { hashmapPut(global->package_to_appid, name, (void*) (uintptr_t) info->uid); ERROR("failed to open package list: %s\n", strerror(errno)); packagelist_free(info); pthread_mutex_unlock(&global->lock); return true; return -1; } } char buf[512]; static bool read_package_list(struct fuse_global* global) { while (fgets(buf, sizeof(buf), file) != NULL) { pthread_mutex_lock(&global->lock); char package_name[512]; int appid; char gids[512]; if (sscanf(buf, "%s %d %*d %*s %*s %s", package_name, &appid, gids) == 3) { hashmapForEach(global->package_to_appid, remove_str_to_int, global->package_to_appid); char* package_name_dup = strdup(package_name); hashmapPut(global->package_to_appid, package_name_dup, (void*) (uintptr_t) appid); } } bool rc = packagelist_parse(package_parse_callback, global); TRACE("read_package_list: found %zu packages\n", TRACE("read_package_list: found %zu packages\n", hashmapSize(global->package_to_appid)); hashmapSize(global->package_to_appid)); fclose(file); pthread_mutex_unlock(&global->lock); pthread_mutex_unlock(&global->lock); return 0; return rc; } } static void watch_package_list(struct fuse_global* global) { 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; bool active = false; while (1) { while (1) { if (!active) { 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 (res == -1) { if (errno == ENOENT || errno == EACCES) { if (errno == ENOENT || errno == EACCES) { /* Framework may not have created yet, sleep and retry */ /* 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); sleep(3); continue; continue; } else { } 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 /* Watch above will tell us about any future changes, so * read the current state. */ * read the current state. */ if (read_package_list(global) == -1) { if (read_package_list(global) == false) { ERROR("read_package_list failed: %s\n", strerror(errno)); ERROR("read_package_list failed\n"); return; return; } } active = true; active = true; Loading Loading
sdcard/Android.mk +1 −2 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,6 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := sdcard.c LOCAL_SRC_FILES := sdcard.c LOCAL_MODULE := sdcard LOCAL_MODULE := sdcard LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror LOCAL_SHARED_LIBRARIES := libcutils libpackagelistparser LOCAL_SHARED_LIBRARIES := libcutils include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
sdcard/sdcard.c +21 −29 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <limits.h> #include <limits.h> #include <linux/fuse.h> #include <linux/fuse.h> #include <pthread.h> #include <pthread.h> #include <stdbool.h> #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include <stdlib.h> #include <string.h> #include <string.h> Loading @@ -34,6 +35,7 @@ #include <sys/stat.h> #include <sys/stat.h> #include <sys/statfs.h> #include <sys/statfs.h> #include <sys/time.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/uio.h> #include <unistd.h> #include <unistd.h> Loading @@ -41,6 +43,7 @@ #include <cutils/hashmap.h> #include <cutils/hashmap.h> #include <cutils/log.h> #include <cutils/log.h> #include <cutils/multiuser.h> #include <cutils/multiuser.h> #include <packagelistparser/packagelistparser.h> #include <private/android_filesystem_config.h> #include <private/android_filesystem_config.h> Loading Loading @@ -103,9 +106,6 @@ * or that a reply has already been written. */ * or that a reply has already been written. */ #define NO_STATUS 1 #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 */ /* Supplementary groups to execute with */ static const gid_t kGroups[1] = { AID_PACKAGE_INFO }; 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; return true; } } static int read_package_list(struct fuse_global* global) { static bool package_parse_callback(pkg_info *info, void *userdata) { pthread_mutex_lock(&global->lock); struct fuse_global *global = (struct fuse_global *)userdata; hashmapForEach(global->package_to_appid, remove_str_to_int, global->package_to_appid); FILE* file = fopen(kPackagesListFile, "r"); char* name = strdup(info->name); if (!file) { hashmapPut(global->package_to_appid, name, (void*) (uintptr_t) info->uid); ERROR("failed to open package list: %s\n", strerror(errno)); packagelist_free(info); pthread_mutex_unlock(&global->lock); return true; return -1; } } char buf[512]; static bool read_package_list(struct fuse_global* global) { while (fgets(buf, sizeof(buf), file) != NULL) { pthread_mutex_lock(&global->lock); char package_name[512]; int appid; char gids[512]; if (sscanf(buf, "%s %d %*d %*s %*s %s", package_name, &appid, gids) == 3) { hashmapForEach(global->package_to_appid, remove_str_to_int, global->package_to_appid); char* package_name_dup = strdup(package_name); hashmapPut(global->package_to_appid, package_name_dup, (void*) (uintptr_t) appid); } } bool rc = packagelist_parse(package_parse_callback, global); TRACE("read_package_list: found %zu packages\n", TRACE("read_package_list: found %zu packages\n", hashmapSize(global->package_to_appid)); hashmapSize(global->package_to_appid)); fclose(file); pthread_mutex_unlock(&global->lock); pthread_mutex_unlock(&global->lock); return 0; return rc; } } static void watch_package_list(struct fuse_global* global) { 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; bool active = false; while (1) { while (1) { if (!active) { 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 (res == -1) { if (errno == ENOENT || errno == EACCES) { if (errno == ENOENT || errno == EACCES) { /* Framework may not have created yet, sleep and retry */ /* 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); sleep(3); continue; continue; } else { } 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 /* Watch above will tell us about any future changes, so * read the current state. */ * read the current state. */ if (read_package_list(global) == -1) { if (read_package_list(global) == false) { ERROR("read_package_list failed: %s\n", strerror(errno)); ERROR("read_package_list failed\n"); return; return; } } active = true; active = true; Loading