qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] GuestAgent: PIDFILE remains when daemon start fails
@ 2012-01-05 22:26 MATSUDA, Daiki
  2012-01-06  0:18 ` Michael Roth
  0 siblings, 1 reply; 9+ messages in thread
From: MATSUDA, Daiki @ 2012-01-05 22:26 UTC (permalink / raw)
  To: qemu-devel, Kazuo Tanaka

[-- Attachment #1: Type: text/plain, Size: 175 bytes --]

Hi, all.

I am trying QEMU Guest Agent and encountered a small bug. It is that the
PIDFILE remains when daemon start fails. And maybe forgotton to g_free().

MATSUDA, Daiki



[-- Attachment #2: qemu-ga_add_cleanup.patch --]
[-- Type: text/plain, Size: 3123 bytes --]

diff -uNrp qemu/qemu-ga.c qemu-c47f3223658119219bbe0b8d09da733d1c06e76f/qemu-ga.c
--- qemu/qemu-ga.c	2012-01-05 01:06:25.000000000 +0900
+++ qemu-c47f3223658119219bbe0b8d09da733d1c06e76f/qemu-ga.c	2012-01-06 07:07:03.807872085 +0900
@@ -49,6 +49,13 @@ struct GAState {
 };
 
 static struct GAState *ga_state;
+const char *pidfile = QGA_PIDFILE_DEFAULT;
+
+static void cleanup(void)
+{
+    g_free(ga_state);
+    unlink(pidfile);
+}
 
 static void quit_handler(int sig)
 {
@@ -70,6 +77,7 @@ static void register_signal_handlers(voi
     ret = sigaction(SIGINT, &sigact, NULL);
     if (ret == -1) {
         g_error("error configuring signal handler: %s", strerror(errno));
+        cleanup();
         exit(EXIT_FAILURE);
     }
     ret = sigaction(SIGTERM, &sigact, NULL);
@@ -485,6 +493,7 @@ static void init_guest_agent(GAState *s)
     if (s->path == NULL) {
         if (strcmp(s->method, "virtio-serial") != 0) {
             g_critical("must specify a path for this channel");
+            cleanup();
             exit(EXIT_FAILURE);
         }
         /* try the default path for the virtio-serial port */
@@ -496,17 +505,20 @@ static void init_guest_agent(GAState *s)
         fd = qemu_open(s->path, O_RDWR | O_NONBLOCK | O_ASYNC);
         if (fd == -1) {
             g_critical("error opening channel: %s", strerror(errno));
+            cleanup();
             exit(EXIT_FAILURE);
         }
         ret = conn_channel_add(s, fd);
         if (ret) {
             g_critical("error adding channel to main loop");
+            cleanup();
             exit(EXIT_FAILURE);
         }
     } else if (strcmp(s->method, "isa-serial") == 0) {
         fd = qemu_open(s->path, O_RDWR | O_NOCTTY);
         if (fd == -1) {
             g_critical("error opening channel: %s", strerror(errno));
+            cleanup();
             exit(EXIT_FAILURE);
         }
         tcgetattr(fd, &tio);
@@ -533,15 +545,18 @@ static void init_guest_agent(GAState *s)
         fd = unix_listen(s->path, NULL, strlen(s->path));
         if (fd == -1) {
             g_critical("error opening path: %s", strerror(errno));
+            cleanup();
             exit(EXIT_FAILURE);
         }
         ret = listen_channel_add(s, fd, true);
         if (ret) {
             g_critical("error binding/listening to specified socket");
+            cleanup();
             exit(EXIT_FAILURE);
         }
     } else {
         g_critical("unsupported channel method/type: %s", s->method);
+        cleanup();
         exit(EXIT_FAILURE);
     }
 
@@ -552,7 +567,7 @@ static void init_guest_agent(GAState *s)
 int main(int argc, char **argv)
 {
     const char *sopt = "hVvdm:p:l:f:b:";
-    const char *method = NULL, *path = NULL, *pidfile = QGA_PIDFILE_DEFAULT;
+    const char *method = NULL, *path = NULL;
     const struct option lopt[] = {
         { "help", 0, NULL, 'h' },
         { "version", 0, NULL, 'V' },
@@ -662,7 +677,7 @@ int main(int argc, char **argv)
     g_main_loop_run(ga_state->main_loop);
 
     ga_command_state_cleanup_all(ga_state->command_state);
-    unlink(pidfile);
+    cleanup();
 
     return 0;
 }

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH] GuestAgent: PIDFILE remains when daemon start fails
@ 2012-01-05 22:16 MATSUDA, Daiki
  0 siblings, 0 replies; 9+ messages in thread
From: MATSUDA, Daiki @ 2012-01-05 22:16 UTC (permalink / raw)
  To: qemu-devel, MATSUDA, Daiki

Hi, all.

I am trying QEMU Guest Agent and encountered a small bug. It is that the
PIDFILE remains when daemon start fails. And maybe forgotton to g_free().

MATSUDA, Daiki

diff -uNrp qemu/qemu-ga.c
qemu-c47f3223658119219bbe0b8d09da733d1c06e76f/qemu-ga.c
--- qemu/qemu-ga.c	2012-01-05 01:06:25.000000000 +0900
+++ qemu-c47f3223658119219bbe0b8d09da733d1c06e76f/qemu-ga.c	2012-01-06
07:07:03.807872085 +0900
@@ -49,6 +49,13 @@ struct GAState {
 };

 static struct GAState *ga_state;
+const char *pidfile = QGA_PIDFILE_DEFAULT;
+
+static void cleanup(void)
+{
+    g_free(ga_state);
+    unlink(pidfile);
+}

 static void quit_handler(int sig)
 {
@@ -70,6 +77,7 @@ static void register_signal_handlers(voi
     ret = sigaction(SIGINT, &sigact, NULL);
     if (ret == -1) {
         g_error("error configuring signal handler: %s", strerror(errno));
+        cleanup();
         exit(EXIT_FAILURE);
     }
     ret = sigaction(SIGTERM, &sigact, NULL);
@@ -485,6 +493,7 @@ static void init_guest_agent(GAState *s)
     if (s->path == NULL) {
         if (strcmp(s->method, "virtio-serial") != 0) {
             g_critical("must specify a path for this channel");
+            cleanup();
             exit(EXIT_FAILURE);
         }
         /* try the default path for the virtio-serial port */
@@ -496,17 +505,20 @@ static void init_guest_agent(GAState *s)
         fd = qemu_open(s->path, O_RDWR | O_NONBLOCK | O_ASYNC);
         if (fd == -1) {
             g_critical("error opening channel: %s", strerror(errno));
+            cleanup();
             exit(EXIT_FAILURE);
         }
         ret = conn_channel_add(s, fd);
         if (ret) {
             g_critical("error adding channel to main loop");
+            cleanup();
             exit(EXIT_FAILURE);
         }

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-01-06 20:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-05 22:26 [Qemu-devel] [PATCH] GuestAgent: PIDFILE remains when daemon start fails MATSUDA, Daiki
2012-01-06  0:18 ` Michael Roth
2012-01-06 10:56   ` Daniel P. Berrange
2012-01-06 17:00     ` Michael Roth
2012-01-06 17:05       ` Daniel P. Berrange
2012-01-06 19:06         ` Luiz Capitulino
2012-01-06 20:09           ` Michael Roth
2012-01-06 20:18             ` Luiz Capitulino
  -- strict thread matches above, loose matches on Subject: below --
2012-01-05 22:16 MATSUDA, Daiki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).