diff options
author | Tianjie Xu | 2018-01-30 15:44:02 -0600 |
---|---|---|
committer | Gerrit Code Review | 2018-01-30 15:44:02 -0600 |
commit | bded087f7de69fc352c5860659e2db4478b30bdd (patch) | |
tree | 26ebc8890fcc2fdf5357494abc6bda180249c505 | |
parent | 63eb1a444489167429964d55cf59f3217b52efd6 (diff) | |
parent | 5ad802839d84f7bcdfbb8aa5c48cb56b303ce5f0 (diff) | |
download | platform-bootable-recovery-bded087f7de69fc352c5860659e2db4478b30bdd.tar.gz platform-bootable-recovery-bded087f7de69fc352c5860659e2db4478b30bdd.tar.xz platform-bootable-recovery-bded087f7de69fc352c5860659e2db4478b30bdd.zip |
Merge "Avoid overwrite of the error message in AbortFn"
-rw-r--r-- | edify/expr.cpp | 19 | ||||
-rw-r--r-- | updater/blockimg.cpp | 18 | ||||
-rw-r--r-- | updater/install.cpp | 12 |
3 files changed, 26 insertions, 23 deletions
diff --git a/edify/expr.cpp b/edify/expr.cpp index 1b8623f0..6823b733 100644 --- a/edify/expr.cpp +++ b/edify/expr.cpp | |||
@@ -114,9 +114,9 @@ Value* IfElseFn(const char* name, State* state, const std::vector<std::unique_pt | |||
114 | Value* AbortFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { | 114 | Value* AbortFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
115 | std::string msg; | 115 | std::string msg; |
116 | if (!argv.empty() && Evaluate(state, argv[0], &msg)) { | 116 | if (!argv.empty() && Evaluate(state, argv[0], &msg)) { |
117 | state->errmsg = msg; | 117 | state->errmsg += msg; |
118 | } else { | 118 | } else { |
119 | state->errmsg = "called abort()"; | 119 | state->errmsg += "called abort()"; |
120 | } | 120 | } |
121 | return nullptr; | 121 | return nullptr; |
122 | } | 122 | } |
@@ -410,12 +410,15 @@ Value* ErrorAbort(State* state, const char* format, ...) { | |||
410 | } | 410 | } |
411 | 411 | ||
412 | Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) { | 412 | Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) { |
413 | va_list ap; | 413 | std::string err_message; |
414 | va_start(ap, format); | 414 | va_list ap; |
415 | android::base::StringAppendV(&state->errmsg, format, ap); | 415 | va_start(ap, format); |
416 | va_end(ap); | 416 | android::base::StringAppendV(&err_message, format, ap); |
417 | state->cause_code = cause_code; | 417 | va_end(ap); |
418 | return nullptr; | 418 | // Ensure that there's exactly one line break at the end of the error message. |
419 | state->errmsg = android::base::Trim(err_message) + "\n"; | ||
420 | state->cause_code = cause_code; | ||
421 | return nullptr; | ||
419 | } | 422 | } |
420 | 423 | ||
421 | State::State(const std::string& script, void* cookie) | 424 | State::State(const std::string& script, void* cookie) |
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 08f9930e..0e90e94a 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp | |||
@@ -817,7 +817,7 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& blockd | |||
817 | size_t max_stash_size = maxblocks * BLOCKSIZE; | 817 | size_t max_stash_size = maxblocks * BLOCKSIZE; |
818 | 818 | ||
819 | if (res == -1 && errno != ENOENT) { | 819 | if (res == -1 && errno != ENOENT) { |
820 | ErrorAbort(state, kStashCreationFailure, "stat \"%s\" failed: %s\n", dirname.c_str(), | 820 | ErrorAbort(state, kStashCreationFailure, "stat \"%s\" failed: %s", dirname.c_str(), |
821 | strerror(errno)); | 821 | strerror(errno)); |
822 | return -1; | 822 | return -1; |
823 | } else if (res != 0) { | 823 | } else if (res != 0) { |
@@ -825,19 +825,19 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& blockd | |||
825 | res = mkdir(dirname.c_str(), STASH_DIRECTORY_MODE); | 825 | res = mkdir(dirname.c_str(), STASH_DIRECTORY_MODE); |
826 | 826 | ||
827 | if (res != 0) { | 827 | if (res != 0) { |
828 | ErrorAbort(state, kStashCreationFailure, "mkdir \"%s\" failed: %s\n", dirname.c_str(), | 828 | ErrorAbort(state, kStashCreationFailure, "mkdir \"%s\" failed: %s", dirname.c_str(), |
829 | strerror(errno)); | 829 | strerror(errno)); |
830 | return -1; | 830 | return -1; |
831 | } | 831 | } |
832 | 832 | ||
833 | if (chown(dirname.c_str(), AID_SYSTEM, AID_SYSTEM) != 0) { // system user | 833 | if (chown(dirname.c_str(), AID_SYSTEM, AID_SYSTEM) != 0) { // system user |
834 | ErrorAbort(state, kStashCreationFailure, "chown \"%s\" failed: %s\n", dirname.c_str(), | 834 | ErrorAbort(state, kStashCreationFailure, "chown \"%s\" failed: %s", dirname.c_str(), |
835 | strerror(errno)); | 835 | strerror(errno)); |
836 | return -1; | 836 | return -1; |
837 | } | 837 | } |
838 | 838 | ||
839 | if (CacheSizeCheck(max_stash_size) != 0) { | 839 | if (CacheSizeCheck(max_stash_size) != 0) { |
840 | ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu needed)\n", | 840 | ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu needed)", |
841 | max_stash_size); | 841 | max_stash_size); |
842 | return -1; | 842 | return -1; |
843 | } | 843 | } |
@@ -869,7 +869,7 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& blockd | |||
869 | if (max_stash_size > existing) { | 869 | if (max_stash_size > existing) { |
870 | size_t needed = max_stash_size - existing; | 870 | size_t needed = max_stash_size - existing; |
871 | if (CacheSizeCheck(needed) != 0) { | 871 | if (CacheSizeCheck(needed) != 0) { |
872 | ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu more needed)\n", | 872 | ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu more needed)", |
873 | needed); | 873 | needed); |
874 | return -1; | 874 | return -1; |
875 | } | 875 | } |
@@ -1517,7 +1517,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, | |||
1517 | 1517 | ||
1518 | std::vector<std::string> lines = android::base::Split(transfer_list_value->data, "\n"); | 1518 | std::vector<std::string> lines = android::base::Split(transfer_list_value->data, "\n"); |
1519 | if (lines.size() < 2) { | 1519 | if (lines.size() < 2) { |
1520 | ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zd]\n", | 1520 | ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zd]", |
1521 | lines.size()); | 1521 | lines.size()); |
1522 | return StringValue(""); | 1522 | return StringValue(""); |
1523 | } | 1523 | } |
@@ -1533,7 +1533,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, | |||
1533 | // Second line in transfer list is the total number of blocks we expect to write. | 1533 | // Second line in transfer list is the total number of blocks we expect to write. |
1534 | size_t total_blocks; | 1534 | size_t total_blocks; |
1535 | if (!android::base::ParseUint(lines[1], &total_blocks)) { | 1535 | if (!android::base::ParseUint(lines[1], &total_blocks)) { |
1536 | ErrorAbort(state, kArgsParsingFailure, "unexpected block count [%s]\n", lines[1].c_str()); | 1536 | ErrorAbort(state, kArgsParsingFailure, "unexpected block count [%s]", lines[1].c_str()); |
1537 | return StringValue(""); | 1537 | return StringValue(""); |
1538 | } | 1538 | } |
1539 | 1539 | ||
@@ -1543,7 +1543,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, | |||
1543 | 1543 | ||
1544 | size_t start = 2; | 1544 | size_t start = 2; |
1545 | if (lines.size() < 4) { | 1545 | if (lines.size() < 4) { |
1546 | ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zu]\n", | 1546 | ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zu]", |
1547 | lines.size()); | 1547 | lines.size()); |
1548 | return StringValue(""); | 1548 | return StringValue(""); |
1549 | } | 1549 | } |
@@ -1554,7 +1554,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, | |||
1554 | // Fourth line is the maximum number of blocks that will be stashed simultaneously | 1554 | // Fourth line is the maximum number of blocks that will be stashed simultaneously |
1555 | size_t stash_max_blocks; | 1555 | size_t stash_max_blocks; |
1556 | if (!android::base::ParseUint(lines[3], &stash_max_blocks)) { | 1556 | if (!android::base::ParseUint(lines[3], &stash_max_blocks)) { |
1557 | ErrorAbort(state, kArgsParsingFailure, "unexpected maximum stash blocks [%s]\n", | 1557 | ErrorAbort(state, kArgsParsingFailure, "unexpected maximum stash blocks [%s]", |
1558 | lines[3].c_str()); | 1558 | lines[3].c_str()); |
1559 | return StringValue(""); | 1559 | return StringValue(""); |
1560 | } | 1560 | } |
diff --git a/updater/install.cpp b/updater/install.cpp index b83d30ff..eef252e3 100644 --- a/updater/install.cpp +++ b/updater/install.cpp | |||
@@ -268,7 +268,7 @@ Value* FormatFn(const char* name, State* state, const std::vector<std::unique_pt | |||
268 | 268 | ||
269 | int64_t size; | 269 | int64_t size; |
270 | if (!android::base::ParseInt(fs_size, &size)) { | 270 | if (!android::base::ParseInt(fs_size, &size)) { |
271 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s\n", name, | 271 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s", name, |
272 | fs_size.c_str()); | 272 | fs_size.c_str()); |
273 | } | 273 | } |
274 | 274 | ||
@@ -352,12 +352,12 @@ Value* ShowProgressFn(const char* name, State* state, | |||
352 | 352 | ||
353 | double frac; | 353 | double frac; |
354 | if (!android::base::ParseDouble(frac_str.c_str(), &frac)) { | 354 | if (!android::base::ParseDouble(frac_str.c_str(), &frac)) { |
355 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s\n", name, | 355 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s", name, |
356 | frac_str.c_str()); | 356 | frac_str.c_str()); |
357 | } | 357 | } |
358 | int sec; | 358 | int sec; |
359 | if (!android::base::ParseInt(sec_str.c_str(), &sec)) { | 359 | if (!android::base::ParseInt(sec_str.c_str(), &sec)) { |
360 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s\n", name, | 360 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s", name, |
361 | sec_str.c_str()); | 361 | sec_str.c_str()); |
362 | } | 362 | } |
363 | 363 | ||
@@ -380,7 +380,7 @@ Value* SetProgressFn(const char* name, State* state, const std::vector<std::uniq | |||
380 | 380 | ||
381 | double frac; | 381 | double frac; |
382 | if (!android::base::ParseDouble(frac_str.c_str(), &frac)) { | 382 | if (!android::base::ParseDouble(frac_str.c_str(), &frac)) { |
383 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s\n", name, | 383 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s", name, |
384 | frac_str.c_str()); | 384 | frac_str.c_str()); |
385 | } | 385 | } |
386 | 386 | ||
@@ -574,8 +574,8 @@ Value* ApplyPatchSpaceFn(const char* name, State* state, const std::vector<std:: | |||
574 | 574 | ||
575 | size_t bytes; | 575 | size_t bytes; |
576 | if (!android::base::ParseUint(bytes_str.c_str(), &bytes)) { | 576 | if (!android::base::ParseUint(bytes_str.c_str(), &bytes)) { |
577 | return ErrorAbort(state, kArgsParsingFailure, "%s(): can't parse \"%s\" as byte count\n\n", | 577 | return ErrorAbort(state, kArgsParsingFailure, "%s(): can't parse \"%s\" as byte count", name, |
578 | name, bytes_str.c_str()); | 578 | bytes_str.c_str()); |
579 | } | 579 | } |
580 | 580 | ||
581 | // Skip the cache size check if the update is a retry. | 581 | // Skip the cache size check if the update is a retry. |