summaryrefslogtreecommitdiff
path: root/utility
diff options
context:
space:
mode:
authorYu-Ping Wu <yupingso@chromium.org>2019-12-26 18:12:19 +0800
committerCommit Bot <commit-bot@chromium.org>2020-01-06 12:50:25 +0000
commitedfe2f28738571aab8f83880c453916bcc4b3985 (patch)
tree40698575c9f1f4ad1aa6cc84901a412163fdf8cc /utility
parent582453dd62a9616a95a19b42a36f6adb8988e329 (diff)
downloadvboot-edfe2f28738571aab8f83880c453916bcc4b3985.tar.gz
crossystem: Fix error message when passing invalid parameter
When setting crossystem parameters with various errors, the error message was always "Parameter dev_default_boot is read-only". Display various error messages based on the types of errors. BRANCH=none BUG=chromium:965799 TEST=emerge-nami vboot_reference Change-Id: I185ce5f9c142da538f86b6c6c298f5a76377e395 Signed-off-by: Yu-Ping Wu <yupingso@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1982431 Reviewed-by: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'utility')
-rw-r--r--utility/crossystem.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/utility/crossystem.c b/utility/crossystem.c
index 0fb01ad3..f3f901b8 100644
--- a/utility/crossystem.c
+++ b/utility/crossystem.c
@@ -146,26 +146,34 @@ static const Param* FindParam(const char* name) {
return NULL;
}
+/* Return code of SetParam() below. */
+enum {
+ PARAM_SUCCESS = 0,
+ PARAM_ERROR_UNKNOWN,
+ PARAM_ERROR_READ_ONLY,
+ PARAM_ERROR_INVALID_INT,
+};
/* Set the specified parameter.
*
- * Returns 0 if success, non-zero if error. */
+ * Returns PARAM_SUCCESS if success, PARAM_ERROR_* if error. */
static int SetParam(const Param* p, const char* value) {
if (!(p->flags & CAN_WRITE))
- return 1; /* Parameter is read-only */
+ return PARAM_ERROR_READ_ONLY;
if (p->flags & IS_STRING) {
- return (0 == VbSetSystemPropertyString(p->name, value) ? 0 : 1);
+ return (0 == VbSetSystemPropertyString(p->name, value) ?
+ 0 : PARAM_ERROR_UNKNOWN);
} else {
char* e;
int i = (int)strtol(value, &e, 0);
if (!*value || (e && *e))
- return 1;
- return (0 == VbSetSystemPropertyInt(p->name, i) ? 0 : 1);
+ return PARAM_ERROR_INVALID_INT;
+ return (0 == VbSetSystemPropertyInt(p->name, i) ?
+ 0 : PARAM_ERROR_UNKNOWN);
}
}
-
/* Compares the parameter with the expected value.
*
* Returns 0 if success (match), non-zero if error (mismatch). */
@@ -300,8 +308,18 @@ int main(int argc, char* argv[]) {
printf(" "); /* Output params space-delimited */
if (has_set) {
retval = SetParam(p, value);
- if (retval) {
+ switch (retval) {
+ case PARAM_SUCCESS:
+ break;
+ case PARAM_ERROR_READ_ONLY:
fprintf(stderr, "Parameter %s is read-only\n", name);
+ break;
+ case PARAM_ERROR_INVALID_INT:
+ fprintf(stderr, "Value %s is not a valid integer\n", value);
+ break;
+ default:
+ fprintf(stderr, "Failed to set parameter %s\n", name);
+ break;
}
} else if (has_expect)
retval = CheckParam(p, value);