diff options
author | Vladimir Chtchetkine <vchtchetkine@google.com> | 2010-10-07 05:40:39 -0700 |
---|---|---|
committer | Vladimir Chtchetkine <vchtchetkine@google.com> | 2010-10-08 01:02:22 -0700 |
commit | 7746af04f1c7a44253ce49cf7cf1914757faaafe (patch) | |
tree | 7a556d8622f4d750c59a38821a625a7ac798fd09 /android/core-init-utils.c | |
parent | 4e024bb4f5c8aa8b07459f7fbd65c35122127fd1 (diff) | |
download | external_qemu-7746af04f1c7a44253ce49cf7cf1914757faaafe.zip external_qemu-7746af04f1c7a44253ce49cf7cf1914757faaafe.tar.gz external_qemu-7746af04f1c7a44253ce49cf7cf1914757faaafe.tar.bz2 |
Make core initialization replying to the UI at the end of initialization.
Also, this CL contains a minor fix to formatting boot options passed to the kernel
Change-Id: I267172d82094a0cbbbced2cee7a2990bb7fa3793
Diffstat (limited to 'android/core-init-utils.c')
-rw-r--r-- | android/core-init-utils.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/android/core-init-utils.c b/android/core-init-utils.c new file mode 100644 index 0000000..97d5f05 --- /dev/null +++ b/android/core-init-utils.c @@ -0,0 +1,99 @@ +/* Copyright (C) 2010 The Android Open Source Project +** +** This software is licensed under the terms of the GNU General Public +** License version 2, as published by the Free Software Foundation, and +** may be copied, distributed, and modified under those terms. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +*/ + +/* + * Contains implementation of routines and that are used in the course + * of the emulator's core initialization. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include "qemu-common.h" +#include "sockets.h" +#include "android/android.h" +#include "android/core-init-utils.h" +#include "android/utils/bufprint.h" + +extern char* android_op_ui_port; + +/* Sends core initialization status message back to the UI that started this + * core process. + * Param: + * msg - Message to send. On success, message must begin with "ok:", followed + * by "port=<console port number>". On initialization failure, message must + * begin with "ko:", followed by a string describing the reason of failure. + */ +static void +android_core_send_init_response(const char* msg) +{ + int fd; + int ui_port; + + if (android_op_ui_port == NULL) { + // No socket - no reply. + return; + } + + ui_port = atoi(android_op_ui_port); + if (ui_port >= 0) { + // At this point UI always starts the core on the same workstation. + fd = socket_loopback_client(ui_port, SOCKET_STREAM); + if (fd == -1) { + fprintf(stderr, "Unable to create UI socket client for port %s: %s\n", + android_op_ui_port, errno_str); + return; + } + socket_send(fd, msg, strlen(msg) + 1); + socket_close(fd); + } else { + fprintf(stderr, "Invalid -ui-port parameter: %s\n", android_op_ui_port); + } +} + +void +android_core_init_completed(void) +{ + char msg[32]; + snprintf(msg, sizeof(msg), "ok:port=%d", android_base_port); + android_core_send_init_response(msg); +} + +void +android_core_init_failure(const char* fmt, ...) +{ + va_list args; + char msg[4096]; + + // Format "ko" message to send back to the UI. + snprintf(msg, sizeof(msg), "ko:"); + + va_start(args, fmt); + vbufprint(msg + strlen(msg), msg + sizeof(msg), fmt, args); + va_end(args); + + // Send message back to the UI, print it to the error stdout, and exit the + // process. + android_core_send_init_response(msg); + fprintf(stderr, "%s\n", msg); + exit(1); +} + +void +android_core_init_exit(int exit_status) +{ + char msg[32]; + // Build "ok" message with the exit status, and send it back to the UI. + snprintf(msg, sizeof(msg), "ok:status=%d", exit_status); + android_core_send_init_response(msg); + exit(exit_status); +} |