summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2010-07-16 18:25:22 +0200
committerGravatar Martin Szulecki2010-07-16 18:25:22 +0200
commit646c196ab19e80fbd91cc60ab9b006f997d8b666 (patch)
tree0f1a28b235003f7a754c69800f3b478ef75db5e9
parentaedb4aa1be0751f3bca7029b4a9588727662e4bc (diff)
downloadlibirecovery-646c196ab19e80fbd91cc60ab9b006f997d8b666.tar.gz
libirecovery-646c196ab19e80fbd91cc60ab9b006f997d8b666.tar.bz2
irecovery: Move getenv handling into precommand callback to fix getenv usage
-rw-r--r--src/irecovery.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/irecovery.c b/src/irecovery.c
index 415c20e..327527b 100644
--- a/src/irecovery.c
+++ b/src/irecovery.c
@@ -137,26 +137,21 @@ int received_cb(irecv_client_t client, const irecv_event_t* event) {
}
int precommand_cb(irecv_client_t client, const irecv_event_t* event) {
- if (event->type == IRECV_PRECOMMAND) {
- irecv_error_t error = 0;
- if (event->data[0] == '/') {
- parse_command(client, event->data, event->size);
- return -1;
- }
- }
- return 0;
-}
-
-int postcommand_cb(irecv_client_t client, const irecv_event_t* event) {
char* value = NULL;
char* action = NULL;
char* command = NULL;
char* argument = NULL;
irecv_error_t error = IRECV_E_SUCCESS;
- if (event->type == IRECV_POSTCOMMAND) {
+ if (event->type == IRECV_PRECOMMAND) {
+ if (event->data[0] == '/') {
+ parse_command(client, event->data, event->size);
+ return -1;
+ }
+
command = strdup(event->data);
action = strtok(command, " ");
+
if (!strcmp(action, "getenv")) {
argument = strtok(NULL, " ");
error = irecv_getenv(client, argument, &value);
@@ -165,9 +160,23 @@ int postcommand_cb(irecv_client_t client, const irecv_event_t* event) {
free(command);
return error;
}
- printf("%s\n", value);
- free(value);
+ if (value) {
+ printf("%s\n", value);
+ free(value);
+ }
+ return 1;
}
+ }
+ return 0;
+}
+
+int postcommand_cb(irecv_client_t client, const irecv_event_t* event) {
+ char* action = NULL;
+ char* command = NULL;
+
+ if (event->type == IRECV_POSTCOMMAND) {
+ command = strdup(event->data);
+ action = strtok(command, " ");
if (!strcmp(action, "reboot")) {
quit = 1;