NAck - this breaks the Linux build. See below for more comments.
- ZB
On 06/09/11 05:00, Adam Stokes wrote:
- Fixes rhbz#733483 as a result
- Add support for generating UUIDs in Windows
Signed-off-by: Adam Stokes<astokes(a)fedoraproject.org>
---
src/lib/CMakeLists.txt | 2 +-
src/lib/utilities.c | 31 ++++++++++---------------------
src/lib/utilities_linux.c | 19 +++++++++++++++++++
src/lib/utilities_private.h | 14 ++++++++++++++
src/lib/utilities_windows.c | 24 ++++++++++++++++++++++++
5 files changed, 68 insertions(+), 22 deletions(-)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 1cd41d4..610040f 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -32,7 +32,7 @@ target_link_libraries(msysconfig ${pcre_LIBRARIES} mcommon
${glib_LIBRARIES})
if(WIN32)
foreach (lib ${LIBS})
- target_link_libraries(${lib} wsock32 dnsapi)
+ target_link_libraries(${lib} wsock32 dnsapi rpcrt4)
install(TARGETS ${lib} DESTINATION sbin)
endforeach (lib ${LIBS})
else(WIN32)
diff --git a/src/lib/utilities.c b/src/lib/utilities.c
index 9d60de8..30720a4 100644
--- a/src/lib/utilities.c
+++ b/src/lib/utilities.c
@@ -382,6 +382,16 @@ mh_dnsdomainname(void)
}
const char *
+mh_uuid(void)
+{
+ const char *res;
+
+ res = mh_os_uuid();
+
+ return res;
+}
+
+const char *
mh_hostname(void)
{
static char *hostname = NULL;
@@ -437,27 +447,6 @@ char *mh_file_first_line(const char *file)
return buffer;
}
-const char *
-mh_uuid(void)
-{
- static char *uuid = NULL;
-
-#ifdef __linux__
- if (uuid == NULL&& g_file_test("/etc/machine-id",
G_FILE_TEST_EXISTS)) {
- uuid = mh_file_first_line("/etc/machine-id");
- }
- if (uuid == NULL&& g_file_test("/var/lib/dbus/machine-id",
G_FILE_TEST_EXISTS)) {
- /* For pre-systemd machines */
- uuid = mh_file_first_line("/var/lib/dbus/machine-id");
- }
-#endif
-
- if(uuid) {
- mh_trace("Got uuid: %s", uuid);
- }
- return uuid;
-}
-
#ifdef WIN32
wchar_t *
char2wide(const char *str)
diff --git a/src/lib/utilities_linux.c b/src/lib/utilities_linux.c
index c848802..f0aae14 100644
--- a/src/lib/utilities_linux.c
+++ b/src/lib/utilities_linux.c
@@ -63,3 +63,22 @@ mh_os_dnsdomainname(void)
return dnsdomainname ? dnsdomainname : "";
}
+
+const char *
+mh_os_uuid(void)
+{
+ static char *uuid = NULL;
+
+ if (uuid == NULL&& g_file_test("/etc/machine-id",
G_FILE_TEST_EXISTS)) {
This was already in the code before you moved it, but could you fix up
the spaces around the && at the same time please?
+ uuid = mh_file_first_line("/etc/machine-id");
+ }
+ if (uuid == NULL&& g_file_test("/var/lib/dbus/machine-id",
G_FILE_TEST_EXISTS)) {
+ /* For pre-systemd machines */
+ uuid = mh_file_first_line("/var/lib/dbus/machine-id");
+ }
+
+ if(uuid) {
+ mh_trace("Got uuid: %s", uuid);
+ }
+ return uuid;
+}
diff --git a/src/lib/utilities_private.h b/src/lib/utilities_private.h
index e39d22c..41f074d 100644
--- a/src/lib/utilities_private.h
+++ b/src/lib/utilities_private.h
@@ -30,10 +30,24 @@
#ifndef __MH_UTILITIES_PRIVATE_H__
#define __MH_UTILITIES_PRIVATE_H__
+#include<windows.h>
+#include<rpc.h>
You can't put this in this header; it's included in both Windows & Linux
builds.
+
+#ifdef uuid_t
+#undef uuid_t
+#endif
+typedef UUID uuid_t[1];
+
Changing the definition of uuid_t midstream is unnecessary obfuscation.
Just declare a UUID and pass a pointer to it; no need to make it an
array of 1 so that the pointer conversion is hidden.
/**
* Get the local dnsdomainname.
*/
const char *
mh_os_dnsdomainname(void);
+/**
+ * Generate UUID
+ */
+const char *
+mh_os_uuid(void);
+
#endif /* __MH_UTILITIES_PRIVATE_H__ */
diff --git a/src/lib/utilities_windows.c b/src/lib/utilities_windows.c
index 26a3679..583b544 100644
--- a/src/lib/utilities_windows.c
+++ b/src/lib/utilities_windows.c
@@ -18,9 +18,15 @@
#include "config.h"
+#include<windows.h>
+#include<rpc.h>
+
#include "matahari/utilities.h"
+#include "matahari/logging.h"
#include "utilities_private.h"
+#define MAXUUIDLEN 37
+
const char *
mh_os_dnsdomainname(void)
{
@@ -32,3 +38,21 @@ mh_os_dnsdomainname(void)
return mh_domainname();
}
+
+const char *
+mh_os_uuid(void)
+{
+ uuid_t u;
+ static char s[MAXUUIDLEN];
+ unsigned char __RPC_FAR *rs;
+
+ UuidCreate(u);
This function generates a new UUID each time it is called. Is that the
intended behaviour? It doesn't seem consistent with the Linux
implementation of mh_host_uuid().
+
+ if (UuidToStringA((UUID *)u,&rs) == RPC_S_OK) {
This cast is not required.
+ strncpy(s,(char __RPC_FAR *)rs, MAXUUIDLEN);
strncpy() does not necessarily null-terminate the destination.
Also, the cast here could just be to char *
+ RpcStringFree(&rs);
This needs to be RpcStringFreeA() to avoid a compiler warning.
+ mh_trace("Got uuid: %s", s);
+ return s;
+ }
+ return "";
+}