aboutsummaryrefslogtreecommitdiffstats
path: root/edify
diff options
context:
space:
mode:
authorTianjie Xu2016-05-23 13:42:40 -0500
committerTianjie Xu2016-05-23 14:24:28 -0500
commit84478e88234b68e457e18877ba9542029e5c7865 (patch)
treee4884c5c70dcde2cb1a346f8f7259839826c6f85 /edify
parent8a55c653458c2d33af506b193e658faf8f88bfa3 (diff)
parent50f6417317f9e327ed76abaf34512370f8376245 (diff)
downloadplatform-bootable-recovery-84478e88234b68e457e18877ba9542029e5c7865.tar.gz
platform-bootable-recovery-84478e88234b68e457e18877ba9542029e5c7865.tar.xz
platform-bootable-recovery-84478e88234b68e457e18877ba9542029e5c7865.zip
resolve merge conflicts of 50f6417 to nyc-dev-plus-aosp
Change-Id: I42c127f7946e678acf6596f6352f090abc0ca019
Diffstat (limited to 'edify')
-rw-r--r--edify/Android.mk4
-rw-r--r--edify/expr.cpp39
-rw-r--r--edify/expr.h18
3 files changed, 50 insertions, 11 deletions
diff --git a/edify/Android.mk b/edify/Android.mk
index 038dec08..71cf7652 100644
--- a/edify/Android.mk
+++ b/edify/Android.mk
@@ -22,6 +22,8 @@ LOCAL_YACCFLAGS := -v
22LOCAL_CPPFLAGS += -Wno-unused-parameter 22LOCAL_CPPFLAGS += -Wno-unused-parameter
23LOCAL_CPPFLAGS += -Wno-deprecated-register 23LOCAL_CPPFLAGS += -Wno-deprecated-register
24LOCAL_CLANG := true 24LOCAL_CLANG := true
25LOCAL_C_INCLUDES += $(LOCAL_PATH)/..
26LOCAL_STATIC_LIBRARIES += libbase
25 27
26include $(BUILD_HOST_EXECUTABLE) 28include $(BUILD_HOST_EXECUTABLE)
27 29
@@ -36,5 +38,7 @@ LOCAL_CPPFLAGS := -Wno-unused-parameter
36LOCAL_CPPFLAGS += -Wno-deprecated-register 38LOCAL_CPPFLAGS += -Wno-deprecated-register
37LOCAL_MODULE := libedify 39LOCAL_MODULE := libedify
38LOCAL_CLANG := true 40LOCAL_CLANG := true
41LOCAL_C_INCLUDES += $(LOCAL_PATH)/..
42LOCAL_STATIC_LIBRARIES += libbase
39 43
40include $(BUILD_STATIC_LIBRARY) 44include $(BUILD_STATIC_LIBRARY)
diff --git a/edify/expr.cpp b/edify/expr.cpp
index c34342f7..ecb1bea1 100644
--- a/edify/expr.cpp
+++ b/edify/expr.cpp
@@ -21,6 +21,11 @@
21#include <stdarg.h> 21#include <stdarg.h>
22#include <unistd.h> 22#include <unistd.h>
23 23
24#include <string>
25
26#include <android-base/stringprintf.h>
27#include <android-base/strings.h>
28
24#include "expr.h" 29#include "expr.h"
25 30
26// Functions should: 31// Functions should:
@@ -36,7 +41,7 @@ char* Evaluate(State* state, Expr* expr) {
36 Value* v = expr->fn(expr->name, state, expr->argc, expr->argv); 41 Value* v = expr->fn(expr->name, state, expr->argc, expr->argv);
37 if (v == NULL) return NULL; 42 if (v == NULL) return NULL;
38 if (v->type != VAL_STRING) { 43 if (v->type != VAL_STRING) {
39 ErrorAbort(state, "expecting string, got value type %d", v->type); 44 ErrorAbort(state, kArgsParsingFailure, "expecting string, got value type %d", v->type);
40 FreeValue(v); 45 FreeValue(v);
41 return NULL; 46 return NULL;
42 } 47 }
@@ -494,15 +499,29 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]) {
494 return args; 499 return args;
495} 500}
496 501
502static void ErrorAbortV(State* state, const char* format, va_list ap) {
503 std::string buffer;
504 android::base::StringAppendV(&buffer, format, ap);
505 free(state->errmsg);
506 state->errmsg = strdup(buffer.c_str());
507 return;
508}
509
497// Use printf-style arguments to compose an error message to put into 510// Use printf-style arguments to compose an error message to put into
498// *state. Returns NULL. 511// *state. Returns nullptr.
499Value* ErrorAbort(State* state, const char* format, ...) { 512Value* ErrorAbort(State* state, const char* format, ...) {
500 char* buffer = reinterpret_cast<char*>(malloc(4096)); 513 va_list ap;
501 va_list v; 514 va_start(ap, format);
502 va_start(v, format); 515 ErrorAbortV(state, format, ap);
503 vsnprintf(buffer, 4096, format, v); 516 va_end(ap);
504 va_end(v); 517 return nullptr;
505 free(state->errmsg); 518}
506 state->errmsg = buffer; 519
507 return NULL; 520Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
521 va_list ap;
522 va_start(ap, format);
523 ErrorAbortV(state, format, ap);
524 va_end(ap);
525 state->cause_code = cause_code;
526 return nullptr;
508} 527}
diff --git a/edify/expr.h b/edify/expr.h
index 36f8e961..5c06de84 100644
--- a/edify/expr.h
+++ b/edify/expr.h
@@ -19,6 +19,7 @@
19 19
20#include <unistd.h> 20#include <unistd.h>
21 21
22#include "error_code.h"
22#include "yydefs.h" 23#include "yydefs.h"
23 24
24#define MAX_STRING_LEN 1024 25#define MAX_STRING_LEN 1024
@@ -39,6 +40,15 @@ typedef struct {
39 // Should be NULL initially, will be either NULL or a malloc'd 40 // Should be NULL initially, will be either NULL or a malloc'd
40 // pointer after Evaluate() returns. 41 // pointer after Evaluate() returns.
41 char* errmsg; 42 char* errmsg;
43
44 // error code indicates the type of failure (e.g. failure to update system image)
45 // during the OTA process.
46 ErrorCode error_code = kNoError;
47
48 // cause code provides more detailed reason of an OTA failure (e.g. fsync error)
49 // in addition to the error code.
50 CauseCode cause_code = kNoCause;
51
42} State; 52} State;
43 53
44#define VAL_STRING 1 // data will be NULL-terminated; size doesn't count null 54#define VAL_STRING 1 // data will be NULL-terminated; size doesn't count null
@@ -152,7 +162,13 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]);
152 162
153// Use printf-style arguments to compose an error message to put into 163// Use printf-style arguments to compose an error message to put into
154// *state. Returns NULL. 164// *state. Returns NULL.
155Value* ErrorAbort(State* state, const char* format, ...) __attribute__((format(printf, 2, 3))); 165Value* ErrorAbort(State* state, const char* format, ...)
166 __attribute__((format(printf, 2, 3), deprecated));
167
168// ErrorAbort has an optional (but recommended) argument 'cause_code'. If the cause code
169// is set, it will be logged into last_install and provides reason of OTA failures.
170Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...)
171 __attribute__((format(printf, 3, 4)));
156 172
157// Wrap a string into a Value, taking ownership of the string. 173// Wrap a string into a Value, taking ownership of the string.
158Value* StringValue(char* str); 174Value* StringValue(char* str);