source: patches/coreutils-6.12-uname-1.patch@ 4254ff10

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 4254ff10 was 7b31c44, checked in by Joe Ciccone <jciccone@…>, 16 years ago

Updated Coreutils to 6.12.
Drop Mktemp in favor of the version included in Coreutils.
Updated Perl to 5.10.0.
Updated File to 4.25.
Updated File to 4.26.
Updated GCC to 4.3.2.

  • Property mode set to 100644
File size: 4.2 KB
  • coreutils-6.12

    Submitted By: Jim Gifford <jim at linuxfromscratch dot org>
    Date: 2006-08-24
    Initial Package Version: 5.97
            Rediffed against 6.12 by Joe Ciccone on 2008-08-30
    Upstream Status: Not Accepted
    Origin: Gentoo - http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/coreutils
    Description: Display CPU Information from /proc/cpuinfo or /proc/sysinfo
    
    Original Patch by - Matthew Burgess and Scot McPherson
    
    diff -Naur coreutils-6.12.orig/src/uname.c coreutils-6.12/src/uname.c
    old new  
    5050# include <mach-o/arch.h>
    5151#endif
    5252
     53#if defined (__linux__)
     54# define USE_PROCINFO
     55# define UNAME_HARDWARE_PLATFORM
     56#endif
     57
    5358#include "system.h"
    5459#include "error.h"
    5560#include "quote.h"
     
    158163  exit (status);
    159164}
    160165
     166#if defined(USE_PROCINFO)
     167
     168# if defined(__s390__) || defined(__s390x__)
     169#  define CPUINFO_FILE    "/proc/sysinfo"
     170#  define CPUINFO_FORMAT  "%64[^\t :]%*[ :]%256[^\n]%c"
     171# else
     172#  define CPUINFO_FILE    "/proc/cpuinfo"
     173#  define CPUINFO_FORMAT  "%64[^\t:]\t:%256[^\n]%c"
     174# endif
     175
     176# define PROCINFO_PROCESSOR      0
     177# define PROCINFO_HARDWARE_PLATFORM 1
     178
     179static void __eat_cpuinfo_space(char *buf)
     180{
     181        /* first eat trailing space */
     182        char *tmp = buf + strlen(buf) - 1;
     183        while (tmp > buf && isspace(*tmp))
     184                *tmp-- = '\0';
     185        /* then eat leading space */
     186        tmp = buf;
     187        while (*tmp && isspace(*tmp))
     188                tmp++;
     189        if (tmp != buf)
     190                memmove(buf, tmp, strlen(tmp)+1);
     191}
     192
     193static int __linux_procinfo (int x, char *fstr, size_t s)
     194{
     195        FILE *fp;
     196
     197        char *procinfo_keys[] = {
     198                /* --processor --hardware-platform */
     199                #if defined(__alpha__)
     200                        "cpu model", "system type"
     201                #elif defined(__arm__)
     202                        "Processor", "Hardware"
     203                #elif defined(bfin)
     204                        "CPU", "BOARD Name"
     205                #elif defined(__cris__)
     206                        "cpu", "cpu model"
     207                #elif defined(__frv__)
     208                        "CPU-Core", "System"
     209                #elif defined(__i386__) || defined(__x86_64__)
     210                        "model name", "vendor_id"
     211                #elif defined(__ia64__)
     212                        "family", "vendor"
     213                #elif defined(__hppa__)
     214                        "cpu", "model"
     215                #elif defined(__m68k__)
     216                        "CPU", "MMU"
     217                #elif defined(__mips__)
     218                        "cpu model", "system type"
     219                #elif defined(__powerpc__) || defined(__powerpc64__)
     220                        "cpu", "machine"
     221                #elif defined(__s390__) || defined(__s390x__)
     222                        "Type", "Manufacturer"
     223                #elif defined(__sh__)
     224                        "cpu type", "machine"
     225                #elif defined(sparc) || defined(__sparc__)
     226                        "type", "cpu"
     227                #elif defined(__vax__)
     228                        "cpu type", "cpu"
     229                #else
     230                        "unknown", "unknown"
     231                #endif
     232        };
     233
     234        if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
     235                char key[65], value[257], eol, *ret = NULL;
     236
     237                while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
     238                        __eat_cpuinfo_space(key);
     239                        if (!strcmp(key, procinfo_keys[x])) {
     240                                __eat_cpuinfo_space(value);
     241                                ret = value;
     242                                break;
     243                        }
     244                        if (eol != '\n') {
     245                                /* we need two fscanf's here in case the previous
     246                                 * length limit caused us to read right up to the
     247                                 * newline ... doing "%*[^\n]\n" wont eat the newline
     248                                 */
     249                                fscanf(fp, "%*[^\n]");
     250                                fscanf(fp, "\n");
     251                        }
     252                }
     253                fclose(fp);
     254
     255                if (ret) {
     256                        strncpy(fstr, ret, s);
     257                        return 0;
     258                }
     259        }
     260
     261        return -1;
     262}
     263
     264#endif
     265
    161266/* Print ELEMENT, preceded by a space if something has already been
    162267   printed.  */
    163268
     
    305410  if (toprint & PRINT_PROCESSOR)
    306411    {
    307412      char const *element = unknown;
    308 #if HAVE_SYSINFO && defined SI_ARCHITECTURE
     413#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
    309414      {
    310415        static char processor[257];
     416#if defined(USE_PROCINFO)
     417        if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor))
     418#else
    311419        if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
     420#endif
    312421          element = processor;
    313422      }
    314423#endif
     
    361470      if (element == unknown)
    362471        {
    363472          static char hardware_platform[257];
     473#if defined(USE_PROCINFO)
     474          if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
     475#else
    364476          size_t s = sizeof hardware_platform;
    365477          static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
    366478          if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
     479#endif
    367480            element = hardware_platform;
    368481        }
    369482#endif
Note: See TracBrowser for help on using the repository browser.