Loading libcutils/canned_fs_config.c +81 −75 Original line number Original line Diff line number Diff line Loading @@ -14,12 +14,12 @@ * limitations under the License. * limitations under the License. */ */ #include <inttypes.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <errno.h> #include <inttypes.h> #include <limits.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <stdlib.h> #include <string.h> #include <private/android_filesystem_config.h> #include <private/android_filesystem_config.h> #include <private/canned_fs_config.h> #include <private/canned_fs_config.h> Loading @@ -41,26 +41,30 @@ static int path_compare(const void* a, const void* b) { } } int load_canned_fs_config(const char* fn) { int load_canned_fs_config(const char* fn) { FILE* f = fopen(fn, "r"); char line[PATH_MAX + 200]; FILE* f; f = fopen(fn, "r"); if (f == NULL) { if (f == NULL) { fprintf(stderr, "failed to open %s: %s\n", fn, strerror(errno)); fprintf(stderr, "failed to open %s: %s\n", fn, strerror(errno)); return -1; return -1; } } char line[PATH_MAX + 200]; while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) { Path* p; char* token; while (canned_used >= canned_alloc) { while (canned_used >= canned_alloc) { canned_alloc = (canned_alloc+1) * 2; canned_alloc = (canned_alloc+1) * 2; canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path)); canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path)); } } Path* p = canned_data + canned_used; p = canned_data + canned_used; p->path = strdup(strtok(line, " ")); p->path = strdup(strtok(line, " ")); p->uid = atoi(strtok(NULL, " ")); p->uid = atoi(strtok(NULL, " ")); p->gid = atoi(strtok(NULL, " ")); p->gid = atoi(strtok(NULL, " ")); p->mode = strtol(strtok(NULL, " "), NULL, 8); // mode is in octal p->mode = strtol(strtok(NULL, " "), NULL, 8); // mode is in octal p->capabilities = 0; p->capabilities = 0; char* token = NULL; do { do { token = strtok(NULL, " "); token = strtok(NULL, " "); if (token && strncmp(token, "capabilities=", 13) == 0) { if (token && strncmp(token, "capabilities=", 13) == 0) { Loading @@ -84,11 +88,11 @@ static const int kDebugCannedFsConfig = 0; void canned_fs_config(const char* path, int dir, const char* target_out_path, void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) { unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) { Path key; Path key, *p; key.path = path; key.path = path; if (path[0] == '/') if (path[0] == '/') key.path++; // canned paths lack the leading '/' key.path++; // canned paths lack the leading '/' p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare); Path* p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare); if (p == NULL) { if (p == NULL) { fprintf(stderr, "failed to find [%s] in canned fs_config\n", path); fprintf(stderr, "failed to find [%s] in canned fs_config\n", path); exit(1); exit(1); Loading @@ -103,15 +107,17 @@ void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned c_uid, c_gid, c_mode; unsigned c_uid, c_gid, c_mode; uint64_t c_capabilities; uint64_t c_capabilities; fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities); fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities); if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid); if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid); if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid); if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid); if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode); if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode); if (c_capabilities != *capabilities) if (c_capabilities != *capabilities) { printf("%s capabilities %" PRIx64 " %" PRIx64 "\n", printf("%s capabilities %" PRIx64 " %" PRIx64 "\n", path, path, *capabilities, *capabilities, c_capabilities); c_capabilities); } } } } } Loading
libcutils/canned_fs_config.c +81 −75 Original line number Original line Diff line number Diff line Loading @@ -14,12 +14,12 @@ * limitations under the License. * limitations under the License. */ */ #include <inttypes.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <errno.h> #include <inttypes.h> #include <limits.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <stdlib.h> #include <string.h> #include <private/android_filesystem_config.h> #include <private/android_filesystem_config.h> #include <private/canned_fs_config.h> #include <private/canned_fs_config.h> Loading @@ -41,26 +41,30 @@ static int path_compare(const void* a, const void* b) { } } int load_canned_fs_config(const char* fn) { int load_canned_fs_config(const char* fn) { FILE* f = fopen(fn, "r"); char line[PATH_MAX + 200]; FILE* f; f = fopen(fn, "r"); if (f == NULL) { if (f == NULL) { fprintf(stderr, "failed to open %s: %s\n", fn, strerror(errno)); fprintf(stderr, "failed to open %s: %s\n", fn, strerror(errno)); return -1; return -1; } } char line[PATH_MAX + 200]; while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) { Path* p; char* token; while (canned_used >= canned_alloc) { while (canned_used >= canned_alloc) { canned_alloc = (canned_alloc+1) * 2; canned_alloc = (canned_alloc+1) * 2; canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path)); canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path)); } } Path* p = canned_data + canned_used; p = canned_data + canned_used; p->path = strdup(strtok(line, " ")); p->path = strdup(strtok(line, " ")); p->uid = atoi(strtok(NULL, " ")); p->uid = atoi(strtok(NULL, " ")); p->gid = atoi(strtok(NULL, " ")); p->gid = atoi(strtok(NULL, " ")); p->mode = strtol(strtok(NULL, " "), NULL, 8); // mode is in octal p->mode = strtol(strtok(NULL, " "), NULL, 8); // mode is in octal p->capabilities = 0; p->capabilities = 0; char* token = NULL; do { do { token = strtok(NULL, " "); token = strtok(NULL, " "); if (token && strncmp(token, "capabilities=", 13) == 0) { if (token && strncmp(token, "capabilities=", 13) == 0) { Loading @@ -84,11 +88,11 @@ static const int kDebugCannedFsConfig = 0; void canned_fs_config(const char* path, int dir, const char* target_out_path, void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) { unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) { Path key; Path key, *p; key.path = path; key.path = path; if (path[0] == '/') if (path[0] == '/') key.path++; // canned paths lack the leading '/' key.path++; // canned paths lack the leading '/' p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare); Path* p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare); if (p == NULL) { if (p == NULL) { fprintf(stderr, "failed to find [%s] in canned fs_config\n", path); fprintf(stderr, "failed to find [%s] in canned fs_config\n", path); exit(1); exit(1); Loading @@ -103,15 +107,17 @@ void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned c_uid, c_gid, c_mode; unsigned c_uid, c_gid, c_mode; uint64_t c_capabilities; uint64_t c_capabilities; fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities); fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities); if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid); if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid); if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid); if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid); if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode); if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode); if (c_capabilities != *capabilities) if (c_capabilities != *capabilities) { printf("%s capabilities %" PRIx64 " %" PRIx64 "\n", printf("%s capabilities %" PRIx64 " %" PRIx64 "\n", path, path, *capabilities, *capabilities, c_capabilities); c_capabilities); } } } } }