Karel Zak <[EMAIL PROTECTED]> wrote: > * src/uname-arch.c: New program, alias for "uname -m". > * src/uname-uname.c: New file, default uname mode. > * src/uname.h: New file, uname modes. > * src/Makefile.am (EXTRA_PROGRAMS): Add arch. > (uname_SOURCES, arch_SOURCES): Define. > * README: Add arch to the list of programs. > * AUTHORS: Add arch. > * man/arch.x: New file. > * man/Makefile.am (dist_man_MANS): Add arch.1. > (arch.1): New dependency. > * tests/misc/arch: New test, compare "arch" with "uname -m"
Thanks for doing all that. I've made some additional changes: - update NEWS - fix coreutils.texi typo, caught by James Youngman - configure.ac: arrange to build "arch" whenever uname is built. Otherwise, "arch" wasn't built at all, by default. - allow "make distcheck" to pass, by exempting uname-arch.c and uname-uname.c from the always-include-<config.h> rule. - complete ChangeLog - uname.c: adjust wrt AUTHORS/ARCH_AUTHORS - documentation: call it "hardware machine name", not "machine architecture", to be consistent with uname's terminology. FYI, terminology here is not pretty. For reference, the Linux <sys/utsname.h> describes the corresponding "machine" member like this: /* Name of the hardware type the system is running on. */ char machine[_UTSNAME_MACHINE_LENGTH]; Now that I've stopped working on this for today, I realize that we probably need to add a sentence or two of portability advice. Given that uname -m and "arch" are equivalent, I suppose arch should not be used in new scripts, but that's just a gut feeling. If so, documentation should make it clear. For reference, Solaris' uname man page says this about -m: -m Prints the machine hardware name (class). Use of this option is discouraged. Use uname -p instead. See NOTES section below. -p Prints the current host's ISA or processor type. But they can do that solely because their -p option works (which is because Solaris provides a way to get the processor type from the kernel: "sysinfo (SI_ARCHITECTURE,...". As you all know, on Linux, GNU uname -p always prints "unknown" because there isn't a syscall to get the required string. One reason parsing /proc/cpuinfo is not an option is because there is so much variation. Feedback welcome. --------------------------------------------- Here's the current state of the patch (not yet published): New program: arch * NEWS: Mention arch. * README: Add arch to the list of programs. * AUTHORS: Add arch. * src/uname.c: Include "uname.h". (PROGRAM_NAME): Handle arch, too. (ARCH_AUTHORS): Define. (uname_long_options, arch_long_options): Renamed and new globals. (usage): Handle arch-mode as well as uname-mode. (decode_switches): New function, extracted from main, to handle arch-mode as well as uname-mode. (main): Handle both modes. * src/uname-arch.c: New program, alias for "uname -m". * src/uname-uname.c: New file, default uname mode. * src/uname.h: New file, uname modes. * src/Makefile.am (EXTRA_PROGRAMS): Add arch. (uname_SOURCES, arch_SOURCES): Define. * man/arch.x: New file. * man/Makefile.am (dist_man_MANS): Add arch.1. (arch.1): New dependency. * tests/misc/arch: New test, compare "arch" with "uname -m" * configure.ac (OPTIONAL_BIN_PROGS): Add arch. (MAN): Add arch.1. * .x-sc_require_config_h: Exempt uname-arch.c and uname-uname.c from the always-include-<config.h> rule. Signed-off-by: Karel Zak <[EMAIL PROTECTED]> Signed-off-by: Jim Meyering <[EMAIL PROTECTED]> --- .x-sc_require_config_h | 2 + AUTHORS | 1 + ChangeLog | 28 +++++++++ NEWS | 4 + README | 2 +- configure.ac | 4 +- doc/coreutils.texi | 23 +++++++ man/Makefile.am | 5 +- man/arch.x | 6 ++ man/uname.x | 2 +- src/Makefile.am | 9 ++- src/uname-arch.c | 2 + src/uname-uname.c | 2 + src/uname.c | 158 ++++++++++++++++++++++++++++++++--------------- src/uname.h | 7 ++ tests/misc/arch | 48 +++++++++++++++ 16 files changed, 245 insertions(+), 58 deletions(-) create mode 100644 man/arch.x create mode 100644 src/uname-arch.c create mode 100644 src/uname-uname.c create mode 100644 src/uname.h create mode 100755 tests/misc/arch diff --git a/.x-sc_require_config_h b/.x-sc_require_config_h index 415a113..fe8bde1 100644 --- a/.x-sc_require_config_h +++ b/.x-sc_require_config_h @@ -26,3 +26,5 @@ ^src/ls-vdir\.c$ ^src/rand-isaac\.c$ ^src/tac-pipe\.c$ +^src/uname-arch\.c$ +^src/uname-uname\.c$ diff --git a/AUTHORS b/AUTHORS index 9a8b2c9..55e4f43 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,7 @@ Here are the names of the programs in this package, each followed by the name(s) of its author(s). +arch: David MacKenzie, Karel Zak base64: Simon Josefsson basename: FIXME unknown cat: Torbjorn Granlund, Richard M. Stallman diff --git a/ChangeLog b/ChangeLog index cb3fbfe..6ef3d1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2007-06-05 Karel Zak <[EMAIL PROTECTED]> + + New program: arch + * NEWS: Mention arch. + * README: Add arch to the list of programs. + * AUTHORS: Add arch. + * src/uname.c: Include "uname.h". + (PROGRAM_NAME): Handle arch, too. + (ARCH_AUTHORS): Define. + (uname_long_options, arch_long_options): Renamed and new globals. + (usage): Handle arch-mode as well as uname-mode. + (decode_switches): New function, extracted from main, + to handle arch-mode as well as uname-mode. + (main): Handle both modes. + * src/uname-arch.c: New program, alias for "uname -m". + * src/uname-uname.c: New file, default uname mode. + * src/uname.h: New file, uname modes. + * src/Makefile.am (EXTRA_PROGRAMS): Add arch. + (uname_SOURCES, arch_SOURCES): Define. + * man/arch.x: New file. + * man/Makefile.am (dist_man_MANS): Add arch.1. + (arch.1): New dependency. + * tests/misc/arch: New test, compare "arch" with "uname -m" + * configure.ac (OPTIONAL_BIN_PROGS): Add arch. + (MAN): Add arch.1. + * .x-sc_require_config_h: Exempt uname-arch.c and uname-uname.c + from the always-include-<config.h> rule. + 2007-06-04 Paul Eggert <[EMAIL PROTECTED]> * doc/coreutils.texi (Common options): Mention that -h and diff --git a/NEWS b/NEWS index 715b0d6..942c6b9 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ GNU coreutils NEWS -*- outline -*- * Noteworthy changes in release 6.9+ (????-??-??) [stable] +** New programs + + arch: equivalent to uname -m + ** New features Add SELinux support (FIXME: add details here) diff --git a/README b/README index 62853c2..14259c6 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ arbitrary limits. The programs that can be built with this package are: - [ base64 basename cat chcon chgrp chmod chown chroot cksum comm cp + [ arch base64 basename cat chcon chgrp chmod chown chroot cksum comm cp csplit cut date dd df dir dircolors dirname du echo env expand expr factor false fmt fold groups head hostid hostname id install join kill link ln logname ls md5sum mkdir mkfifo mknod mv nice nl nohup diff --git a/configure.ac b/configure.ac index b441256..3d163a6 100644 --- a/configure.ac +++ b/configure.ac @@ -42,8 +42,8 @@ coreutils_MACROS AC_FUNC_FORK AC_CHECK_FUNCS(uname, - OPTIONAL_BIN_PROGS="$OPTIONAL_BIN_PROGS uname\$(EXEEXT)" - MAN="$MAN uname.1") + OPTIONAL_BIN_PROGS="$OPTIONAL_BIN_PROGS arch\$(EXEEXT) uname\$(EXEEXT)" + MAN="$MAN arch.1 uname.1") AC_CHECK_FUNCS(chroot, OPTIONAL_BIN_PROGS="$OPTIONAL_BIN_PROGS chroot\$(EXEEXT)" MAN="$MAN chroot.1") diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 4ba2fb9..adf4c99 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -35,6 +35,7 @@ @dircategory Individual utilities @direntry +* arch: (coreutils)arch invocation. Print machine hardware name. * base64: (coreutils)base64 invocation. Base64 encode/decode data. * basename: (coreutils)basename invocation. Strip directory and suffix. * cat: (coreutils)cat invocation. Concatenate and write files. @@ -396,6 +397,7 @@ User information System context +* arch invocation:: Print machine hardware name * date invocation:: Print or set system date and time * uname invocation:: Print system information * hostname invocation:: Print or set system name @@ -12329,6 +12331,7 @@ This section describes commands that print or change system-wide information. @menu +* arch invocation:: Print machine hardware name. * date invocation:: Print or set system date and time. * uname invocation:: Print system information. * hostname invocation:: Print or set system name. @@ -12961,6 +12964,26 @@ date -u -d '1970-01-01 946684800 seconds' +"%Y-%m-%d %T %z" @end itemize [EMAIL PROTECTED] arch invocation [EMAIL PROTECTED] @command{arch}: Print machine hardware name + [EMAIL PROTECTED] arch [EMAIL PROTECTED] print machine hardware name [EMAIL PROTECTED] system information, printing + [EMAIL PROTECTED] prints the machine hardware name, +and is equivalent to @samp{uname -m}. +Synopsis: + [EMAIL PROTECTED] +arch [EMAIL PROTECTED] [EMAIL PROTECTED] example + +The program accepts the @ref{Common options} only. + [EMAIL PROTECTED] + + @node uname invocation @section @command{uname}: Print system information diff --git a/man/Makefile.am b/man/Makefile.am index 650306e..3d5ce79 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -32,7 +32,7 @@ dist_man_MANS = \ tty.1 unexpand.1 uniq.1 unlink.1 vdir.1 wc.1 \ whoami.1 yes.1 $(MAN) optional_mans = \ - chroot.1 hostid.1 nice.1 pinky.1 stty.1 uname.1 uptime.1 users.1 who.1 + arch.1 chroot.1 hostid.1 nice.1 pinky.1 stty.1 uname.1 uptime.1 users.1 who.1 man_aux = $(dist_man_MANS:.1=.x) $(optional_mans:.1=.x) @@ -43,6 +43,9 @@ MAINTAINERCLEANFILES = $(dist_man_MANS) # Depend on configure.ac to get version number changes. common_dep = $(top_srcdir)/configure.ac +# Note that arch depends on uname.c +arch.1: $(common_dep) $(srcdir)/arch.x ../src/uname.c + base64.1: $(common_dep) $(srcdir)/base64.x ../src/base64.c basename.1: $(common_dep) $(srcdir)/basename.x ../src/basename.c cat.1: $(common_dep) $(srcdir)/cat.x ../src/cat.c diff --git a/man/arch.x b/man/arch.x new file mode 100644 index 0000000..7f7fd7e --- /dev/null +++ b/man/arch.x @@ -0,0 +1,6 @@ +[NAME] +uname \- print machine hardware name (same as uname -m) +[DESCRIPTION] +.\" Add any additional description here +[SEE ALSO] +uname(1), uname(2) diff --git a/man/uname.x b/man/uname.x index b019140..b27e86f 100644 --- a/man/uname.x +++ b/man/uname.x @@ -3,4 +3,4 @@ uname \- print system information [DESCRIPTION] .\" Add any additional description here [SEE ALSO] -uname(2) +arch(1), uname(2) diff --git a/src/Makefile.am b/src/Makefile.am index 0da57e3..8171cbc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,8 @@ ## along with this program; if not, write to the Free Software Foundation, ## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -EXTRA_PROGRAMS = chroot df hostid nice pinky stty su uname uptime users who +EXTRA_PROGRAMS = chroot df hostid nice pinky stty su uname uptime users who \ + arch bin_SCRIPTS = groups bin_PROGRAMS = [ chcon chgrp chown chmod cp dd dircolors du \ @@ -44,7 +45,8 @@ noinst_HEADERS = \ remove.h \ system.h \ wheel-size.h \ - wheel.h + wheel.h \ + uname.h EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \ groups.sh wheel-gen.pl extract-magic c99-to-c89.diff @@ -203,6 +205,9 @@ chgrp_SOURCES = chgrp.c chown-core.c mv_SOURCES = mv.c copy.c cp-hash.c remove.c rm_SOURCES = rm.c remove.c +uname_SOURCES = uname.c uname-uname.c +arch_SOURCES = uname.c uname-arch.c + md5sum_SOURCES = md5sum.c md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS) sha1sum_SOURCES = md5sum.c diff --git a/src/uname-arch.c b/src/uname-arch.c new file mode 100644 index 0000000..eb42942 --- /dev/null +++ b/src/uname-arch.c @@ -0,0 +1,2 @@ +#include "uname.h" +int uname_mode = UNAME_ARCH; diff --git a/src/uname-uname.c b/src/uname-uname.c new file mode 100644 index 0000000..450245d --- /dev/null +++ b/src/uname-uname.c @@ -0,0 +1,2 @@ +#include "uname.h" +int uname_mode = UNAME_UNAME; diff --git a/src/uname.c b/src/uname.c index 7389d42..a901a57 100644 --- a/src/uname.c +++ b/src/uname.c @@ -1,7 +1,7 @@ /* uname -- print system information - Copyright (C) 1989, 1992, 1993, 1996, 1997, 1999, 2000, 2001, 2002, - 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1989, 1992, 1993, 1996, 1997, 1999-2005, 2007 + Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -54,11 +54,13 @@ #include "system.h" #include "error.h" #include "quote.h" +#include "uname.h" /* The official name of this program (e.g., no `g' prefix). */ -#define PROGRAM_NAME "uname" +#define PROGRAM_NAME (uname_mode == UNAME_UNAME ? "uname" : "arch") #define AUTHORS "David MacKenzie" +#define ARCH_AUTHORS "David MacKenzie", "Karel Zak" /* Values that are bitwise or'd into `toprint'. */ /* Kernel name. */ @@ -88,7 +90,7 @@ /* The name this program was run with, for error messages. */ char *program_name; -static struct option const long_options[] = +static struct option const uname_long_options[] = { {"all", no_argument, NULL, 'a'}, {"kernel-name", no_argument, NULL, 's'}, @@ -106,6 +108,13 @@ static struct option const long_options[] = {NULL, 0, NULL, 0} }; +static struct option const arch_long_options[] = +{ + {GETOPT_HELP_OPTION_DECL}, + {GETOPT_VERSION_OPTION_DECL}, + {NULL, 0, NULL, 0} +}; + void usage (int status) { @@ -115,7 +124,10 @@ usage (int status) else { printf (_("Usage: %s [OPTION]...\n"), program_name); - fputs (_("\ + + if (uname_mode == UNAME_UNAME) + { + fputs (_("\ Print certain system information. With no OPTION, same as -s.\n\ \n\ -a, --all print all information, in the following order,\n\ @@ -124,13 +136,22 @@ Print certain system information. With no OPTION, same as -s.\n\ -n, --nodename print the network node hostname\n\ -r, --kernel-release print the kernel release\n\ "), stdout); - fputs (_("\ + fputs (_("\ -v, --kernel-version print the kernel version\n\ -m, --machine print the machine hardware name\n\ -p, --processor print the processor type or \"unknown\"\n\ -i, --hardware-platform print the hardware platform or \"unknown\"\n\ -o, --operating-system print the operating system\n\ "), stdout); + } + else + { + fputs (_("\ +Print machine architecture.\n\ +\n\ +"), stdout); + } + fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); emit_bug_reporting_address (); @@ -151,69 +172,83 @@ print_element (char const *element) fputs (element, stdout); } -int -main (int argc, char **argv) + +/* Set all the option flags according to the switches specified. + Return the mask indicating which elements to print. */ + +static int +decode_switches (int argc, char **argv) { int c; - static char const unknown[] = "unknown"; - - /* Mask indicating which elements to print. */ unsigned int toprint = 0; - initialize_main (&argc, &argv); - program_name = argv[0]; - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + if (uname_mode == UNAME_ARCH) + { + while ((c = getopt_long (argc, argv, "", + arch_long_options, NULL)) != -1) + { + switch (c) + { + case_GETOPT_HELP_CHAR; - atexit (close_stdout); + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, ARCH_AUTHORS); - while ((c = getopt_long (argc, argv, "asnrvmpio", long_options, NULL)) != -1) + default: + usage (EXIT_FAILURE); + } + } + toprint = PRINT_MACHINE; + } + else { - switch (c) - { - case 'a': - toprint = UINT_MAX; - break; + while ((c = getopt_long (argc, argv, "asnrvmpio", + uname_long_options, NULL)) != -1) + { + switch (c) + { + case 'a': + toprint = UINT_MAX; + break; - case 's': - toprint |= PRINT_KERNEL_NAME; - break; + case 's': + toprint |= PRINT_KERNEL_NAME; + break; - case 'n': - toprint |= PRINT_NODENAME; - break; + case 'n': + toprint |= PRINT_NODENAME; + break; - case 'r': - toprint |= PRINT_KERNEL_RELEASE; - break; + case 'r': + toprint |= PRINT_KERNEL_RELEASE; + break; - case 'v': - toprint |= PRINT_KERNEL_VERSION; - break; + case 'v': + toprint |= PRINT_KERNEL_VERSION; + break; - case 'm': - toprint |= PRINT_MACHINE; - break; + case 'm': + toprint |= PRINT_MACHINE; + break; - case 'p': - toprint |= PRINT_PROCESSOR; - break; + case 'p': + toprint |= PRINT_PROCESSOR; + break; - case 'i': - toprint |= PRINT_HARDWARE_PLATFORM; - break; + case 'i': + toprint |= PRINT_HARDWARE_PLATFORM; + break; - case 'o': - toprint |= PRINT_OPERATING_SYSTEM; - break; + case 'o': + toprint |= PRINT_OPERATING_SYSTEM; + break; - case_GETOPT_HELP_CHAR; + case_GETOPT_HELP_CHAR; - case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); - default: - usage (EXIT_FAILURE); + default: + usage (EXIT_FAILURE); + } } } @@ -223,6 +258,27 @@ main (int argc, char **argv) usage (EXIT_FAILURE); } + return toprint; +} + +int +main (int argc, char **argv) +{ + static char const unknown[] = "unknown"; + + /* Mask indicating which elements to print. */ + unsigned int toprint = 0; + + initialize_main (&argc, &argv); + program_name = argv[0]; + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + atexit (close_stdout); + + toprint = decode_switches (argc, argv); + if (toprint == 0) toprint = PRINT_KERNEL_NAME; diff --git a/src/uname.h b/src/uname.h new file mode 100644 index 0000000..2f4a872 --- /dev/null +++ b/src/uname.h @@ -0,0 +1,7 @@ +/* This is for the `uname' program. */ +#define UNAME_UNAME 1 + +/* This is for the `arch' program. */ +#define UNAME_ARCH 2 + +extern int uname_mode; diff --git a/tests/misc/arch b/tests/misc/arch new file mode 100755 index 0000000..4773491 --- /dev/null +++ b/tests/misc/arch @@ -0,0 +1,48 @@ +#!/bin/sh +# Ensure that arch output is equal to uname -m + +# Copyright (C) 2007 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +if test "$VERBOSE" = yes; then + set -x + arch --version +fi + +pwd=`pwd` +t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ +trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +framework_failure=0 +mkdir -p $tmp || framework_failure=1 +cd $tmp || framework_failure=1 + +if test $framework_failure = 1; then + echo "$0: failure in testing framework" 1>&2 + (exit 1); exit 1 +fi + +fail=0 + +arch > out || fail=1 +uname -m > exp || fail=1 + +cmp out exp || fail=1 +test $fail = 1 && diff out exp 2> /dev/null + +(exit $fail); exit $fail -- 1.5.2.1.116.g9f308 _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils