From 39b256e9f11c5cc7115a214654fda8891bfb473f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 16 Jun 2011 13:34:47 +0200 Subject: [PATCH] vdagent: reexec ourself on version mismatch --- src/vdagent.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/vdagent.c b/src/vdagent.c index c40cf5f..5bf0452 100644 --- a/src/vdagent.c +++ b/src/vdagent.c @@ -45,6 +45,7 @@ static struct vdagent_x11 *x11 = NULL; static struct udscs_connection *client = NULL; static FILE *logfile = NULL; static int quit = 0; +static int version_mismatch = 0; void daemon_read_complete(struct udscs_connection **connp, struct udscs_message_header *header, uint8_t *data) @@ -79,6 +80,7 @@ void daemon_read_complete(struct udscs_connection **connp, "Fatal vdagentd version mismatch: got %s expected %s\n", data, VERSION); udscs_destroy_connection(connp); + version_mismatch = 1; } break; default: @@ -148,6 +150,15 @@ static int file_test(const char *path) return stat(path, &buffer); } +static void cleanup(void) +{ + vdagent_x11_destroy(x11); + udscs_destroy_connection(&client); + + if (logfile != stderr) + fclose(logfile); +} + int main(int argc, char *argv[]) { fd_set readfds, writefds; @@ -214,6 +225,14 @@ int main(int argc, char *argv[]) if (do_daemonize) daemonize(); +reconnect: + if (version_mismatch) { + fprintf(logfile, "Version mismatch, restarting\n"); + cleanup(); + sleep(1); + execvp(argv[0], argv); + } + if (client_setup(do_daemonize)) { retval = 1; goto finish; @@ -253,6 +272,8 @@ int main(int argc, char *argv[]) vdagent_x11_destroy(x11); udscs_destroy_connection(&client); + if (!quit) + goto reconnect; finish: if (logfile != stderr) -- 2.11.4.GIT