]> git.proxmox.com Git - qemu.git/blobdiff - qemu-ga.c
sun4u: give ISA bus to ISA methods
[qemu.git] / qemu-ga.c
index 1f3585c51e13597a8771fd3c22f29abcd1b71b16..200bb1585f06415e6005c10b3d5f6aea0bbe55d5 100644 (file)
--- a/qemu-ga.c
+++ b/qemu-ga.c
@@ -14,7 +14,6 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <glib.h>
-#include <gio/gio.h>
 #include <getopt.h>
 #include <termios.h>
 #include <syslog.h>
@@ -28,6 +27,7 @@
 #include "signal.h"
 #include "qerror.h"
 #include "error_int.h"
+#include "qapi/qmp-core.h"
 
 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
 #define QGA_PIDFILE_DEFAULT "/var/run/qemu-ga.pid"
@@ -37,9 +37,7 @@
 struct GAState {
     JSONMessageParser parser;
     GMainLoop *main_loop;
-    GSocket *conn_sock;
     GIOChannel *conn_channel;
-    GSocket *listen_sock;
     GIOChannel *listen_channel;
     const char *path;
     const char *method;
@@ -54,7 +52,7 @@ static struct GAState *ga_state;
 
 static void quit_handler(int sig)
 {
-    g_debug("recieved signal num %d, quitting", sig);
+    g_debug("received signal num %d, quitting", sig);
 
     if (g_main_loop_is_running(ga_state->main_loop)) {
         g_main_loop_quit(ga_state->main_loop);
@@ -94,6 +92,8 @@ static void usage(const char *cmd)
 "  -v, --verbose     log extra debugging information\n"
 "  -V, --version     print version information and exit\n"
 "  -d, --daemonize   become a daemon\n"
+"  -b, --blacklist   comma-seperated list of RPCs to disable (no spaces, \"?\""
+"                    to list available RPCs)\n"
 "  -h, --help        display this help and exit\n"
 "\n"
 "Report bugs to <mdroth@linux.vnet.ibm.com>\n"
@@ -149,7 +149,7 @@ static void ga_log(const gchar *domain, GLogLevelFlags level,
     }
 
     level &= G_LOG_LEVEL_MASK;
-    if (g_strcmp0(domain, "syslog") == 0) {
+    if (domain && strcmp(domain, "syslog") == 0) {
         syslog(LOG_INFO, "%s: %s", level_str, msg);
     } else if (level & s->log_level) {
         g_get_current_time(&time);
@@ -412,18 +412,20 @@ static gboolean listen_channel_accept(GIOChannel *channel,
                                       GIOCondition condition, gpointer data)
 {
     GAState *s = data;
-    GError *err = NULL;
     g_assert(channel != NULL);
-    int ret;
+    int ret, conn_fd;
     bool accepted = false;
+    struct sockaddr_un addr;
+    socklen_t addrlen = sizeof(addr);
 
-    s->conn_sock = g_socket_accept(s->listen_sock, NULL, &err);
-    if (err != NULL) {
-        g_warning("error converting fd to gsocket: %s", err->message);
-        g_error_free(err);
+    conn_fd = qemu_accept(g_io_channel_unix_get_fd(s->listen_channel),
+                             (struct sockaddr *)&addr, &addrlen);
+    if (conn_fd == -1) {
+        g_warning("error converting fd to gsocket: %s", strerror(errno));
         goto out;
     }
-    ret = conn_channel_add(s, g_socket_get_fd(s->conn_sock));
+    fcntl(conn_fd, F_SETFL, O_NONBLOCK);
+    ret = conn_channel_add(s, conn_fd);
     if (ret) {
         g_warning("error setting up connection");
         goto out;
@@ -440,19 +442,8 @@ out:
  */
 static int listen_channel_add(GAState *s, int listen_fd, bool new)
 {
-    GError *err = NULL;
-
     if (new) {
         s->listen_channel = g_io_channel_unix_new(listen_fd);
-        if (s->listen_sock) {
-            g_object_unref(s->listen_sock);
-        }
-        s->listen_sock = g_socket_new_from_fd(listen_fd, &err);
-        if (err != NULL) {
-            g_warning("error converting fd to gsocket: %s", err->message);
-            g_error_free(err);
-            return -1;
-        }
     }
     g_io_add_watch(s->listen_channel, G_IO_IN,
                    listen_channel_accept, s);
@@ -466,8 +457,6 @@ static void conn_channel_close(GAState *s)
 {
     if (strcmp(s->method, "unix-listen") == 0) {
         g_io_channel_shutdown(s->conn_channel, true, NULL);
-        g_object_unref(s->conn_sock);
-        s->conn_sock = NULL;
         listen_channel_add(s, 0, false);
     } else if (strcmp(s->method, "virtio-serial") == 0) {
         /* we spin on EOF for virtio-serial, so back off a bit. also,
@@ -562,7 +551,7 @@ static void init_guest_agent(GAState *s)
 
 int main(int argc, char **argv)
 {
-    const char *sopt = "hVvdm:p:l:f:";
+    const char *sopt = "hVvdm:p:l:f:b:";
     const char *method = NULL, *path = NULL, *pidfile = QGA_PIDFILE_DEFAULT;
     const struct option lopt[] = {
         { "help", 0, NULL, 'h' },
@@ -573,13 +562,16 @@ int main(int argc, char **argv)
         { "method", 0, NULL, 'm' },
         { "path", 0, NULL, 'p' },
         { "daemonize", 0, NULL, 'd' },
+        { "blacklist", 0, NULL, 'b' },
         { NULL, 0, NULL, 0 }
     };
-    int opt_ind = 0, ch, daemonize = 0;
+    int opt_ind = 0, ch, daemonize = 0, i, j, len;
     GLogLevelFlags log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL;
     FILE *log_file = stderr;
     GAState *s;
 
+    module_call_init(MODULE_INIT_QAPI);
+
     while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
         switch (ch) {
         case 'm':
@@ -609,6 +601,32 @@ int main(int argc, char **argv)
         case 'd':
             daemonize = 1;
             break;
+        case 'b': {
+            char **list_head, **list;
+            if (*optarg == '?') {
+                list_head = list = qmp_get_command_list();
+                while (*list != NULL) {
+                    printf("%s\n", *list);
+                    g_free(*list);
+                    list++;
+                }
+                g_free(list_head);
+                return 0;
+            }
+            for (j = 0, i = 0, len = strlen(optarg); i < len; i++) {
+                if (optarg[i] == ',') {
+                    optarg[i] = 0;
+                    qmp_disable_command(&optarg[j]);
+                    g_debug("disabling command: %s", &optarg[j]);
+                    j = i + 1;
+                }
+            }
+            if (j < i) {
+                qmp_disable_command(&optarg[j]);
+                g_debug("disabling command: %s", &optarg[j]);
+            }
+            break;
+        }
         case 'h':
             usage(argv[0]);
             return 0;
@@ -624,10 +642,7 @@ int main(int argc, char **argv)
         become_daemon(pidfile);
     }
 
-    g_type_init();
-    g_thread_init(NULL);
-
-    s = qemu_mallocz(sizeof(GAState));
+    s = g_malloc0(sizeof(GAState));
     s->conn_channel = NULL;
     s->path = path;
     s->method = method;
@@ -636,14 +651,17 @@ int main(int argc, char **argv)
     g_log_set_default_handler(ga_log, s);
     g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR);
     s->logging_enabled = true;
+    s->command_state = ga_command_state_new();
+    ga_command_state_init(s, s->command_state);
+    ga_command_state_init_all(s->command_state);
     ga_state = s;
 
-    module_call_init(MODULE_INIT_QAPI);
     init_guest_agent(ga_state);
     register_signal_handlers();
 
     g_main_loop_run(ga_state->main_loop);
 
+    ga_command_state_cleanup_all(ga_state->command_state);
     unlink(pidfile);
 
     return 0;