diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-01-22 19:14:59 +0100 |
---|---|---|
committer | Christian Göttsche <cgzones@googlemail.com> | 2021-01-25 18:01:39 +0100 |
commit | 575edffb4bf4e8a98949a368efa9ba5905c08462 (patch) | |
tree | d6a1ebf7745d5aba9112d48fb07ae7d70479c80f /linux | |
parent | 759a34039c10081e510b9217d9d25ce6e9f200ae (diff) |
Add configure option to create static htop binary
Diffstat (limited to 'linux')
-rw-r--r-- | linux/LibSensors.c | 34 | ||||
-rw-r--r-- | linux/SystemdMeter.c | 44 |
2 files changed, 75 insertions, 3 deletions
diff --git a/linux/LibSensors.c b/linux/LibSensors.c index 158829aa..f94bcff7 100644 --- a/linux/LibSensors.c +++ b/linux/LibSensors.c @@ -10,6 +10,19 @@ #include "XUtils.h" +#ifdef BUILD_STATIC + +#define sym_sensors_init sensors_init +#define sym_sensors_cleanup sensors_cleanup +#define sym_sensors_get_detected_chips sensors_get_detected_chips +#define sym_sensors_snprintf_chip_name sensors_snprintf_chip_name +#define sym_sensors_get_features sensors_get_features +#define sym_sensors_get_subfeature sensors_get_subfeature +#define sym_sensors_get_value sensors_get_value +#define sym_sensors_get_label sensors_get_label + +#else + static int (*sym_sensors_init)(FILE*); static void (*sym_sensors_cleanup)(void); static const sensors_chip_name* (*sym_sensors_get_detected_chips)(const sensors_chip_name*, int*); @@ -21,7 +34,15 @@ static char* (*sym_sensors_get_label)(const sensors_chip_name*, const sensors_fe static void* dlopenHandle = NULL; +#endif /* BUILD_STATIC */ + int LibSensors_init(FILE* input) { +#ifdef BUILD_STATIC + + return sym_sensors_init(input); + +#else + if (!dlopenHandle) { /* Find the unversioned libsensors.so (symlink) and prefer that, but Debian has .so.5 and Fedora .so.4 without matching symlinks (unless people install the -dev packages) */ @@ -56,29 +77,42 @@ int LibSensors_init(FILE* input) { return sym_sensors_init(input); + dlfailure: if (dlopenHandle) { dlclose(dlopenHandle); dlopenHandle = NULL; } return -1; + +#endif /* BUILD_STATIC */ } void LibSensors_cleanup(void) { +#ifdef BUILD_STATIC + + sym_sensors_cleanup(); + +#else + if (dlopenHandle) { sym_sensors_cleanup(); dlclose(dlopenHandle); dlopenHandle = NULL; } + +#endif /* BUILD_STATIC */ } void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int cpuCount) { for (unsigned int i = 0; i <= cpuCount; i++) cpus[i].temperature = NAN; +#ifndef BUILD_STATIC if (!dlopenHandle) return; +#endif /* !BUILD_STATIC */ unsigned int coreTempCount = 0; diff --git a/linux/SystemdMeter.c b/linux/SystemdMeter.c index 75c666f8..f6dcb3fb 100644 --- a/linux/SystemdMeter.c +++ b/linux/SystemdMeter.c @@ -21,8 +21,19 @@ in the source distribution for its full text. #include "RichString.h" #include "XUtils.h" +#if defined(BUILD_STATIC) && defined(HAVE_LIBSYSTEMD) +#include <systemd/sd-bus.h> +#endif -#define INVALID_VALUE ((unsigned int)-1) + +#ifdef BUILD_STATIC + +#define sym_sd_bus_open_system sd_bus_open_system +#define sym_sd_bus_get_property_string sd_bus_get_property_string +#define sym_sd_bus_get_property_trivial sd_bus_get_property_trivial +#define sym_sd_bus_unref sd_bus_unref + +#else typedef void sd_bus; typedef void sd_bus_error; @@ -30,19 +41,35 @@ static int (*sym_sd_bus_open_system)(sd_bus**); static int (*sym_sd_bus_get_property_string)(sd_bus*, const char*, const char*, const char*, const char*, sd_bus_error*, char**); static int (*sym_sd_bus_get_property_trivial)(sd_bus*, const char*, const char*, const char*, const char*, sd_bus_error*, char, void*); static sd_bus* (*sym_sd_bus_unref)(sd_bus*); +static void* dlopenHandle = NULL; + +#endif /* BUILD_STATIC */ + +#if !defined(BUILD_STATIC) || defined(HAVE_LIBSYSTEMD) +static sd_bus* bus = NULL; +#endif /* !BUILD_STATIC || HAVE_LIBSYSTEMD */ + + +#define INVALID_VALUE ((unsigned int)-1) static char* systemState = NULL; static unsigned int nFailedUnits = INVALID_VALUE; static unsigned int nInstalledJobs = INVALID_VALUE; static unsigned int nNames = INVALID_VALUE; static unsigned int nJobs = INVALID_VALUE; -static void* dlopenHandle = NULL; -static sd_bus* bus = NULL; static void SystemdMeter_done(ATTR_UNUSED Meter* this) { free(systemState); systemState = NULL; +#ifdef BUILD_STATIC +# ifdef HAVE_LIBSYSTEMD + if (bus) { + sym_sd_bus_unref(bus); + } + bus = NULL; +# endif /* HAVE_LIBSYSTEMD */ +#else /* BUILD_STATIC */ if (bus && dlopenHandle) { sym_sd_bus_unref(bus); } @@ -52,9 +79,12 @@ static void SystemdMeter_done(ATTR_UNUSED Meter* this) { dlclose(dlopenHandle); dlopenHandle = NULL; } +#endif /* BUILD_STATIC */ } +#if !defined(BUILD_STATIC) || defined(HAVE_LIBSYSTEMD) static int updateViaLib(void) { +#ifndef BUILD_STATIC if (!dlopenHandle) { dlopenHandle = dlopen("libsystemd.so.0", RTLD_LAZY); if (!dlopenHandle) @@ -76,6 +106,7 @@ static int updateViaLib(void) { #undef resolve } +#endif /* !BUILD_STATIC */ int r; @@ -152,13 +183,16 @@ busfailure: bus = NULL; return -2; +#ifndef BUILD_STATIC dlfailure: if (dlopenHandle) { dlclose(dlopenHandle); dlopenHandle = NULL; } return -1; +#endif /* !BUILD_STATIC */ } +#endif /* !BUILD_STATIC || HAVE_LIBSYSTEMD */ static void updateViaExec(void) { int fdpair[2]; @@ -233,8 +267,12 @@ static void SystemdMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, siz systemState = NULL; nFailedUnits = nInstalledJobs = nNames = nJobs = INVALID_VALUE; +#if !defined(BUILD_STATIC) || defined(HAVE_LIBSYSTEMD) if (updateViaLib() < 0) updateViaExec(); +#else + updateViaExec(); +#endif /* !BUILD_STATIC || HAVE_LIBSYSTEMD */ xSnprintf(buffer, size, "%s", systemState ? systemState : "???"); } |