diff options
author | kraxel <kraxel> | 2007-02-07 17:13:00 +0000 |
---|---|---|
committer | kraxel <kraxel> | 2007-02-07 17:13:00 +0000 |
commit | 00c221150a3d3638b8a701e0d2080fd86ccf6fde (patch) | |
tree | 1369b3305d4630b2be5f24c1ec6ba6db6270277b | |
parent | 7d906990781d561e9b196138356300460b2c0da2 (diff) | |
download | xenwatch-00c221150a3d3638b8a701e0d2080fd86ccf6fde.tar.gz |
xendom
-rw-r--r-- | mdns-publish-xendom.c | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/mdns-publish-xendom.c b/mdns-publish-xendom.c index ec22206..01678a4 100644 --- a/mdns-publish-xendom.c +++ b/mdns-publish-xendom.c @@ -24,14 +24,18 @@ static struct xs_handle *xenstore; static int debug = 0; static char *appname = "mdns-publish-xendom"; +static struct utsname uts; static char *service = "_xendom._tcp"; static int port = 9; static char vm_uuid[256]; static char dom_id[256]; +static struct mdns_pub *mdns; +static struct mdns_pub_entry *entry; + /* --------------------------------------------------------------------- */ -static int xen_init(struct mdns_pub *mdns) +static int xen_init(void) { struct stat st; @@ -51,7 +55,7 @@ static int xen_init(struct mdns_pub *mdns) return 0; } -static int xen_get_info(struct mdns_pub *mdns) +static int xen_get_info(void) { xs_transaction_t xst; char *xs_value; @@ -86,7 +90,7 @@ static int xen_get_info(struct mdns_pub *mdns) return -1; } -static int xen_watch_add(struct mdns_pub *mdns, char *path) +static int xen_watch_add(char *path) { int ret = 0; @@ -99,14 +103,32 @@ static int xen_watch_add(struct mdns_pub *mdns, char *path) return ret; } -static int xen_watch_data(struct mdns_pub *mdns) +static int xen_publish(void) +{ + static int count = 1; + char buf[128]; + + if (debug) + snprintf(buf, sizeof(buf), "Xen domain %s (%d)", uts.nodename, count++); + else + snprintf(buf, sizeof(buf), "Xen domain %s", uts.nodename); + + if (entry) + mdns_pub_del(entry); + entry = mdns_pub_add(mdns, buf, service, port, + vm_uuid, dom_id, NULL); + return 0; +} + +static int xen_watch_data(void) { char **vec = NULL; unsigned int count; vec = xs_read_watch(xenstore, &count); mdns_log_printf(mdns, LOG_DEBUG, "%s: \"%s\"\n", __FUNCTION__, vec[XS_WATCH_PATH]); - + xen_get_info(); + xen_publish(); if (vec) free(vec); return 0; @@ -150,11 +172,8 @@ static int wait_fd(int fd, int secs) int main(int argc, char*argv[]) { - struct mdns_pub *mdns = NULL; - char buf[128]; - struct utsname uts; - int c; int ret = 1; + int c; /* parse options */ for (;;) { @@ -175,34 +194,27 @@ int main(int argc, char*argv[]) /* figure name */ uname(&uts); - snprintf(buf, sizeof(buf), "Xen domain %s", uts.nodename); mdns_pub_appname = appname; if (!debug) mdns_daemonize(); - /* figure domain info */ - if (0 != xen_init(mdns)) - goto fail; - xen_get_info(mdns); - mdns = mdns_pub_init(debug); if (NULL == mdns) goto fail; - mdns_pub_add(mdns, buf, service, port, - vm_uuid, dom_id, NULL); mdns_sigsetup(mdns); + /* figure domain info */ + if (0 != xen_init()) + goto fail; + xen_get_info(); + + xen_watch_add("vm"); + xen_watch_add("domid"); + /* enter main loop */ ret = 0; mdns_pub_start(mdns); - - if (0) { - /* hmm, not working */ - if (0 != xen_watch_add(mdns, "memory/target")) - goto fail; - xen_watch_add(mdns, "vm"); - xen_watch_add(mdns, "domid"); - } + xen_publish(); for (;;) { if (mdns_pub_appquit) @@ -216,7 +228,7 @@ int main(int argc, char*argv[]) break; default: /* data to read */ - xen_watch_data(mdns); + xen_watch_data(); } } |