source: patches/coreutils-8.21-uname-1.patch@ ce56d9d

clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since ce56d9d was 7718031, checked in by William Harrington <kb0iic@…>, 12 years ago

Update coreutils uname patch.

  • Property mode set to 100644
File size: 4.8 KB
  • coreutils-8.21

    Submitted By: Jim Gifford <jim at cross-lfs dot org>
    Date: 2010-07-26
    Initial Package Version: 5.97
    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
    
    Rediffed for 7.1 by Jim Gifford
    Rediffed for 7.5 by Jim Gifford
    Rediffed for 8.4 by Joe Ciccone
    Rediffed for 8.9 by Joe Ciccone
    Rediffed for 8.16 by Jonathan Norman - 2012-06-10
    Rediffed for 8.19 by William Harrington - 2012-08-27
    Renamed for 8.20 by William Harrington - 2012-11-01
    Rediffed for 8.21 by William Harrington 2013-05-31
    
    diff -Naur coreutils-8.21.orig/src/uname.c coreutils-8.21/src/uname.c
    old new  
    4949# include <mach-o/arch.h>
    5050#endif
    5151
     52#if defined (__linux__)
     53# define USE_PROCINFO
     54# define UNAME_HARDWARE_PLATFORM
     55#endif
     56
    5257#include "system.h"
    5358#include "error.h"
    5459#include "quote.h"
     
    153158  exit (status);
    154159}
    155160
     161#if defined(USE_PROCINFO)
     162
     163# if defined(__s390__) || defined(__s390x__)
     164#  define CPUINFO_FILE    "/proc/sysinfo"
     165#  define CPUINFO_FORMAT  "%64[^\t :]%*[ :]%256[^\n]%c"
     166# else
     167#  define CPUINFO_FILE    "/proc/cpuinfo"
     168#  define CPUINFO_FORMAT  "%64[^\t:]\t:%256[^\n]%c"
     169# endif
     170
     171# define PROCINFO_PROCESSOR      0
     172# define PROCINFO_HARDWARE_PLATFORM 1
     173
     174static void __eat_cpuinfo_space(char *buf)
     175{
     176        /* first eat trailing space */
     177        char *tmp = buf + strlen(buf) - 1;
     178        while (tmp > buf && isspace(*tmp))
     179                *tmp-- = '\0';
     180        /* then eat leading space */
     181        tmp = buf;
     182        while (*tmp && isspace(*tmp))
     183                tmp++;
     184        if (tmp != buf)
     185                memmove(buf, tmp, strlen(tmp)+1);
     186        /* finally collapse whitespace */
     187        tmp = buf;
     188        while (tmp[0] && tmp[1]) {
     189                if (isspace(tmp[0]) && isspace(tmp[1])) {
     190                        memmove(tmp, tmp+1, strlen(tmp));
     191                        continue;
     192                }
     193                ++tmp;
     194        }
     195}
     196
     197static int __linux_procinfo (int x, char *fstr, size_t s)
     198{
     199        FILE *fp;
     200
     201        char *procinfo_keys[] = {
     202                /* --processor --hardware-platform */
     203                #if defined(__alpha__)
     204                        "cpu model", "system type"
     205                #elif defined(__arm__)
     206                        "Processor", "Hardware"
     207                #elif defined(__avr32__)
     208                        "processor", "cpu family"
     209                #elif defined(__bfin__)
     210                        "CPU", "BOARD Name"
     211                #elif defined(__cris__)
     212                        "cpu", "cpu model"
     213                #elif defined(__frv__)
     214                        "CPU-Core", "System"
     215                #elif defined(__i386__) || defined(__x86_64__)
     216                        "model name", "vendor_id"
     217                #elif defined(__ia64__)
     218                        "family", "vendor"
     219                #elif defined(__hppa__)
     220                        "cpu", "model"
     221                #elif defined(__m68k__)
     222                        "CPU", "MMU"
     223                #elif defined(__mips__)
     224                        "cpu model", "system type"
     225                #elif defined(__powerpc__) || defined(__powerpc64__)
     226                        "cpu", "machine"
     227                #elif defined(__s390__) || defined(__s390x__)
     228                        "Type", "Manufacturer"
     229                #elif defined(__sh__)
     230                        "cpu type", "machine"
     231                #elif defined(sparc) || defined(__sparc__)
     232                        "type", "cpu"
     233                #elif defined(__vax__)
     234                        "cpu type", "cpu"
     235                #else
     236                        "unknown", "unknown"
     237                #endif
     238        };
     239
     240        if ((fp = fopen(CPUINFO_FILE, "r")) != NULL) {
     241                char key[65], value[257], eol, *ret = NULL;
     242
     243                while (fscanf(fp, CPUINFO_FORMAT, key, value, &eol) != EOF) {
     244                        __eat_cpuinfo_space(key);
     245                        if (!strcmp(key, procinfo_keys[x])) {
     246                                __eat_cpuinfo_space(value);
     247                                ret = value;
     248                                break;
     249                        }
     250                        if (eol != '\n') {
     251                                /* we need two fscanf's here in case the previous
     252                                 * length limit caused us to read right up to the
     253                                 * newline ... doing "%*[^\n]\n" wont eat the newline
     254                                 */
     255                                fscanf(fp, "%*[^\n]");
     256                                fscanf(fp, "\n");
     257                        }
     258                }
     259                fclose(fp);
     260
     261                if (ret) {
     262                        strncpy(fstr, ret, s);
     263                        return 0;
     264                }
     265        }
     266
     267        return -1;
     268}
     269
     270#endif
     271
    156272/* Print ELEMENT, preceded by a space if something has already been
    157273   printed.  */
    158274
     
    300416  if (toprint & PRINT_PROCESSOR)
    301417    {
    302418      char const *element = unknown;
    303 #if HAVE_SYSINFO && defined SI_ARCHITECTURE
     419#if ( HAVE_SYSINFO && defined SI_ARCHITECTURE ) || defined(USE_PROCINFO)
    304420      {
    305421        static char processor[257];
     422#if defined(USE_PROCINFO)
     423        if (0 <= __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof processor))
     424#else
    306425        if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
     426#endif
    307427          element = processor;
    308428      }
    309429#endif
     
    356476      if (element == unknown)
    357477        {
    358478          static char hardware_platform[257];
     479#if defined(USE_PROCINFO)
     480        if (0 <= __linux_procinfo (PROCINFO_HARDWARE_PLATFORM, hardware_platform, sizeof hardware_platform))
     481#else
    359482          size_t s = sizeof hardware_platform;
    360483          static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
    361484          if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
     485#endif
    362486            element = hardware_platform;
    363487        }
    364488#endif
Note: See TracBrowser for help on using the repository browser.