Revision 1fc7bd4a qemu-ga.c
b/qemu-ga.c | ||
---|---|---|
14 | 14 |
#include <stdio.h> |
15 | 15 |
#include <stdbool.h> |
16 | 16 |
#include <glib.h> |
17 |
#include <gio/gio.h> |
|
18 | 17 |
#include <getopt.h> |
19 | 18 |
#include <termios.h> |
20 | 19 |
#include <syslog.h> |
... | ... | |
37 | 36 |
struct GAState { |
38 | 37 |
JSONMessageParser parser; |
39 | 38 |
GMainLoop *main_loop; |
40 |
GSocket *conn_sock; |
|
41 | 39 |
GIOChannel *conn_channel; |
42 |
GSocket *listen_sock; |
|
43 | 40 |
GIOChannel *listen_channel; |
44 | 41 |
const char *path; |
45 | 42 |
const char *method; |
... | ... | |
412 | 409 |
GIOCondition condition, gpointer data) |
413 | 410 |
{ |
414 | 411 |
GAState *s = data; |
415 |
GError *err = NULL; |
|
416 | 412 |
g_assert(channel != NULL); |
417 |
int ret; |
|
413 |
int ret, conn_fd;
|
|
418 | 414 |
bool accepted = false; |
415 |
struct sockaddr_un addr; |
|
416 |
socklen_t addrlen = sizeof(addr); |
|
419 | 417 |
|
420 |
s->conn_sock = g_socket_accept(s->listen_sock, NULL, &err);
|
|
421 |
if (err != NULL) {
|
|
422 |
g_warning("error converting fd to gsocket: %s", err->message);
|
|
423 |
g_error_free(err);
|
|
418 |
conn_fd = qemu_accept(g_io_channel_unix_get_fd(s->listen_channel),
|
|
419 |
(struct sockaddr *)&addr, &addrlen);
|
|
420 |
if (conn_fd == -1) {
|
|
421 |
g_warning("error converting fd to gsocket: %s", strerror(errno));
|
|
424 | 422 |
goto out; |
425 | 423 |
} |
426 |
ret = conn_channel_add(s, g_socket_get_fd(s->conn_sock)); |
|
424 |
fcntl(conn_fd, F_SETFL, O_NONBLOCK); |
|
425 |
ret = conn_channel_add(s, conn_fd); |
|
427 | 426 |
if (ret) { |
428 | 427 |
g_warning("error setting up connection"); |
429 | 428 |
goto out; |
... | ... | |
440 | 439 |
*/ |
441 | 440 |
static int listen_channel_add(GAState *s, int listen_fd, bool new) |
442 | 441 |
{ |
443 |
GError *err = NULL; |
|
444 |
|
|
445 | 442 |
if (new) { |
446 | 443 |
s->listen_channel = g_io_channel_unix_new(listen_fd); |
447 |
if (s->listen_sock) { |
|
448 |
g_object_unref(s->listen_sock); |
|
449 |
} |
|
450 |
s->listen_sock = g_socket_new_from_fd(listen_fd, &err); |
|
451 |
if (err != NULL) { |
|
452 |
g_warning("error converting fd to gsocket: %s", err->message); |
|
453 |
g_error_free(err); |
|
454 |
return -1; |
|
455 |
} |
|
456 | 444 |
} |
457 | 445 |
g_io_add_watch(s->listen_channel, G_IO_IN, |
458 | 446 |
listen_channel_accept, s); |
... | ... | |
466 | 454 |
{ |
467 | 455 |
if (strcmp(s->method, "unix-listen") == 0) { |
468 | 456 |
g_io_channel_shutdown(s->conn_channel, true, NULL); |
469 |
g_object_unref(s->conn_sock); |
|
470 |
s->conn_sock = NULL; |
|
471 | 457 |
listen_channel_add(s, 0, false); |
472 | 458 |
} else if (strcmp(s->method, "virtio-serial") == 0) { |
473 | 459 |
/* we spin on EOF for virtio-serial, so back off a bit. also, |
... | ... | |
624 | 610 |
become_daemon(pidfile); |
625 | 611 |
} |
626 | 612 |
|
627 |
g_type_init(); |
|
628 |
g_thread_init(NULL); |
|
629 |
|
|
630 | 613 |
s = qemu_mallocz(sizeof(GAState)); |
631 | 614 |
s->conn_channel = NULL; |
632 | 615 |
s->path = path; |
Also available in: Unified diff