fix a minor bug in sort: bogus --batch-size diagnostic

2008-08-10 Thread Jim Meyering
I noticed that ./sort -m --batch-size=18446744073709551617
was printing garbage as part of its diagnostic.
Here's the fix, along with a couple other improvements.

>From cd1f4bc1ecde1e7b313c1d0d587a07965d00d8b1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Sun, 10 Aug 2008 10:51:03 +0200
Subject: [PATCH] sort: don't print uninitialized in diagnostic

* src/sort.c (specify_nmerge): Do use uinttostr value.
Provoke with e.g., sort -m --batch-size=18446744073709551617
Omit quotes around known-numeric value in diagnostic.
* tests/misc/sort-merge [nmerge-big]: Tighten ERR_SUBST regexp
to require a numeric value in that diagnostic, so this particular
failure cannot reappear.
---
 src/sort.c|4 ++--
 tests/misc/sort-merge |4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/sort.c b/src/sort.c
index 9f998a6..74318b9 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -,12 +,12 @@ specify_nmerge (int oi, char c, char const *s)
   if (e == LONGINT_OVERFLOW)
 {
   char max_nmerge_buf[INT_BUFSIZE_BOUND (unsigned int)];
-  uinttostr (max_nmerge, max_nmerge_buf);
   error (0, 0, _("--%s argument %s too large"),
 long_options[oi].name, quote(s));
   error (SORT_FAILURE, 0,
 _("maximum --%s argument with current rlimit is %s"),
-long_options[oi].name, quote (max_nmerge_buf));
+long_options[oi].name,
+uinttostr (max_nmerge, max_nmerge_buf));
 }
   else
 xstrtol_fatal (e, oi, c, long_options, s);
diff --git a/tests/misc/sort-merge b/tests/misc/sort-merge
index fb7c63c..985d7a4 100755
--- a/tests/misc/sort-merge
+++ b/tests/misc/sort-merge
@@ -55,9 +55,9 @@ my @Tests =
 {ERR=>"$prog: invalid --batch-size argument `a'\n"}, {EXIT=>2}],

  ['nmerge-big', "-m --batch-size=$bigint", @inputs,
-   {ERR_SUBST=>'s/current rlimit is .+\n/current rlimit is/'},
+   {ERR_SUBST=>'s/(current rlimit is) \d+/$1/'},
 {ERR=>"$prog: --batch-size argument `$bigint' too large\n".
- "$prog: maximum --batch-size argument with current rlimit is"},
+ "$prog: maximum --batch-size argument with current rlimit is\n"},
 {EXIT=>2}],

  # This should work since nmerge >= the number of input files
--
1.6.0.rc2.24.g3cd61


>From 43f66923ccaf0f3ba6969e43762602fdaafbe912 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Sun, 10 Aug 2008 16:13:14 +0200
Subject: [PATCH] sort: avoid erroneous cast

* src/sort.c (OPEN_MAX): Define if not already defined.
(MAX_NMERGE): Remove definition.
(specify_nmerge): Don't cast MAX_NMERGE (of type size_t) to unsigned int.
Instead, use OPEN_MAX as the fall-back value.
---
 src/sort.c |   17 +++--
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/sort.c b/src/sort.c
index 74318b9..a07ecfc 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -76,6 +76,13 @@ struct rlimit { size_t rlim_cur; };
 # endif
 #endif

+#if !defined OPEN_MAX && defined NR_OPEN
+# define OPEN_MAX NR_OPEN
+#endif
+#if !defined OPEN_MAX
+# define OPEN_MAX 20
+#endif
+
 #ifndef STDC_HEADERS
 double strtod ();
 #endif
@@ -231,9 +238,6 @@ static struct month monthtab[] =
 /* Minimum sort size; the code might not work with smaller sizes.  */
 #define MIN_SORT_SIZE (nmerge * MIN_MERGE_BUFFER_SIZE)

-/* Maximum merge buffers we can theoretically support */
-#define MAX_NMERGE (SIZE_MAX / MIN_MERGE_BUFFER_SIZE)
-
 /* The number of bytes needed for a merge or check buffer, which can
function relatively efficiently even if it holds only one line.  If
a longer line is seen, this value is increased.  */
@@ -1075,14 +1079,15 @@ specify_nmerge (int oi, char c, char const *s)
 {
   uintmax_t n;
   struct rlimit rlimit;
-  unsigned int max_nmerge = (unsigned int) MAX_NMERGE;
   enum strtol_error e = xstrtoumax (s, NULL, 10, &n, NULL);

   /* Try to find out how many file descriptors we'll be able
  to open.  We need at least nmerge + 3 (STDIN_FILENO,
  STDOUT_FILENO and STDERR_FILENO). */
-  if (getrlimit (RLIMIT_NOFILE, &rlimit) == 0)
-max_nmerge = MIN (max_nmerge, rlimit.rlim_cur - 3);
+  unsigned int max_nmerge = ((getrlimit (RLIMIT_NOFILE, &rlimit) == 0
+ ? rlimit.rlim_cur
+ : OPEN_MAX)
+- 3);

   if (e == LONGINT_OK)
 {
--
1.6.0.rc2.24.g3cd61


>From 4b5e044be39c4699adfe499bd100d19613a98c58 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Sun, 10 Aug 2008 16:15:00 +0200
Subject: [PATCH] sort: remove unnecessary declaration of strtod

* src/sort.c (STDC_HEADERS): Remove declaration of strtod.
---
 src/sort.c |4 
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/src/sort.c b/src/sort.c
index a07ecfc..b932a51 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -83,10 +83,6 @@ struct rlimit { size_t rlim_cur; };
 # define OPEN_MAX 20
 #endif

-#ifndef STDC_HEADERS
-double strt

rm && opensolaris && ntfs-3g problem

2008-08-10 Thread Andras Barna
on opensolaris (update 94) can't remove recursively directories.

@osol /ntfs: /usr/gnu/bin/mkdir -p t/t/t/t/t/t/t/t/t/t//t/t///t//t/t/t/
@osol /ntfs: /usr/gnu/bin/rm --version|head -1
rm (GNU coreutils) 6.7
@osol /ntfs: rm -rf t
rm: cannot remove directory `t': Directory not empty
@osol /ntfs: rm -r t
@osol /ntfs: ls t
ls: cannot access t: No such file or directory
@osol /ntfs: /usr/gnu/bin/mkdir -p t/t/t/t/t/t/t/t/t/t//t/t///t//t/t/t/
@osol /ntfs: /data/a/bin/rm --version|head -1
rm (GNU coreutils) 6.12
@osol /ntfs: /data/a/bin/rm -rf t
@osol /ntfs: echo $?
0
@osol /ntfs: ls t
t
@osol /ntfs: /data/a/bin/rm -r t
@osol /ntfs: ls t
t
@osol /ntfs: /data/a/bin/rm -r t
@osol /ntfs: echo $?
0
@osol /ntfs: ls t
t
@osol /ntfs: /usr/bin/rm --version
/usr/bin/rm: illegal option -- version
usage: rm [-fiRr] file ...
@osol /ntfs: /usr/bin/rm -r t
@osol /ntfs: ls t
ls: cannot access t: No such file or directory
@osol /ntfs: /usr/gnu/bin/mkdir -p t/t/t/t/t/t/t/t/t/t//t/t///t//t/t/t/
@osol /ntfs: /usr/bin/rm -rf t
@osol /ntfs: ls t
ls: cannot access t: No such file or directory
@osol /ntfs:



-- 
Andy
http://blog.sartek.net


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: ls -s but sorted

2008-08-10 Thread jidanni
JY> What are you suggesting should be changed?

There is no way to get any order into these rectangles I cropped from
your reply:

~/tm
tota
104K
 12K
 32K
~/tm
tota
 12
104
 32

One must resort to an external program to get them in order.
You only offer -S sorting, but we people trying to weed out torrent
shrapnel want to order on the -s numbers.

"So what, use an external program" you might say. But e.g.,

  dired-sort-toggle-or-edit...With a prefix argument you can edit the
  current listing switches instead.

doesn't allow one.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


some more tiny string fixes [patches]

2008-08-10 Thread Benno Schulenberg

Hi,

Attached the promised batch of other string fixes.

The sixth patch removes brackets around the MMDD... part on the 
second synopsis line of 'date'.  They are unneeded, because the 
first synopsis line already desscribes the possibility of having 
zero arguments or only an option argument.  Removing the brackets 
makes it clearer what "or set the system date" refers to.

The equal signs in the eighth patch (to 'dd') are just a suggestion.  
If not acceptable, then at least the "xM M" should move to the end 
of the line; it is rather confusing to find it there out of order.  
Maybe leave it out altogether?

In the thirteenth patch (to 'fmt'), maybe replace -DIGITS with 
-WIDTH, as in the Info document?  Or maybe deprecate the option, as 
it is for 'fold'?  Having one accept it and the other not seems odd.

Some of these synopsis changes may need to be made to the Info 
documents too, I haven't systematically checked that.

Benno
>From 7c92e6ddd7e3341eba32ca7e5096b4f10bb4a46b Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[EMAIL PROTECTED]>
Date: Mon, 4 Aug 2008 22:11:47 +0200
Subject: [PATCH] who: Gettextize two forgotten strings.

---
 src/who.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/who.c b/src/who.c
index 0bba912..94af8bf 100644
--- a/src/who.c
+++ b/src/who.c
@@ -427,7 +427,7 @@ print_user (const STRUCT_UTMP *utmp_ent, time_t boottime)
 static void
 print_boottime (const STRUCT_UTMP *utmp_ent)
 {
-  print_line (-1, "", ' ', -1, "system boot",
+  print_line (-1, "", ' ', -1, _("system boot"),
 	  time_string (utmp_ent), "", "", "", "");
 }
 
@@ -472,7 +472,7 @@ print_login (const STRUCT_UTMP *utmp_ent)
 
   /* FIXME: add idle time? */
 
-  print_line (-1, "LOGIN", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
+  print_line (-1, _("LOGIN"), ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
 	  time_string (utmp_ent), "", pidstr, comment, "");
   free (comment);
 }
-- 
1.5.6.4

>From 75706de0aae7d455af877f251564bba5906dbf51 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[EMAIL PROTECTED]>
Date: Mon, 4 Aug 2008 22:40:48 +0200
Subject: [PATCH] cp: Move a newline to make second message identical to others.

---
 src/cp.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/cp.c b/src/cp.c
index c768d1b..059f317 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -235,9 +235,9 @@ corresponding DEST file is made sparse as well.  That is the behavior\n\
 selected by --sparse=auto.  Specify --sparse=always to create a sparse DEST\n\
 file whenever the SOURCE file contains a long enough sequence of zero bytes.\n\
 Use --sparse=never to inhibit creation of sparse files.\n\
-\n\
 "), stdout);
   fputs (_("\
+\n\
 The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
 The version control method may be selected via the --backup option or through\n\
 the VERSION_CONTROL environment variable.  Here are the values:\n\
-- 
1.5.6.4

>From 310b52e5bdae2021836e95c0693bc11733b59f2a Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[EMAIL PROTECTED]>
Date: Mon, 4 Aug 2008 23:21:35 +0200
Subject: [PATCH] doc: Put the exitstatus paragraph in a better place.

* doc/coreutils.texi (tsort invocation): move two lines
---
 doc/coreutils.texi |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index b47448f..3d18608 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -4624,6 +4624,8 @@ precedes @code{main}.
 The only options are @option{--help} and @option{--version}.  @xref{Common
 options}.
 
[EMAIL PROTECTED]
+
 @node tsort background
 @section @command{tsort}: Background
 
@@ -4659,8 +4661,6 @@ Anyhow, that's where tsort came from.  To solve an old problem with
 the way the linker handled archive files, which has since been solved
 in different ways.
 
[EMAIL PROTECTED]
-
 
 @node ptx invocation
 @section @command{ptx}: Produce permuted indexes
-- 
1.5.6.4

>From a776e8406a2be4d945110e5eac77f2d32d71b81f Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[EMAIL PROTECTED]>
Date: Mon, 4 Aug 2008 22:57:07 +0200
Subject: [PATCH] printenv: Say what it does when variables are specified.

---
 src/printenv.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/printenv.c b/src/printenv.c
index b68fb21..ecb6593 100644
--- a/src/printenv.c
+++ b/src/printenv.c
@@ -58,7 +58,8 @@ usage (int status)
   printf (_("\
 Usage: %s [VARIABLE]...\n\
   or:  %s OPTION\n\
-If no environment VARIABLE specified, print them all.\n\
+Print the values of the specified environment VARIABLE(s).\n\
+If no VARIABLE is specified, print name and value pairs for them all.\n\
 \n\
 "),
 	  program_name, program_name);
-- 
1.5.6.4

>From 32906d0864978535682615199cecb2686cf3c98c Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[EMAIL PROTECTED]>
Date: Thu, 7 Aug 2008 00:01:16 +0200
Subject: [PATCH] date: Remove confusing and unneeded sentence from -help.

I

Re: whoami problem when two or more users have the same uid

2008-08-10 Thread Bob Proulx
First, thank you for making this suggestion.  However I do not believe
this to be a deficiency of the whoami command.  This is expected
behavior in the GNU and Unix systems.

flaviano petrocchi wrote:
> I use an alternate root user with login capabilities, created with
> "useradd -u 0 -o -g 0 -G 0 -m -s /bin/bash superuser".

Note that you are simply creating a new way to log into the account.
You are not creating a new account.  You are simply enabling a new way
to log into the existing root superuser account.  I think that is a
key point.  It isn't a separate account.  This isn't even a documented
behavior as far as I know.  It is simply the way the implementation
has always worked.

> If I login with superuser, whoami returns root or superuser
> depending on which user comes before in the /etc/passwd file.

Yes.  That is because the password file defines the mapping from uid
to name.  The first one in the file defines the name.  This is the way
it has always worked.  For decades.

> echo $USER instead always returns the correct user name.

Caution here.  The USER variable is sometimes overridden by the
operating system.  In particular Red Hat overrides USER and LOGNAME
from their original settings in /etc/profile.

Traditionally LOGNAME referred to the name the user used to log into
the system.  (This was also available with 'who am i' too.)  RH breaks
this by setting both LOGNAME and USER to the output of 'id -un'.
Other systems that I am familiar with (Debian, Ubuntu, SuSE, HP-UX,
Solaris) do not override the value.

> I think whoami should always report the correct name maybe

The disagreement here is on the "correct" name.  The correct name is
the named defined for the current effective user id from the password
database (not necessarily the /etc/passwd file for example if NIS/YP
or LDAP is in use).  The correct name is not the $USER nor $LOGNAME
since those might be changed and invalid in the environment.

> retrieving the USER environment variable instead of parsing the
> passwd file. Those who use whoami to check if a user is root should
> instead use id -u and check if the uid is 0.

The 'whoami' command must map the current user id to the associated
name.  Otherwise too much system breakage would occur.  For example
contemplate the following:

  $ USER=foo whoami
  foo

That wouldn't be good.  If a script desires to use $USER then the
script should simply use $USER instead of calling 'whoami'.  Also
although I admit that while I usually use 'whoami' in my scripts the
standard POSIX standard method would be to use 'id -un'.

Note that 'whoami' is a BSD derived utility and isn't standardized by
POSIX.  BSD therefore is the reference for the behavior of this
command.  This has decades of legacy behavior and therefore it really
isn't practical to try to change the behavior now.  Instead new
behavior should be part of a new command.  But in this case what you
wish is easily available simply by using the $USER value directly so
there really isn't a need to put this in a command at all.

See also the 'logname' and 'who am i' commands.

Bob


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils