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/SystemdMeter.c | |
parent | 759a34039c10081e510b9217d9d25ce6e9f200ae (diff) |
Add configure option to create static htop binary
Diffstat (limited to 'linux/SystemdMeter.c')
-rw-r--r-- | linux/SystemdMeter.c | 44 |
1 files changed, 41 insertions, 3 deletions
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 : "???"); } |