~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to vswitchd/xenserver.c

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2009, 2010 Nicira, Inc.
 
1
/* Copyright (c) 2009, 2010, 2013 Nicira, Inc.
2
2
 *
3
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
4
 * you may not use this file except in compliance with the License.
17
17
#include "xenserver.h"
18
18
#include <ctype.h>
19
19
#include <errno.h>
 
20
#include <pthread.h>
20
21
#include <stdlib.h>
21
22
#include <string.h>
22
23
#include <unistd.h>
26
27
 
27
28
VLOG_DEFINE_THIS_MODULE(xenserver);
28
29
 
29
 
static char *
 
30
/* If running on a XenServer, the XenServer host UUID as a 36-character string,
 
31
 * otherwise null. */
 
32
static char *host_uuid;
 
33
 
 
34
static void
30
35
read_host_uuid(void)
31
36
{
32
37
    static const char filename[] = "/etc/xensource-inventory";
38
43
        if (errno == ENOENT) {
39
44
            VLOG_DBG("not running on a XenServer");
40
45
        } else {
41
 
            VLOG_INFO("%s: open: %s", filename, strerror(errno));
 
46
            VLOG_INFO("%s: open: %s", filename, ovs_strerror(errno));
42
47
        }
43
 
        return NULL;
 
48
        return;
44
49
    }
45
50
 
46
51
    while (fgets(line, sizeof line, file)) {
53
58
        if (strlen(line) == leader_len + uuid_len + trailer_len
54
59
            && !memcmp(line, leader, leader_len)
55
60
            && !memcmp(line + leader_len + uuid_len, trailer, trailer_len)) {
56
 
            char *host_uuid = xmemdup0(line + leader_len, uuid_len);
 
61
            host_uuid = xmemdup0(line + leader_len, uuid_len);
57
62
            VLOG_INFO("running on XenServer, host-uuid %s", host_uuid);
58
63
            fclose(file);
59
 
            return host_uuid;
 
64
            return;
60
65
        }
61
66
    }
62
67
    fclose(file);
63
68
    VLOG_ERR("%s: INSTALLATION_UUID not found", filename);
64
 
    return NULL;
65
69
}
66
70
 
67
71
const char *
68
72
xenserver_get_host_uuid(void)
69
73
{
70
 
    static char *host_uuid;
71
 
    static bool inited;
72
 
 
73
 
    if (!inited) {
74
 
        host_uuid = read_host_uuid();
75
 
        inited = true;
76
 
    }
 
74
    static pthread_once_t once = PTHREAD_ONCE_INIT;
 
75
    pthread_once(&once, read_host_uuid);
77
76
    return host_uuid;
78
77
}
79
78