[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
uname -p is broken
From: |
J. Grant |
Subject: |
uname -p is broken |
Date: |
Wed, 13 Feb 2002 18:06:17 +0900 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011226 |
Hello
Are you aware that uname -a gives incorrect output? or rather missing
the -p, --processor print the host processor type feature?
I just did a search and it happens that some one has made a patch for
linux. maybe you can apply this patch and fix this feature?
JG
$ uname -a
Linux np850.tk.hm.rd.sanyo.co.jp 2.4.8-26mdk #1 Sun Sep 23 17:06:39 CEST
2001 i686 unknown
address@hidden jg]$ uname -p
unknown
*** uname.c Sat Dec 16 01:22:57 2000
--- uname.c Fri Dec 15 23:01:08 2000
***************
*** 112,124 ****
exit (status);
}
int
main (int argc, char **argv)
{
struct utsname name;
int c;
char processor[256];
!
program_name = argv[0];
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
--- 112,236 ----
exit (status);
}
+ /* Hack to get processor model name from /proc/cpuinfo on linux machines */
+
+ /* szChoices holds the list of strings you want to look for. */
+ char* szChoices[] =
+ {
+ "model name",
+ "cpu\t\t:"
+ };
+ int nChoices = sizeof(szChoices)/sizeof(char*);
+
+
+ int
+ linux_get_processor(char* processor)
+ {
+ FILE* fd;
+ char buff[256];
+ char* buffwalk;
+ int i = 0;
+ char** szStrings = NULL;
+
+ szStrings = (char**)(malloc(nChoices));
+
+ if (szStrings == NULL)
+ return 0;
+
+ for (i = 0; i < nChoices; i++)
+ szStrings[i] = NULL;
+
+ fd = fopen("/proc/cpuinfo", "r");
+
+ if (!fd)
+ goto LocalError;
+
+ while (!feof(fd))
+ {
+ if (!fgets(buff, 256, fd))
+ break;
+
+ for (i = 0; i < nChoices; i++)
+ {
+ if (!strncmp(buff, szChoices[i], strlen(szChoices[i]))
+ && szStrings[i] == NULL)
+ {
+ szStrings[i] = (char*)(malloc(strlen(buff) + 1));
+
+ if (szStrings[i] == NULL)
+ {
+ fclose(fd);
+ goto LocalError;
+ }
+
+ strncpy(szStrings[i], buff, strlen(buff));
+ }
+ }
+ }
+
+ for(i = 0; i < nChoices; i++)
+ if (szStrings[i] != NULL)
+ break;
+
+ if (i == nChoices)
+ {
+ fclose(fd);
+ goto LocalError;
+ }
+
+ buffwalk = szStrings[i];
+ while (*buffwalk != ':' && *buffwalk != '\0')
+ buffwalk++;
+
+ if (*buffwalk == '\0')
+ {
+ fclose(fd);
+ goto LocalError;
+ }
+
+ /* get past the ':' and the following space */
+ buffwalk += 2;
+
+ /* now copy the resulting string into *processor */
+ strncpy(processor, buffwalk, strlen(buffwalk) + 1);
+
+ buffwalk = processor;
+ while (*buffwalk != '\n' && *buffwalk != '\0')
+ buffwalk++;
+
+ *buffwalk = '\0';
+
+ /* sanity check */
+ buffwalk = NULL;
+
+ for (i = 0; i < nChoices; i++)
+ {
+ if (szStrings[i])
+ free(szStrings[i]);
+ }
+ free(szStrings);
+
+ fclose(fd);
+ return 1;
+
+ LocalError:
+ for (i = 0; i < nChoices; i++)
+ {
+ if (szStrings[i])
+ free(szStrings[i]);
+ }
+ free(szStrings);
+
+ return 0;
+ }
+
int
main (int argc, char **argv)
{
struct utsname name;
int c;
char processor[256];
!
program_name = argv[0];
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
***************
*** 184,190 ****
if (sysinfo (SI_ARCHITECTURE, processor, sizeof (processor)) == -1)
error (1, errno, _("cannot get processor type"));
#else
! strcpy (processor, "unknown");
#endif
print_element (PRINT_SYSNAME, name.sysname);
--- 296,311 ----
if (sysinfo (SI_ARCHITECTURE, processor, sizeof (processor)) == -1)
error (1, errno, _("cannot get processor type"));
#else
! /* If this is a linux machine and does not have SI_ARCHITECTURE, then try
! * to get processor from /proc/cpuinfo
! */
! if (!strncmp(name.sysname, "Linux", strlen("Linux")))
! {
! if (!linux_get_processor(processor))
! strcpy(processor, "unknown");
! }
! else
! strcpy (processor, "unknown");
#endif
print_element (PRINT_SYSNAME, name.sysname);
- uname -p is broken,
J. Grant <=