unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* Strange error with cat (coreutils 4.5.2) on HP/UX
@ 2002-10-12 16:13 Petter Reinholdtsen
  2002-10-12 22:36 ` Petter Reinholdtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Petter Reinholdtsen @ 2002-10-12 16:13 UTC (permalink / raw)



I get the message 'cat: memory exhausted' when trying to run 'cat' on
a big file across rsh to a HP/UX box.  The problem goes away when I
try to do this in an interactive shell, or if I pipe the output from
cat through dd:

Here is a summary:

  % /bin/uname -a
  Linux ravenclaw.uio.no 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
  % rsh snipe /usr/bin/uname -a
  HP-UX snipe B.11.00 A 9000/782 2001385808 two-user license
  % rsh snipe "cat /local/store/snipe/bash-c/V*" |tar tf - >/dev/null
  cat: memory exhausted
  % rsh snipe "cat /local/store/snipe/bash-c/V* | dd" |tar tf - >/dev/null
  4620+0 records in
  4620+0 records out
  %

Any ideas?  This only seem to happen on HP/UX, and not on Irix,
Solaris, Tru64 UNIX or Linux.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Strange error with cat (coreutils 4.5.2) on HP/UX
  2002-10-12 16:13 Strange error with cat (coreutils 4.5.2) on HP/UX Petter Reinholdtsen
@ 2002-10-12 22:36 ` Petter Reinholdtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Petter Reinholdtsen @ 2002-10-12 22:36 UTC (permalink / raw)
  Cc: bug-gnu-emacs


[Petter Reinholdtsen]
> I get the message 'cat: memory exhausted' when trying to run 'cat' on
> a big file across rsh to a HP/UX box.  The problem goes away when I
> try to do this in an interactive shell, or if I pipe the output from
> cat through dd:

I've tracked it down to a problem with fstat()/st_blksize when stdout
is sent through rsh.  I used this code to test:

  #include <stdio.h>
  #include <unistd.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  int main(int argc, char *argv[]) {
     struct stat stat_buf;
     fstat(STDOUT_FILENO, &stat_buf);
     printf("st_blksize=%d(0x%x) high=%d low=%d\n", stat_buf.st_blksize,
            stat_buf.st_blksize >> 16,
            stat_buf.st_blksize & 0xffff);
     return 0;
  }

When I run it using an interactive shell on the HP/UX box:

  st_blksize=65536(0x10000) high=1 low=0

If I run it using 'rsh host testprog', the output is worse:

  st_blksize=2147421096(0x7fff0ba8) high=32767 low=2984

If I instead use dd in front (rsh snipe "/tmp/foo |dd"), I get this:

  st_blksize=8192(0x2000) high=0 low=8192'.

Perhaps the code in cat.c should check for insanely large values, and
not try to call xmalloc() with any large number?

Here is a stupid patch to fix the problem.  I'm not sure if this is
the right fix, but at least GNU cat works again on HP/UX.

diff -ur src-4.5.2/src/cat.c src-4.5.2-local/src/cat.c
--- src-4.5.2/src/cat.c 2002-09-29 23:25:03.000000000 +0200
+++ src-4.5.2-local/src/cat.c   2002-10-13 00:32:51.000000000 +0200
@@ -804,6 +804,10 @@
         --version, or --help) were specified, use `cat', otherwise use
         `simple_cat'.  */

+      /* Special case for HP/UX 11.00 */
+      if (outsize > 0x20000) /* Avoid xmalloc() on very huge numbers */
+          outsize = DEV_BSIZE;
+
       if (options == 0)
        {
          insize = max (insize, outsize);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-12 22:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-12 16:13 Strange error with cat (coreutils 4.5.2) on HP/UX Petter Reinholdtsen
2002-10-12 22:36 ` Petter Reinholdtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).