Skip to content

Commit

Permalink
ui: Convert vnc_display_init(), init_keyboard_layout() to Error
Browse files Browse the repository at this point in the history
Signed-off-by: Fei Li <fli@suse.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20181017082702.5581-27-armbru@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
ShirleyFei authored and Markus Armbruster committed Oct 19, 2018
1 parent f7b9e29 commit ab4f931
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/ui/console.h
Expand Up @@ -453,7 +453,7 @@ void qemu_display_early_init(DisplayOptions *opts);
void qemu_display_init(DisplayState *ds, DisplayOptions *opts);

/* vnc.c */
void vnc_display_init(const char *id);
void vnc_display_init(const char *id, Error **errp);
void vnc_display_open(const char *id, Error **errp);
void vnc_display_add_client(const char *id, int csock, bool skipauth);
int vnc_display_password(const char *id, const char *password);
Expand Down
6 changes: 3 additions & 3 deletions ui/curses.c
Expand Up @@ -28,6 +28,7 @@
#include <termios.h>
#endif

#include "qapi/error.h"
#include "qemu-common.h"
#include "ui/console.h"
#include "ui/input.h"
Expand Down Expand Up @@ -421,9 +422,8 @@ static void curses_keyboard_setup(void)
keyboard_layout = "en-us";
#endif
if(keyboard_layout) {
kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
if (!kbd_layout)
exit(1);
kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout,
&error_fatal);
}
}

Expand Down
11 changes: 6 additions & 5 deletions ui/keymaps.c
Expand Up @@ -27,6 +27,7 @@
#include "sysemu/sysemu.h"
#include "trace.h"
#include "qemu/error-report.h"
#include "qapi/error.h"

struct keysym2code {
uint32_t count;
Expand Down Expand Up @@ -81,7 +82,7 @@ static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *k)

static int parse_keyboard_layout(kbd_layout_t *k,
const name2keysym_t *table,
const char *language)
const char *language, Error **errp)
{
int ret;
FILE *f;
Expand All @@ -95,7 +96,7 @@ static int parse_keyboard_layout(kbd_layout_t *k,
f = filename ? fopen(filename, "r") : NULL;
g_free(filename);
if (!f) {
fprintf(stderr, "Could not read keymap file: '%s'\n", language);
error_setg(errp, "could not read keymap file: '%s'", language);
return -1;
}

Expand All @@ -114,7 +115,7 @@ static int parse_keyboard_layout(kbd_layout_t *k,
continue;
}
if (!strncmp(line, "include ", 8)) {
if (parse_keyboard_layout(k, table, line + 8) < 0) {
if (parse_keyboard_layout(k, table, line + 8, errp) < 0) {
ret = -1;
goto out;
}
Expand Down Expand Up @@ -172,13 +173,13 @@ static int parse_keyboard_layout(kbd_layout_t *k,


kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,
const char *language)
const char *language, Error **errp)
{
kbd_layout_t *k;

k = g_new0(kbd_layout_t, 1);
k->hash = g_hash_table_new(NULL, NULL);
if (parse_keyboard_layout(k, table, language) < 0) {
if (parse_keyboard_layout(k, table, language, errp) < 0) {
g_hash_table_unref(k->hash);
g_free(k);
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion ui/keymaps.h
Expand Up @@ -53,7 +53,7 @@ typedef struct {
typedef struct kbd_layout_t kbd_layout_t;

kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,
const char *language);
const char *language, Error **errp);
int keysym2scancode(kbd_layout_t *k, int keysym,
bool shift, bool altgr, bool ctrl);
int keycode_is_keypad(kbd_layout_t *k, int keycode);
Expand Down
6 changes: 3 additions & 3 deletions ui/sdl.c
Expand Up @@ -29,6 +29,7 @@
#include <SDL.h>
#include <SDL_syswm.h>

#include "qapi/error.h"
#include "qemu-common.h"
#include "qemu/cutils.h"
#include "ui/console.h"
Expand Down Expand Up @@ -917,9 +918,8 @@ static void sdl1_display_init(DisplayState *ds, DisplayOptions *o)
keyboard_layout = "en-us";
#endif
if(keyboard_layout) {
kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
if (!kbd_layout)
exit(1);
kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout,
&error_fatal);
}

g_printerr("Running QEMU with SDL 1.2 is deprecated, and will be removed\n"
Expand Down
15 changes: 10 additions & 5 deletions ui/vnc.c
Expand Up @@ -3205,7 +3205,7 @@ static const DisplayChangeListenerOps dcl_ops = {
.dpy_cursor_define = vnc_dpy_cursor_define,
};

void vnc_display_init(const char *id)
void vnc_display_init(const char *id, Error **errp)
{
VncDisplay *vd;

Expand All @@ -3222,13 +3222,14 @@ void vnc_display_init(const char *id)

if (keyboard_layout) {
trace_vnc_key_map_init(keyboard_layout);
vd->kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
vd->kbd_layout = init_keyboard_layout(name2keysym,
keyboard_layout, errp);
} else {
vd->kbd_layout = init_keyboard_layout(name2keysym, "en-us");
vd->kbd_layout = init_keyboard_layout(name2keysym, "en-us", errp);
}

if (!vd->kbd_layout) {
exit(1);
return;
}

vd->share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE;
Expand Down Expand Up @@ -4079,7 +4080,11 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)
char *id = (char *)qemu_opts_id(opts);

assert(id);
vnc_display_init(id);
vnc_display_init(id, &local_err);
if (local_err) {
error_report_err(local_err);
exit(1);
}
vnc_display_open(id, &local_err);
if (local_err != NULL) {
error_reportf_err(local_err, "Failed to start VNC server: ");
Expand Down

0 comments on commit ab4f931

Please sign in to comment.