diff options
Diffstat (limited to 'updater/install.cpp')
-rw-r--r-- | updater/install.cpp | 122 |
1 files changed, 66 insertions, 56 deletions
diff --git a/updater/install.cpp b/updater/install.cpp index 11d5215c3..cf3e938a4 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -48,9 +48,10 @@ #include "cutils/misc.h" #include "cutils/properties.h" #include "edify/expr.h" -#include "openssl/sha.h" +#include "error_code.h" #include "minzip/DirUtil.h" #include "mounts.h" +#include "openssl/sha.h" #include "ota_io.h" #include "updater.h" #include "install.h" @@ -110,7 +111,7 @@ char* PrintSha1(const uint8_t* digest) { Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) { char* result = NULL; if (argc != 4 && argc != 5) { - return ErrorAbort(state, "%s() expects 4-5 args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 4-5 args, got %d", name, argc); } char* fs_type; char* partition_type; @@ -133,20 +134,21 @@ Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) { } if (strlen(fs_type) == 0) { - ErrorAbort(state, "fs_type argument to %s() can't be empty", name); + ErrorAbort(state, kArgsParsingFailure, "fs_type argument to %s() can't be empty", name); goto done; } if (strlen(partition_type) == 0) { - ErrorAbort(state, "partition_type argument to %s() can't be empty", + ErrorAbort(state, kArgsParsingFailure, "partition_type argument to %s() can't be empty", name); goto done; } if (strlen(location) == 0) { - ErrorAbort(state, "location argument to %s() can't be empty", name); + ErrorAbort(state, kArgsParsingFailure, "location argument to %s() can't be empty", name); goto done; } if (strlen(mount_point) == 0) { - ErrorAbort(state, "mount_point argument to %s() can't be empty", name); + ErrorAbort(state, kArgsParsingFailure, "mount_point argument to %s() can't be empty", + name); goto done; } @@ -190,14 +192,14 @@ done: Value* IsMountedFn(const char* name, State* state, int argc, Expr* argv[]) { char* result = NULL; if (argc != 1) { - return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %d", name, argc); } char* mount_point; if (ReadArgs(state, argv, 1, &mount_point) < 0) { return NULL; } if (strlen(mount_point) == 0) { - ErrorAbort(state, "mount_point argument to unmount() can't be empty"); + ErrorAbort(state, kArgsParsingFailure, "mount_point argument to unmount() can't be empty"); goto done; } @@ -220,14 +222,14 @@ done: Value* UnmountFn(const char* name, State* state, int argc, Expr* argv[]) { char* result = NULL; if (argc != 1) { - return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %d", name, argc); } char* mount_point; if (ReadArgs(state, argv, 1, &mount_point) < 0) { return NULL; } if (strlen(mount_point) == 0) { - ErrorAbort(state, "mount_point argument to unmount() can't be empty"); + ErrorAbort(state, kArgsParsingFailure, "mount_point argument to unmount() can't be empty"); goto done; } @@ -277,7 +279,7 @@ static int exec_cmd(const char* path, char* const argv[]) { Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) { char* result = NULL; if (argc != 5) { - return ErrorAbort(state, "%s() expects 5 args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 5 args, got %d", name, argc); } char* fs_type; char* partition_type; @@ -290,21 +292,22 @@ Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) { } if (strlen(fs_type) == 0) { - ErrorAbort(state, "fs_type argument to %s() can't be empty", name); + ErrorAbort(state, kArgsParsingFailure, "fs_type argument to %s() can't be empty", name); goto done; } if (strlen(partition_type) == 0) { - ErrorAbort(state, "partition_type argument to %s() can't be empty", + ErrorAbort(state, kArgsParsingFailure, "partition_type argument to %s() can't be empty", name); goto done; } if (strlen(location) == 0) { - ErrorAbort(state, "location argument to %s() can't be empty", name); + ErrorAbort(state, kArgsParsingFailure, "location argument to %s() can't be empty", name); goto done; } if (strlen(mount_point) == 0) { - ErrorAbort(state, "mount_point argument to %s() can't be empty", name); + ErrorAbort(state, kArgsParsingFailure, "mount_point argument to %s() can't be empty", + name); goto done; } @@ -350,7 +353,7 @@ done: Value* RenameFn(const char* name, State* state, int argc, Expr* argv[]) { char* result = NULL; if (argc != 2) { - return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %d", name, argc); } char* src_name; @@ -360,21 +363,21 @@ Value* RenameFn(const char* name, State* state, int argc, Expr* argv[]) { return NULL; } if (strlen(src_name) == 0) { - ErrorAbort(state, "src_name argument to %s() can't be empty", name); + ErrorAbort(state, kArgsParsingFailure, "src_name argument to %s() can't be empty", name); goto done; } if (strlen(dst_name) == 0) { - ErrorAbort(state, "dst_name argument to %s() can't be empty", name); + ErrorAbort(state, kArgsParsingFailure, "dst_name argument to %s() can't be empty", name); goto done; } if (make_parents(dst_name) != 0) { - ErrorAbort(state, "Creating parent of %s failed, error %s", + ErrorAbort(state, kFileRenameFailure, "Creating parent of %s failed, error %s", dst_name, strerror(errno)); } else if (access(dst_name, F_OK) == 0 && access(src_name, F_OK) != 0) { // File was already moved result = dst_name; } else if (rename(src_name, dst_name) != 0) { - ErrorAbort(state, "Rename of %s to %s failed, error %s", + ErrorAbort(state, kFileRenameFailure, "Rename of %s to %s failed, error %s", src_name, dst_name, strerror(errno)); } else { result = dst_name; @@ -417,7 +420,7 @@ Value* DeleteFn(const char* name, State* state, int argc, Expr* argv[]) { Value* ShowProgressFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 2) { - return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %d", name, argc); } char* frac_str; char* sec_str; @@ -438,7 +441,7 @@ Value* ShowProgressFn(const char* name, State* state, int argc, Expr* argv[]) { Value* SetProgressFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 1) { - return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %d", name, argc); } char* frac_str; if (ReadArgs(state, argv, 1, &frac_str) < 0) { @@ -457,7 +460,7 @@ Value* SetProgressFn(const char* name, State* state, int argc, Expr* argv[]) { Value* PackageExtractDirFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 2) { - return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %d", name, argc); } char* zip_path; char* dest_path; @@ -485,7 +488,7 @@ Value* PackageExtractDirFn(const char* name, State* state, Value* PackageExtractFileFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc < 1 || argc > 2) { - return ErrorAbort(state, "%s() expects 1 or 2 args, got %d", + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 or 2 args, got %d", name, argc); } bool success = false; @@ -593,7 +596,7 @@ static int make_parents(char* name) { // unlinks any previously existing src1, src2, etc before creating symlinks. Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc == 0) { - return ErrorAbort(state, "%s() expects 1+ args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1+ args, got %d", name, argc); } char* target; target = Evaluate(state, argv[0]); @@ -629,7 +632,7 @@ Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) { } free(srcs); if (bad) { - return ErrorAbort(state, "%s: some symlinks failed", name); + return ErrorAbort(state, kSymlinkFailure, "%s: some symlinks failed", name); } return StringValue(strdup("")); } @@ -853,14 +856,16 @@ static Value* SetMetadataFn(const char* name, State* state, int argc, Expr* argv bool recursive = (strcmp(name, "set_metadata_recursive") == 0); if ((argc % 2) != 1) { - return ErrorAbort(state, "%s() expects an odd number of arguments, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, + "%s() expects an odd number of arguments, got %d", name, argc); } char** args = ReadVarArgs(state, argc, argv); if (args == NULL) return NULL; if (lstat(args[0], &sb) == -1) { - result = ErrorAbort(state, "%s: Error on lstat of \"%s\": %s", name, args[0], strerror(errno)); + result = ErrorAbort(state, kSetMetadataFailure, "%s: Error on lstat of \"%s\": %s", + name, args[0], strerror(errno)); goto done; } @@ -889,7 +894,7 @@ done: } if (bad > 0) { - return ErrorAbort(state, "%s: some changes failed", name); + return ErrorAbort(state, kSetMetadataFailure, "%s: some changes failed", name); } return StringValue(strdup("")); @@ -897,7 +902,7 @@ done: Value* GetPropFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 1) { - return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %d", name, argc); } char* key = Evaluate(state, argv[0]); if (key == NULL) return NULL; @@ -926,20 +931,22 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) { struct stat st; if (stat(filename, &st) < 0) { - ErrorAbort(state, "%s: failed to stat \"%s\": %s", name, filename, strerror(errno)); + ErrorAbort(state, kFileGetPropFailure, "%s: failed to stat \"%s\": %s", name, filename, + strerror(errno)); goto done; } #define MAX_FILE_GETPROP_SIZE 65536 if (st.st_size > MAX_FILE_GETPROP_SIZE) { - ErrorAbort(state, "%s too large for %s (max %d)", filename, name, MAX_FILE_GETPROP_SIZE); + ErrorAbort(state, kFileGetPropFailure, "%s too large for %s (max %d)", filename, name, + MAX_FILE_GETPROP_SIZE); goto done; } buffer = reinterpret_cast<char*>(malloc(st.st_size+1)); if (buffer == NULL) { - ErrorAbort(state, "%s: failed to alloc %zu bytes", name, + ErrorAbort(state, kFileGetPropFailure, "%s: failed to alloc %zu bytes", name, static_cast<size_t>(st.st_size+1)); goto done; } @@ -947,12 +954,13 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) { FILE* f; f = ota_fopen(filename, "rb"); if (f == NULL) { - ErrorAbort(state, "%s: failed to open %s: %s", name, filename, strerror(errno)); + ErrorAbort(state, kFileOpenFailure, "%s: failed to open %s: %s", name, filename, + strerror(errno)); goto done; } if (ota_fread(buffer, 1, st.st_size, f) != static_cast<size_t>(st.st_size)) { - ErrorAbort(state, "%s: failed to read %zu bytes from %s", + ErrorAbort(state, kFreadFailure, "%s: failed to read %zu bytes from %s", name, static_cast<size_t>(st.st_size), filename); ota_fclose(f); goto done; @@ -1016,7 +1024,8 @@ Value* ApplyPatchSpaceFn(const char* name, State* state, size_t bytes; if (!android::base::ParseUint(bytes_str, &bytes)) { - ErrorAbort(state, "%s(): can't parse \"%s\" as byte count\n\n", name, bytes_str); + ErrorAbort(state, kArgsParsingFailure, "%s(): can't parse \"%s\" as byte count\n\n", + name, bytes_str); free(bytes_str); return nullptr; } @@ -1028,9 +1037,8 @@ Value* ApplyPatchSpaceFn(const char* name, State* state, Value* ApplyPatchFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc < 6 || (argc % 2) == 1) { - return ErrorAbort(state, "%s(): expected at least 6 args and an " - "even number, got %d", - name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s(): expected at least 6 args and an " + "even number, got %d", name, argc); } char* source_filename; @@ -1044,7 +1052,8 @@ Value* ApplyPatchFn(const char* name, State* state, int argc, Expr* argv[]) { size_t target_size; if (!android::base::ParseUint(target_size_str, &target_size)) { - ErrorAbort(state, "%s(): can't parse \"%s\" as byte count", name, target_size_str); + ErrorAbort(state, kArgsParsingFailure, "%s(): can't parse \"%s\" as byte count", + name, target_size_str); free(source_filename); free(target_filename); free(target_sha1); @@ -1068,11 +1077,11 @@ Value* ApplyPatchFn(const char* name, State* state, int argc, Expr* argv[]) { for (int i = 0; i < patchcount; ++i) { if (patch_shas[i]->type != VAL_STRING) { - ErrorAbort(state, "%s(): sha-1 #%d is not string", name, i); + ErrorAbort(state, kArgsParsingFailure, "%s(): sha-1 #%d is not string", name, i); return nullptr; } if (patches[i]->type != VAL_BLOB) { - ErrorAbort(state, "%s(): patch #%d is not blob", name, i); + ErrorAbort(state, kArgsParsingFailure, "%s(): patch #%d is not blob", name, i); return nullptr; } } @@ -1095,7 +1104,7 @@ Value* ApplyPatchFn(const char* name, State* state, int argc, Expr* argv[]) { Value* ApplyPatchCheckFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc < 1) { - return ErrorAbort(state, "%s(): expected at least 1 arg, got %d", + return ErrorAbort(state, kArgsParsingFailure, "%s(): expected at least 1 arg, got %d", name, argc); } @@ -1140,7 +1149,7 @@ Value* UIPrintFn(const char* name, State* state, int argc, Expr* argv[]) { Value* WipeCacheFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 0) { - return ErrorAbort(state, "%s() expects no args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects no args, got %d", name, argc); } fprintf(((UpdaterInfo*)(state->cookie))->cmd_pipe, "wipe_cache\n"); return StringValue(strdup("t")); @@ -1148,7 +1157,7 @@ Value* WipeCacheFn(const char* name, State* state, int argc, Expr* argv[]) { Value* RunProgramFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc < 1) { - return ErrorAbort(state, "%s() expects at least 1 arg", name); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects at least 1 arg", name); } char** args = ReadVarArgs(state, argc, argv); if (args == NULL) { @@ -1202,7 +1211,7 @@ Value* RunProgramFn(const char* name, State* state, int argc, Expr* argv[]) { // Value* Sha1CheckFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc < 1) { - return ErrorAbort(state, "%s() expects at least 1 arg", name); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects at least 1 arg", name); } std::unique_ptr<Value*, decltype(&free)> arg_values(ReadValueVarArgs(state, argc, argv), free); @@ -1250,7 +1259,7 @@ Value* Sha1CheckFn(const char* name, State* state, int argc, Expr* argv[]) { // is actually a FileContents*). Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 1) { - return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %d", name, argc); } char* filename; if (ReadArgs(state, argv, 1, &filename) < 0) return NULL; @@ -1286,7 +1295,7 @@ Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) { // partition. Value* RebootNowFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 2) { - return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %d", name, argc); } char* filename; @@ -1312,7 +1321,7 @@ Value* RebootNowFn(const char* name, State* state, int argc, Expr* argv[]) { sleep(5); free(property); - ErrorAbort(state, "%s() failed to reboot", name); + ErrorAbort(state, kRebootFailure, "%s() failed to reboot", name); return NULL; } @@ -1328,7 +1337,7 @@ Value* RebootNowFn(const char* name, State* state, int argc, Expr* argv[]) { // bytes. Value* SetStageFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 2) { - return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %d", name, argc); } char* filename; @@ -1358,7 +1367,7 @@ Value* SetStageFn(const char* name, State* state, int argc, Expr* argv[]) { // is the block device for the misc partition. Value* GetStageFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 1) { - return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %d", name, argc); } char* filename; @@ -1376,7 +1385,7 @@ Value* GetStageFn(const char* name, State* state, int argc, Expr* argv[]) { Value* WipeBlockDeviceFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 2) { - return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %d", name, argc); } char* filename; @@ -1398,7 +1407,7 @@ Value* WipeBlockDeviceFn(const char* name, State* state, int argc, Expr* argv[]) Value* EnableRebootFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 0) { - return ErrorAbort(state, "%s() expects no args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects no args, got %d", name, argc); } UpdaterInfo* ui = (UpdaterInfo*)(state->cookie); fprintf(ui->cmd_pipe, "enable_reboot\n"); @@ -1407,12 +1416,12 @@ Value* EnableRebootFn(const char* name, State* state, int argc, Expr* argv[]) { Value* Tune2FsFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc == 0) { - return ErrorAbort(state, "%s() expects args, got %d", name, argc); + return ErrorAbort(state, kArgsParsingFailure, "%s() expects args, got %d", name, argc); } char** args = ReadVarArgs(state, argc, argv); if (args == NULL) { - return ErrorAbort(state, "%s() could not read args", name); + return ErrorAbort(state, kArgsParsingFailure, "%s() could not read args", name); } char** args2 = reinterpret_cast<char**>(malloc(sizeof(char*) * (argc+1))); @@ -1430,7 +1439,8 @@ Value* Tune2FsFn(const char* name, State* state, int argc, Expr* argv[]) { free(args2[0]); free(args2); if (result != 0) { - return ErrorAbort(state, "%s() returned error code %d", name, result); + return ErrorAbort(state, kTune2FsFailure, "%s() returned error code %d", + name, result); } return StringValue(strdup("t")); } |