X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=vswitchd%2Fxenserver.c;h=bc57f0eadbe9a0437cf2268f368b036a360301d0;hb=HEAD;hp=1f29daf2d4f872f618ea253aee955776c21de175;hpb=e368cad8ecf6dbf272b2a3775b2e3e5e2dc6a5cf;p=sliver-openvswitch.git diff --git a/vswitchd/xenserver.c b/vswitchd/xenserver.c index 1f29daf2d..bc57f0ead 100644 --- a/vswitchd/xenserver.c +++ b/vswitchd/xenserver.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010 Nicira, Inc. +/* Copyright (c) 2009, 2010, 2013 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ #include "xenserver.h" #include #include +#include #include #include #include @@ -26,7 +27,11 @@ VLOG_DEFINE_THIS_MODULE(xenserver); -static char * +/* If running on a XenServer, the XenServer host UUID as a 36-character string, + * otherwise null. */ +static char *host_uuid; + +static void read_host_uuid(void) { static const char filename[] = "/etc/xensource-inventory"; @@ -36,11 +41,11 @@ read_host_uuid(void) file = fopen(filename, "r"); if (!file) { if (errno == ENOENT) { - VLOG_INFO("not running on a XenServer"); + VLOG_DBG("not running on a XenServer"); } else { - VLOG_INFO("%s: open: %s", filename, strerror(errno)); + VLOG_INFO("%s: open: %s", filename, ovs_strerror(errno)); } - return NULL; + return; } while (fgets(line, sizeof line, file)) { @@ -53,27 +58,21 @@ read_host_uuid(void) if (strlen(line) == leader_len + uuid_len + trailer_len && !memcmp(line, leader, leader_len) && !memcmp(line + leader_len + uuid_len, trailer, trailer_len)) { - char *host_uuid = xmemdup0(line + leader_len, uuid_len); + host_uuid = xmemdup0(line + leader_len, uuid_len); VLOG_INFO("running on XenServer, host-uuid %s", host_uuid); fclose(file); - return host_uuid; + return; } } fclose(file); VLOG_ERR("%s: INSTALLATION_UUID not found", filename); - return NULL; } const char * xenserver_get_host_uuid(void) { - static char *host_uuid; - static bool inited; - - if (!inited) { - host_uuid = read_host_uuid(); - inited = true; - } + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, read_host_uuid); return host_uuid; }