trivial: Allow compiling without <sys/utsname.h>

This commit is contained in:
Richard Hughes 2019-11-22 08:53:33 +00:00
parent 17957ebf13
commit fc1e267d33
3 changed files with 20 additions and 0 deletions

View File

@ -13,7 +13,9 @@
#include <locale.h>
#include <string.h>
#ifdef HAVE_UTSNAME_H
#include <sys/utsname.h>
#endif
#include <json-glib/json-glib.h>
#if !GLIB_CHECK_VERSION(2,54,0)
@ -222,12 +224,15 @@ fwupd_build_user_agent_os_release (void)
static gchar *
fwupd_build_user_agent_system (void)
{
#ifdef HAVE_UTSNAME_H
struct utsname name_tmp;
#endif
g_autofree gchar *locale = NULL;
g_autofree gchar *os_release = NULL;
g_autoptr(GPtrArray) ids = g_ptr_array_new_with_free_func (g_free);
/* system, architecture and kernel, e.g. "Linux i686 4.14.5" */
#ifdef HAVE_UTSNAME_H
memset (&name_tmp, 0, sizeof(struct utsname));
if (uname (&name_tmp) >= 0) {
g_ptr_array_add (ids, g_strdup_printf ("%s %s %s",
@ -235,6 +240,7 @@ fwupd_build_user_agent_system (void)
name_tmp.machine,
name_tmp.release));
}
#endif
/* current locale, e.g. "en-gb" */
locale = g_strdup (setlocale (LC_MESSAGES, NULL));

View File

@ -222,6 +222,10 @@ if build_standalone and get_option('plugin_altos')
libelf = dependency('libelf')
endif
if cc.has_header('sys/utsname.h')
conf.set('HAVE_UTSNAME_H', '1')
endif
if build_standalone and get_option('plugin_uefi')
cairo = dependency('cairo')
fontconfig = cc.find_library('fontconfig')

View File

@ -14,7 +14,9 @@
#include <gudev/gudev.h>
#include <fnmatch.h>
#include <string.h>
#ifdef HAVE_UTSNAME_H
#include <sys/utsname.h>
#endif
#include "fwupd-common-private.h"
#include "fwupd-enums-private.h"
@ -1380,7 +1382,9 @@ fu_engine_get_report_metadata (FuEngine *self)
{
GHashTable *hash;
gchar *btime;
#ifdef HAVE_UTSNAME_H
struct utsname name_tmp;
#endif
g_autoptr(GList) compile_keys = g_hash_table_get_keys (self->compile_versions);
g_autoptr(GList) runtime_keys = g_hash_table_get_keys (self->runtime_versions);
@ -1402,12 +1406,14 @@ fu_engine_get_report_metadata (FuEngine *self)
}
/* kernel version is often important for debugging failures */
#ifdef HAVE_UTSNAME_H
memset (&name_tmp, 0, sizeof (struct utsname));
if (uname (&name_tmp) >= 0) {
g_hash_table_insert (hash,
g_strdup ("CpuArchitecture"),
g_strdup (name_tmp.machine));
}
#endif
/* add the kernel boot time so we can detect a reboot */
btime = fu_engine_get_boot_time ();
@ -4947,7 +4953,9 @@ fu_engine_idle_status_notify_cb (FuIdle *idle, GParamSpec *pspec, FuEngine *self
static void
fu_engine_init (FuEngine *self)
{
#ifdef HAVE_UTSNAME_H
struct utsname uname_tmp;
#endif
self->percentage = 0;
self->status = FWUPD_STATUS_IDLE;
self->config = fu_config_new ();
@ -4983,9 +4991,11 @@ fu_engine_init (FuEngine *self)
#endif
/* optional kernel version */
#ifdef HAVE_UTSNAME_H
memset (&uname_tmp, 0, sizeof(uname_tmp));
if (uname (&uname_tmp) >= 0)
fu_engine_add_runtime_version (self, "org.kernel", uname_tmp.release);
#endif
g_hash_table_insert (self->compile_versions,
g_strdup ("com.redhat.fwupdate"),