fix release+refresh hardware caches

This commit is contained in:
deepend committed 2026-12-04 18:24:57 -06:00
1 parent 3abcb33d4f
commit 42efb59ee0
6 files changed
+82 -30

No files matched your search

+10 -2
View File
@@ -99,10 +99,19 @@ get_os_fallback (void)
return g_strdup_printf ("OS X %ld.%ld.%ld", version.majorVersion, version.minorVersion, version.patchVersion);
#endif
}
static char *os_str;
static char *gpu_str;
void
sysinfo_backend_reset_cache (void)
{
g_clear_pointer (&os_str, g_free);
g_clear_pointer (&gpu_str, g_free);
}
char *
sysinfo_backend_get_os(void)
{
static char *os_str = NULL;
if (!os_str)
{
os_str = get_os();
@@ -250,7 +259,6 @@ get_gpu(void)
char *
sysinfo_backend_get_gpu(void)
{
static char *gpu_str = NULL;
if (!gpu_str)
gpu_str = get_gpu();
+2
View File
@@ -21,6 +21,8 @@
#ifndef SYSINFO_BACKEND_H
#define SYSINFO_BACKEND_H
/* Called on the same client thread as the getters. Safe to call repeatedly. */
void sysinfo_backend_reset_cache (void);
char *sysinfo_backend_get_os(void);
char *sysinfo_backend_get_disk(void);
char *sysinfo_backend_get_memory(void);
+10 -4
View File
@@ -41,7 +41,7 @@ static zoitechat_plugin *ph;
static char name[] = "Sysinfo";
static char desc[] = "Display info about your hardware and OS";
static char version[] = "2.0";
static char sysinfo_help[] = "SysInfo Usage:\n /SYSINFO [-e|-o] [CLIENT|UI|OS|CPU|RAM|MEMORY|STORAGE|DISK|GPU|VGA|CHIPSET|SOUND|NETWORK|ETHERNET|UPTIME], print various details about your system or print a summary without arguments\n /SYSINFO SET <variable>\n";
static char sysinfo_help[] = "SysInfo Usage:\n /SYSINFO [-e|-o] [CLIENT|UI|OS|CPU|RAM|MEMORY|STORAGE|DISK|GPU|VGA|CHIPSET|SOUND|NETWORK|ETHERNET|UPTIME], print various details about your system or print a summary without arguments\n /SYSINFO SET <variable>\n /SYSINFO REFRESH - clear cached hardware information\n";
typedef struct
{
@@ -241,10 +241,15 @@ sysinfo_cb (char *word[], char *word_eol[], void *userdata)
announce = FALSE;
cmd = word[2+offset];
if (!g_ascii_strcasecmp ("SET", cmd))
sysinfo_set_pref (word[3+offset], word_eol[4+offset]);
else if (!cmd || !cmd[0])
if (!cmd || !cmd[0])
print_summary (announce);
else if (!g_ascii_strcasecmp ("REFRESH", cmd))
{
sysinfo_backend_reset_cache ();
zoitechat_print (ph, _("Sysinfo: Hardware cache cleared."));
}
else if (!g_ascii_strcasecmp ("SET", cmd))
sysinfo_set_pref (word[3+offset], word_eol[4+offset]);
else
print_info (cmd, announce);
@@ -269,6 +274,7 @@ zoitechat_plugin_init (zoitechat_plugin *plugin_handle, char **plugin_name, char
int
zoitechat_plugin_deinit (void)
{
sysinfo_backend_reset_cache ();
zoitechat_command (ph, "MENU DEL \"Window/Send System Info\"");
zoitechat_command (ph, "MENU DEL \"Window/Display System Info\"");
zoitechat_printf (ph, _("%s plugin unloaded\n"), name);
+6
View File
@@ -175,6 +175,12 @@ char *sysinfo_backend_get_uptime(void)
return sysinfo_format_uptime (uptime);
}
/* The legacy Unix backend does not cache hardware snapshots. */
void
sysinfo_backend_reset_cache (void)
{
}
char *sysinfo_backend_get_network(void)
{
char ethernet_card[bsize];
+28 -12
View File
@@ -40,11 +40,27 @@ typedef struct
GHashTable *pci_names;
} LinuxStaticSnapshot;
/* Sysinfo callbacks and plugin teardown run on the client thread. */
static LinuxStaticSnapshot snapshot;
static gsize os_initialized = 0;
static gsize cpu_initialized = 0;
static gsize pci_initialized = 0;
static gsize sound_initialized = 0;
static gboolean os_initialized;
static gboolean cpu_initialized;
static gboolean pci_initialized;
static gboolean sound_initialized;
void
sysinfo_backend_reset_cache (void)
{
g_clear_pointer (&snapshot.os, g_free);
g_clear_pointer (&snapshot.cpu, g_free);
g_clear_pointer (&snapshot.gpu, g_free);
g_clear_pointer (&snapshot.chipset, g_free);
g_clear_pointer (&snapshot.sound, g_free);
g_clear_pointer (&snapshot.pci_names, g_hash_table_unref);
os_initialized = FALSE;
cpu_initialized = FALSE;
pci_initialized = FALSE;
sound_initialized = FALSE;
}
static char *read_trimmed_file (const char *path);
static gboolean read_hex_file (const char *path, guint *value);
@@ -642,40 +658,40 @@ build_os_string (void)
static void
ensure_os_snapshot (void)
{
if (g_once_init_enter (&os_initialized))
if (!os_initialized)
{
snapshot.os = build_os_string ();
g_once_init_leave (&os_initialized, 1);
os_initialized = TRUE;
}
}
static void
ensure_cpu_snapshot (void)
{
if (g_once_init_enter (&cpu_initialized))
if (!cpu_initialized)
{
snapshot.cpu = build_cpu_string ();
g_once_init_leave (&cpu_initialized, 1);
cpu_initialized = TRUE;
}
}
static void
ensure_pci_snapshot (void)
{
if (g_once_init_enter (&pci_initialized))
if (!pci_initialized)
{
scan_pci_devices ();
g_once_init_leave (&pci_initialized, 1);
pci_initialized = TRUE;
}
}
static void
ensure_sound_snapshot (void)
{
if (g_once_init_enter (&sound_initialized))
if (!sound_initialized)
{
snapshot.sound = build_sound_string ();
g_once_init_leave (&sound_initialized, 1);
sound_initialized = TRUE;
}
}
+26 -12
View File
@@ -49,11 +49,25 @@ typedef struct
char *sound;
} WinStaticSnapshot;
/* Sysinfo callbacks and plugin teardown run on the client thread. */
static WinStaticSnapshot snapshot;
static gsize os_initialized = 0;
static gsize cpu_initialized = 0;
static gsize gpu_initialized = 0;
static gsize sound_initialized = 0;
static gboolean os_initialized;
static gboolean cpu_initialized;
static gboolean gpu_initialized;
static gboolean sound_initialized;
void
sysinfo_backend_reset_cache (void)
{
g_clear_pointer (&snapshot.os, g_free);
g_clear_pointer (&snapshot.cpu, g_free);
g_clear_pointer (&snapshot.gpu, g_free);
g_clear_pointer (&snapshot.sound, g_free);
os_initialized = FALSE;
cpu_initialized = FALSE;
gpu_initialized = FALSE;
sound_initialized = FALSE;
}
static char *wide_to_utf8 (const WCHAR *value);
static char *read_registry_string (HKEY root, const WCHAR *subkey, const WCHAR *value_name);
@@ -444,40 +458,40 @@ build_sound_string (void)
static void
ensure_os_snapshot (void)
{
if (g_once_init_enter (&os_initialized))
if (!os_initialized)
{
snapshot.os = build_os_string ();
g_once_init_leave (&os_initialized, 1);
os_initialized = TRUE;
}
}
static void
ensure_cpu_snapshot (void)
{
if (g_once_init_enter (&cpu_initialized))
if (!cpu_initialized)
{
snapshot.cpu = build_cpu_string ();
g_once_init_leave (&cpu_initialized, 1);
cpu_initialized = TRUE;
}
}
static void
ensure_gpu_snapshot (void)
{
if (g_once_init_enter (&gpu_initialized))
if (!gpu_initialized)
{
snapshot.gpu = build_gpu_string ();
g_once_init_leave (&gpu_initialized, 1);
gpu_initialized = TRUE;
}
}
static void
ensure_sound_snapshot (void)
{
if (g_once_init_enter (&sound_initialized))
if (!sound_initialized)
{
snapshot.sound = build_sound_string ();
g_once_init_leave (&sound_initialized, 1);
sound_initialized = TRUE;
}
}