2022-04-18 21:58:04 +02:00
|
|
|
--- ./src/uname.c.orig 2022-04-08 06:22:18.000000000 -0500
|
|
|
|
+++ ./src/uname.c 2022-04-17 13:30:46.550023254 -0500
|
|
|
|
@@ -44,6 +44,11 @@
|
|
|
|
# endif
|
2009-08-26 17:00:38 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
+#if defined (__linux__)
|
|
|
|
+# define USE_PROCINFO
|
|
|
|
+# define UNAME_HARDWARE_PLATFORM
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
#include "system.h"
|
2022-04-18 21:58:04 +02:00
|
|
|
#include "die.h"
|
2009-08-26 17:00:38 +02:00
|
|
|
#include "error.h"
|
2022-04-18 21:58:04 +02:00
|
|
|
@@ -149,6 +154,106 @@
|
2009-08-26 17:00:38 +02:00
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
+#if defined(USE_PROCINFO)
|
|
|
|
+
|
|
|
|
+# if defined(__s390__) || defined(__s390x__)
|
|
|
|
+# define CPUINFO_FILE "/proc/sysinfo"
|
|
|
|
+# define CPUINFO_FORMAT "%64[^\t :]%*[ :]%256[^\n]%c"
|
|
|
|
+# else
|
|
|
|
+# define CPUINFO_FILE "/proc/cpuinfo"
|
|
|
|
+# define CPUINFO_FORMAT "%64[^\t:]\t:%256[^\n]%c"
|
|
|
|
+# endif
|
|
|
|
+
|
|
|
|
+# define PROCINFO_PROCESSOR 0
|
|
|
|
+# define PROCINFO_HARDWARE_PLATFORM 1
|
|
|
|
+
|
|
|
|
+static void __eat_cpuinfo_space(char *buf)
|
|
|
|
+{
|
2010-05-19 10:58:23 +02:00
|
|
|
+ /* first eat trailing space */
|
|
|
|
+ char *tmp = buf + strlen(buf) - 1;
|
|
|
|
+ while (tmp > buf && isspace(*tmp))
|
|
|
|
+ *tmp-- = '\0';
|
|
|
|
+ /* then eat leading space */
|
|
|
|
+ tmp = buf;
|
|
|
|
+ while (*tmp && isspace(*tmp))
|
|
|
|
+ tmp++;
|
|
|
|
+ if (tmp != buf)
|
|
|
|
+ memmove(buf, tmp, strlen(tmp)+1);
|
2009-08-26 17:00:38 +02:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int __linux_procinfo (int x, char *fstr, size_t s)
|
|
|
|
+{
|
2010-05-19 10:58:23 +02:00
|
|
|
+ FILE *fp;
|
2009-08-26 17:00:38 +02:00
|
|
|
+
|
2010-05-19 10:58:23 +02:00
|
|
|
+ char *procinfo_keys[] = {
|
|
|
|
+ /* --processor --hardware-platform */
|
|
|
|
+ #if defined(__alpha__)
|
|
|
|
+ "cpu model", "system type"
|
|
|
|
+ #elif defined(__arm__)
|
|
|
|
+ "Processor", "Hardware"
|
|
|
|
+ #elif defined(bfin)
|
|
|
|
+ "CPU", "BOARD Name"
|
|
|
|
+ #elif defined(__cris__)
|
|
|
|
+ "cpu", "cpu model"
|
|
|
|
+ #elif defined(__frv__)
|
|
|
|
+ "CPU-Core", "System"
|
|
|
|
+ #elif defined(__i386__) || defined(__x86_64__)
|
|
|
|
+ "model name", "vendor_id"
|
|
|
|
+ #elif defined(__ia64__)
|
|
|
|
+ "family", "vendor"
|
|
|
|
+ #elif defined(__hppa__)
|
|
|
|
+ "cpu", "model"
|
|
|
|
+ #elif defined(__m68k__)
|
|
|
|
+ "CPU", "MMU"
|
|
|
|
+ #elif defined(__mips__)
|
|
|
|
+ "cpu model", "system type"
|
|
|
|
+ #elif defined(__powerpc__) || defined(__powerpc64__)
|
|
|
|
+ "cpu", "machine"
|
|
|
|
+ #elif defined(__s390__) || defined(__s390x__)
|
|
|
|
+ "Type", "Manufacturer"
|
|
|
|
+ #elif defined(__sh__)
|
|
|
|
+ "cpu type", "machine"
|
|
|
|
+ #elif defined(sparc) || defined(__sparc__)
|
|
|
|
+ "type", "cpu"
|
|
|
|
+ #elif defined(__vax__)
|
|
|
|
+ "cpu type", "cpu"
|
|
|
|
+ #else
|
|
|
|
+ "unknown", "unknown"
|
|
|
|
+ #endif
|
|
|
|
+ };
|
2009-08-26 17:00:38 +02:00
|
|
|
+
|
2010-05-19 10:58:23 +02:00
|
|
|
+ if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
|
|
|
|
+ char key[65], value[257], eol, *ret = NULL;
|
2009-08-26 17:00:38 +02:00
|
|
|
+
|
2010-05-19 10:58:23 +02:00
|
|
|
+ while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
|
|
|
|
+ __eat_cpuinfo_space(key);
|
|
|
|
+ if (!strcmp(key, procinfo_keys[x])) {
|
|
|
|
+ __eat_cpuinfo_space(value);
|
|
|
|
+ ret = value;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (eol != '\n') {
|
|
|
|
+ /* we need two fscanf's here in case the previous
|
|
|
|
+ * length limit caused us to read right up to the
|
|
|
|
+ * newline ... doing "%*[^\n]\n" wont eat the newline
|
|
|
|
+ */
|
|
|
|
+ fscanf(fp, "%*[^\n]");
|
|
|
|
+ fscanf(fp, "\n");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ fclose(fp);
|
2009-08-26 17:00:38 +02:00
|
|
|
+
|
2010-05-19 10:58:23 +02:00
|
|
|
+ if (ret) {
|
|
|
|
+ strncpy(fstr, ret, s);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
2009-08-26 17:00:38 +02:00
|
|
|
+
|
2010-05-19 10:58:23 +02:00
|
|
|
+ return -1;
|
2009-08-26 17:00:38 +02:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* Print ELEMENT, preceded by a space if something has already been
|
|
|
|
printed. */
|
|
|
|
|
2022-04-18 21:58:04 +02:00
|
|
|
@@ -323,11 +428,16 @@
|
|
|
|
element = "powerpc";
|
|
|
|
# endif
|
|
|
|
#endif
|
2009-08-26 17:00:38 +02:00
|
|
|
-#if HAVE_SYSINFO && defined SI_ARCHITECTURE
|
|
|
|
+#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
|
2022-04-18 21:58:04 +02:00
|
|
|
if (element == unknown)
|
|
|
|
{
|
|
|
|
static char processor[257];
|
2009-08-26 17:00:38 +02:00
|
|
|
+#if defined(USE_PROCINFO)
|
2022-04-18 21:58:04 +02:00
|
|
|
+ if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor))
|
2009-08-26 17:00:38 +02:00
|
|
|
+#else
|
2022-04-18 21:58:04 +02:00
|
|
|
+
|
|
|
|
if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
|
2009-08-26 17:00:38 +02:00
|
|
|
+#endif
|
2022-04-18 21:58:04 +02:00
|
|
|
element = processor;
|
|
|
|
}
|
2009-08-26 17:00:38 +02:00
|
|
|
#endif
|
2022-04-18 21:58:04 +02:00
|
|
|
@@ -360,9 +470,13 @@
|
2009-08-26 17:00:38 +02:00
|
|
|
if (element == unknown)
|
2010-05-19 10:58:23 +02:00
|
|
|
{
|
|
|
|
static char hardware_platform[257];
|
2009-08-26 17:00:38 +02:00
|
|
|
+#if defined(USE_PROCINFO)
|
2010-05-19 10:58:23 +02:00
|
|
|
+ if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
|
2009-08-26 17:00:38 +02:00
|
|
|
+#else
|
2010-05-19 10:58:23 +02:00
|
|
|
size_t s = sizeof hardware_platform;
|
|
|
|
static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
|
|
|
|
if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
|
2009-08-26 17:00:38 +02:00
|
|
|
+#endif
|
2010-05-19 10:58:23 +02:00
|
|
|
element = hardware_platform;
|
|
|
|
}
|
2009-08-26 17:00:38 +02:00
|
|
|
#endif
|