From 6159c7f6143f103ba720bef552e65c16e2578679 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Mon, 8 Sep 2014 12:20:19 +0200 Subject: [PATCH 2/4] Make retrieving harware informations working on FreeBSD --- src/interfaces/hostnamed/hostnamed.c | 22 ++++++++++++++++++++++ src/interfaces/hostnamed/hostnamed.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/interfaces/hostnamed/hostnamed.c b/src/interfaces/hostnamed/hostnamed.c index a320e2e..43c1b43 100644 --- a/src/interfaces/hostnamed/hostnamed.c +++ b/src/interfaces/hostnamed/hostnamed.c @@ -21,11 +21,19 @@ #include #include +#ifdef __OpenBSD__ #include +#endif #include #include +#ifdef __OpenBSD__ #include +#endif + +#ifdef __FreeBSD__ +#include +#endif #include #include @@ -852,27 +860,41 @@ gboolean determine_chassis_and_icon() { g_ptr_array_add(hostnamed_freeable, hwvendor); g_ptr_array_add(hostnamed_freeable, hwmachine); +#ifdef HW_PRODUCT hwproduct_name[0] = CTL_HW; hwproduct_name[1] = HW_PRODUCT; +#endif hwmodel_name[0] = CTL_HW; hwmodel_name[1] = HW_MODEL; +#ifdef HW_VENDOR hwvendor_name[0] = CTL_HW; hwvendor_name[1] = HW_VENDOR; +#endif hwmachine_name[0] = CTL_HW; hwmachine_name[1] = HW_MACHINE; /* pass NULL buffer to check size first, then pass hw to be filled according to freshly-set hw_size */ +#ifndef HW_PRODUCT + if(-1 == kenv(KENV_GET, "smbios.system.product", hwproduct, 4096)) + return FALSE; +#else if(-1 == sysctl(hwproduct_name, 2, NULL, &hwproduct_size, NULL, 0) || -1 == sysctl(hwproduct_name, 2, hwproduct, &hwproduct_size, NULL, 0)) return FALSE; +#endif if(-1 == sysctl(hwmodel_name, 2, NULL, &hwmodel_size, NULL, 0) || -1 == sysctl(hwmodel_name, 2, hwmodel, &hwmodel_size, NULL, 0)) return FALSE; +#ifndef HW_VENDOR + if(-1 == kenv(KENV_GET, "smbios.system.maker", hwvendor, 4096)) + return FALSE; +#else if(-1 == sysctl(hwvendor_name, 2, NULL, &hwvendor_size, NULL, 0) || -1 == sysctl(hwvendor_name, 2, hwvendor, &hwvendor_size, NULL, 0)) return FALSE; +#endif if(-1 == sysctl(hwmachine_name, 2, NULL, &hwmachine_size, NULL, 0) || -1 == sysctl(hwmachine_name, 2, hwmachine, &hwmachine_size, NULL, 0)) return FALSE; diff --git a/src/interfaces/hostnamed/hostnamed.h b/src/interfaces/hostnamed/hostnamed.h index a4dbc0b..daad606 100644 --- a/src/interfaces/hostnamed/hostnamed.h +++ b/src/interfaces/hostnamed/hostnamed.h @@ -21,7 +21,9 @@ const gchar *our_get_pretty_hostname(); int up_apm_get_fd(); gboolean determine_chassis_and_icon(); +#ifdef __OpenBSD__ gboolean up_native_get_sensordev(const char * id, struct sensordev * snsrdev); +#endif gboolean up_native_is_laptop(); gboolean is_server(gchar *arch); gboolean set_uname_properties(); -- 2.1.0