Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Jun 2005 12:06:35 +0200 (CEST)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-amd64@FreeBSD.ORG, obrien@FreeBSD.ORG
Subject:   Re: sript (Perl) test code needed
Message-ID:  <200506301006.j5UA6ZV9017308@lurza.secnetix.de>
In-Reply-To: <20050629221047.GC20836@dragon.NUXI.org>

next in thread | previous in thread | raw e-mail | index | archive | help
David O'Brien <obrien@freebsd.org> wrote:
 > I know this should be trivial to do in perl and maybe someone here has the
 > time to hack it up.  I want a small test script (actually some other
 > scripting language than perl preferred).
 > 
 > The script should run the following commands until an error is returned:
 > 
 >     ls
 >     ls .
 >     ls ./
 >     ls ./.
 >     ls ././
 >     ls ././.
 >     ls ./././
 >     etc...
 > 
 > and when the error occurs print out the length of the command line.
 > I want to get the bottom of the "command too long" issue that causes too
 > much trouble deploying Java on FreeBSD/AMD64.

This is pretty easy to do in plain /bin/sh.

   CMD="ls "
   while $CMD >/dev/null; do
           case "$CMD" in
                   *.)     CMD="$CMD/";;
                   *)      CMD="$CMD.";;
           esac
   done
   echo "length == ${#CMD}"

On my old 4-stable/i386 machine, it reports "File name too
long" when the length of the command reaches 1027 chars
(i.e. the path is 1024 chars, which is PATH_MAX).

When replacing "/" with " ", so that the commands become
"ls . . . . " etc., it runs a lot longer, until finally it
reports "argument list too long" when the command length
reaches 61344 chars.  Since my environment is 2079 chars,
and the " >/dev/null" is another 12 bytes, that adds up
to 65532 bytes.  ARG_MAX is 65536.  Don't ask me where the
remaining 4 chars go.  Maybe some safety margins in the
implementation, or alignment issues.

Best regards
   Oliver

PS:  I couldn't help writing the same in Python, too.  :-)
It reports the same result, of course.

   import os
   cmd = "ls "
   while os.system(cmd + " >/dev/null") == 0:
           cmd = cmd + "/."[len(cmd) % 2]
   print "length ==", len(cmd)

And in awk ...

   BEGIN {
       cmd = "ls "
       while (system(cmd " >/dev/null") == 0)
           cmd = cmd substr("/.", length(cmd) % 2 + 1, 1)
       print "length ==", length(cmd)
   }

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

(On the statement print "42 monkeys" + "1 snake":)  By the way,
both perl and Python get this wrong.  Perl gives 43 and Python
gives "42 monkeys1 snake", when the answer is clearly "41 monkeys
and 1 fat snake".        -- Jim Fulton



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200506301006.j5UA6ZV9017308>