source: patches/coreutils-8.20-uname-1.patch@ 3ed95a3

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

Update coreutils patch header information.

  • Property mode set to 100644
File size: 15.0 KB
  • coreutils-8.19

    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
    
    diff -Naur coreutils-8.19.orig/src/uname.c coreutils-8.19/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
  • src/uname.c.orig

    diff -Naur coreutils-8.19.orig/src/uname.c.orig coreutils-8.19/src/uname.c.orig
    old new  
     1/* uname -- print system information
     2
     3   Copyright (C) 1989-2012 Free Software Foundation, Inc.
     4
     5   This program is free software: you can redistribute it and/or modify
     6   it under the terms of the GNU General Public License as published by
     7   the Free Software Foundation, either version 3 of the License, or
     8   (at your option) any later version.
     9
     10   This program is distributed in the hope that it will be useful,
     11   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU General Public License for more details.
     14
     15   You should have received a copy of the GNU General Public License
     16   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     17
     18/* Written by David MacKenzie <djm@gnu.ai.mit.edu> */
     19
     20#include <config.h>
     21#include <stdio.h>
     22#include <sys/types.h>
     23#include <sys/utsname.h>
     24#include <getopt.h>
     25
     26#if HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H
     27# include <sys/systeminfo.h>
     28#endif
     29
     30#if HAVE_SYS_SYSCTL_H
     31# if HAVE_SYS_PARAM_H
     32#  include <sys/param.h> /* needed for OpenBSD 3.0 */
     33# endif
     34# include <sys/sysctl.h>
     35# ifdef HW_MODEL
     36#  ifdef HW_MACHINE_ARCH
     37/* E.g., FreeBSD 4.5, NetBSD 1.5.2 */
     38#   define UNAME_HARDWARE_PLATFORM HW_MODEL
     39#   define UNAME_PROCESSOR HW_MACHINE_ARCH
     40#  else
     41/* E.g., OpenBSD 3.0 */
     42#   define UNAME_PROCESSOR HW_MODEL
     43#  endif
     44# endif
     45#endif
     46
     47#ifdef __APPLE__
     48# include <mach/machine.h>
     49# include <mach-o/arch.h>
     50#endif
     51
     52#include "system.h"
     53#include "error.h"
     54#include "quote.h"
     55#include "uname.h"
     56
     57/* The official name of this program (e.g., no 'g' prefix).  */
     58#define PROGRAM_NAME (uname_mode == UNAME_UNAME ? "uname" : "arch")
     59
     60#define AUTHORS proper_name ("David MacKenzie")
     61#define ARCH_AUTHORS "David MacKenzie", "Karel Zak"
     62
     63/* Values that are bitwise or'd into 'toprint'. */
     64/* Kernel name. */
     65#define PRINT_KERNEL_NAME 1
     66
     67/* Node name on a communications network. */
     68#define PRINT_NODENAME 2
     69
     70/* Kernel release. */
     71#define PRINT_KERNEL_RELEASE 4
     72
     73/* Kernel version. */
     74#define PRINT_KERNEL_VERSION 8
     75
     76/* Machine hardware name. */
     77#define PRINT_MACHINE 16
     78
     79/* Processor type. */
     80#define PRINT_PROCESSOR 32
     81
     82/* Hardware platform.  */
     83#define PRINT_HARDWARE_PLATFORM 64
     84
     85/* Operating system.  */
     86#define PRINT_OPERATING_SYSTEM 128
     87
     88static struct option const uname_long_options[] =
     89{
     90  {"all", no_argument, NULL, 'a'},
     91  {"kernel-name", no_argument, NULL, 's'},
     92  {"sysname", no_argument, NULL, 's'},  /* Obsolescent.  */
     93  {"nodename", no_argument, NULL, 'n'},
     94  {"kernel-release", no_argument, NULL, 'r'},
     95  {"release", no_argument, NULL, 'r'},  /* Obsolescent.  */
     96  {"kernel-version", no_argument, NULL, 'v'},
     97  {"machine", no_argument, NULL, 'm'},
     98  {"processor", no_argument, NULL, 'p'},
     99  {"hardware-platform", no_argument, NULL, 'i'},
     100  {"operating-system", no_argument, NULL, 'o'},
     101  {GETOPT_HELP_OPTION_DECL},
     102  {GETOPT_VERSION_OPTION_DECL},
     103  {NULL, 0, NULL, 0}
     104};
     105
     106static struct option const arch_long_options[] =
     107{
     108  {GETOPT_HELP_OPTION_DECL},
     109  {GETOPT_VERSION_OPTION_DECL},
     110  {NULL, 0, NULL, 0}
     111};
     112
     113void
     114usage (int status)
     115{
     116  if (status != EXIT_SUCCESS)
     117    emit_try_help ();
     118  else
     119    {
     120      printf (_("Usage: %s [OPTION]...\n"), program_name);
     121
     122      if (uname_mode == UNAME_UNAME)
     123        {
     124          fputs (_("\
     125Print certain system information.  With no OPTION, same as -s.\n\
     126\n\
     127  -a, --all                print all information, in the following order,\n\
     128                             except omit -p and -i if unknown:\n\
     129  -s, --kernel-name        print the kernel name\n\
     130  -n, --nodename           print the network node hostname\n\
     131  -r, --kernel-release     print the kernel release\n\
     132"), stdout);
     133          fputs (_("\
     134  -v, --kernel-version     print the kernel version\n\
     135  -m, --machine            print the machine hardware name\n\
     136  -p, --processor          print the processor type or \"unknown\"\n\
     137  -i, --hardware-platform  print the hardware platform or \"unknown\"\n\
     138  -o, --operating-system   print the operating system\n\
     139"), stdout);
     140        }
     141      else
     142        {
     143          fputs (_("\
     144Print machine architecture.\n\
     145\n\
     146"), stdout);
     147        }
     148
     149      fputs (HELP_OPTION_DESCRIPTION, stdout);
     150      fputs (VERSION_OPTION_DESCRIPTION, stdout);
     151      emit_ancillary_info ();
     152    }
     153  exit (status);
     154}
     155
     156/* Print ELEMENT, preceded by a space if something has already been
     157   printed.  */
     158
     159static void
     160print_element (char const *element)
     161{
     162  static bool printed;
     163  if (printed)
     164    putchar (' ');
     165  printed = true;
     166  fputs (element, stdout);
     167}
     168
     169
     170/* Set all the option flags according to the switches specified.
     171   Return the mask indicating which elements to print.  */
     172
     173static int
     174decode_switches (int argc, char **argv)
     175{
     176  int c;
     177  unsigned int toprint = 0;
     178
     179  if (uname_mode == UNAME_ARCH)
     180    {
     181      while ((c = getopt_long (argc, argv, "",
     182                               arch_long_options, NULL)) != -1)
     183        {
     184          switch (c)
     185            {
     186            case_GETOPT_HELP_CHAR;
     187
     188            case_GETOPT_VERSION_CHAR (PROGRAM_NAME, ARCH_AUTHORS);
     189
     190            default:
     191              usage (EXIT_FAILURE);
     192            }
     193        }
     194      toprint = PRINT_MACHINE;
     195    }
     196  else
     197    {
     198      while ((c = getopt_long (argc, argv, "asnrvmpio",
     199                               uname_long_options, NULL)) != -1)
     200        {
     201          switch (c)
     202            {
     203            case 'a':
     204              toprint = UINT_MAX;
     205              break;
     206
     207            case 's':
     208              toprint |= PRINT_KERNEL_NAME;
     209              break;
     210
     211            case 'n':
     212              toprint |= PRINT_NODENAME;
     213              break;
     214
     215            case 'r':
     216              toprint |= PRINT_KERNEL_RELEASE;
     217              break;
     218
     219            case 'v':
     220              toprint |= PRINT_KERNEL_VERSION;
     221              break;
     222
     223            case 'm':
     224              toprint |= PRINT_MACHINE;
     225              break;
     226
     227            case 'p':
     228              toprint |= PRINT_PROCESSOR;
     229              break;
     230
     231            case 'i':
     232              toprint |= PRINT_HARDWARE_PLATFORM;
     233              break;
     234
     235            case 'o':
     236              toprint |= PRINT_OPERATING_SYSTEM;
     237              break;
     238
     239            case_GETOPT_HELP_CHAR;
     240
     241            case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
     242
     243            default:
     244              usage (EXIT_FAILURE);
     245            }
     246        }
     247    }
     248
     249  if (argc != optind)
     250    {
     251      error (0, 0, _("extra operand %s"), quote (argv[optind]));
     252      usage (EXIT_FAILURE);
     253    }
     254
     255  return toprint;
     256}
     257
     258int
     259main (int argc, char **argv)
     260{
     261  static char const unknown[] = "unknown";
     262
     263  /* Mask indicating which elements to print. */
     264  unsigned int toprint = 0;
     265
     266  initialize_main (&argc, &argv);
     267  set_program_name (argv[0]);
     268  setlocale (LC_ALL, "");
     269  bindtextdomain (PACKAGE, LOCALEDIR);
     270  textdomain (PACKAGE);
     271
     272  atexit (close_stdout);
     273
     274  toprint = decode_switches (argc, argv);
     275
     276  if (toprint == 0)
     277    toprint = PRINT_KERNEL_NAME;
     278
     279  if (toprint
     280       & (PRINT_KERNEL_NAME | PRINT_NODENAME | PRINT_KERNEL_RELEASE
     281          | PRINT_KERNEL_VERSION | PRINT_MACHINE))
     282    {
     283      struct utsname name;
     284
     285      if (uname (&name) == -1)
     286        error (EXIT_FAILURE, errno, _("cannot get system name"));
     287
     288      if (toprint & PRINT_KERNEL_NAME)
     289        print_element (name.sysname);
     290      if (toprint & PRINT_NODENAME)
     291        print_element (name.nodename);
     292      if (toprint & PRINT_KERNEL_RELEASE)
     293        print_element (name.release);
     294      if (toprint & PRINT_KERNEL_VERSION)
     295        print_element (name.version);
     296      if (toprint & PRINT_MACHINE)
     297        print_element (name.machine);
     298    }
     299
     300  if (toprint & PRINT_PROCESSOR)
     301    {
     302      char const *element = unknown;
     303#if HAVE_SYSINFO && defined SI_ARCHITECTURE
     304      {
     305        static char processor[257];
     306        if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
     307          element = processor;
     308      }
     309#endif
     310#ifdef UNAME_PROCESSOR
     311      if (element == unknown)
     312        {
     313          static char processor[257];
     314          size_t s = sizeof processor;
     315          static int mib[] = { CTL_HW, UNAME_PROCESSOR };
     316          if (sysctl (mib, 2, processor, &s, 0, 0) >= 0)
     317            element = processor;
     318
     319# ifdef __APPLE__
     320          /* This kludge works around a bug in Mac OS X.  */
     321          if (element == unknown)
     322            {
     323              cpu_type_t cputype;
     324              size_t s = sizeof cputype;
     325              NXArchInfo const *ai;
     326              if (sysctlbyname ("hw.cputype", &cputype, &s, NULL, 0) == 0
     327                  && (ai = NXGetArchInfoFromCpuType (cputype,
     328                                                     CPU_SUBTYPE_MULTIPLE))
     329                  != NULL)
     330                element = ai->name;
     331
     332              /* Hack "safely" around the ppc vs. powerpc return value. */
     333              if (cputype == CPU_TYPE_POWERPC
     334                  && STRNCMP_LIT (element, "ppc") == 0)
     335                element = "powerpc";
     336            }
     337# endif
     338        }
     339#endif
     340      if (! (toprint == UINT_MAX && element == unknown))
     341        print_element (element);
     342    }
     343
     344  if (toprint & PRINT_HARDWARE_PLATFORM)
     345    {
     346      char const *element = unknown;
     347#if HAVE_SYSINFO && defined SI_PLATFORM
     348      {
     349        static char hardware_platform[257];
     350        if (0 <= sysinfo (SI_PLATFORM,
     351                          hardware_platform, sizeof hardware_platform))
     352          element = hardware_platform;
     353      }
     354#endif
     355#ifdef UNAME_HARDWARE_PLATFORM
     356      if (element == unknown)
     357        {
     358          static char hardware_platform[257];
     359          size_t s = sizeof hardware_platform;
     360          static int mib[] = { CTL_HW, UNAME_HARDWARE_PLATFORM };
     361          if (sysctl (mib, 2, hardware_platform, &s, 0, 0) >= 0)
     362            element = hardware_platform;
     363        }
     364#endif
     365      if (! (toprint == UINT_MAX && element == unknown))
     366        print_element (element);
     367    }
     368
     369  if (toprint & PRINT_OPERATING_SYSTEM)
     370    print_element (HOST_OPERATING_SYSTEM);
     371
     372  putchar ('\n');
     373
     374  exit (EXIT_SUCCESS);
     375}
Note: See TracBrowser for help on using the repository browser.