padding in arguments string array for popen2 or exec
Jaroslav Hajek
highegg at gmail.com
Mon Mar 2 05:27:05 CST 2009
On Mon, Mar 2, 2009 at 12:04 PM, Olaf Till <olaf.till at uni-jena.de> wrote:
> Hi,
>
> in Octave-3.0.3 (probably all versions >= 3.0) please consider the
> following errors:
>
>
> octave:1> [pdw, pdr, pid] = popen2 ("ssh", char ("localhost", "octave-3.0.2"))
> pdw = 5
> pdr = 6
> pid = 11773
> octave:2> ssh: localhost : Name or service not known
>
> octave:2> exec ("ssh", char ("localhost", "octave-3.0.2"))
> ssh: localhost : Name or service not known
> olaf at olaf:~/devel/src/octave-3.0.3$
>
>
> (Don't worry about my calling Octave version 3.0.2 with the passed
> arguments, version 3.0.3 is not installed, but run in place with
> ./run-octave.)
>
> Note the spaces in "localhost :" . Debugging indicates that the
> "all_strings()" method returns the arguments padded (in
> liboctave/oct-syscalls.cc(execvp)):
>
> (gdb) print argv[0]
> $4 = 0x97bd940 "ssh"
> (gdb) print argv[1]
> $5 = 0x97bda68 "localhost "
> (gdb) print argv[2]
> $6 = 0x97bda80 "octave-3.0.2"
>
> (All but the first argv elements were filled in from a string_vector
> returned by all_strings() in src/syscalls.cc(popen2) .)
>
>
> In Octave-2.1.73, for which I have no locally-compiled binary
> available for gdb, the problem does not occur:
>
> octave2.1:1> [pdw, pdr, pid] = popen2 ("ssh", char ("localhost", "octave-3.0.2"))
> pdw =
> {
> id = 3
> name =
> mode = w
> arch = ieee_little_endian
> status = open
> }
> pdr =
> {
> id = 6
> name =
> mode = r
> arch = ieee_little_endian
> status = open
> }
> pid = 11611
> octave2.1:2>
> octave2.1:2> warning: DEFAULT_LOADPATH is no longer a built-in variable; please read the NEWS file or type `news' for details
>
> octave2.1:2>
>
>
> although according to the source (despite an implementation of popen2
> in an m-file) after all the all_strings() method is used in the same
> way (for giving all but the first element of the sring_vector passed
> to Octaves execvp) as in versions >= 3.0.
>
> Olaf
> _______________________________________________
> Bug-octave mailing list
> Bug-octave at octave.org
> https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave
>
Sorry I can't inspect octave 2.1.72 sources, but what you see is the
consequence of char padding by spaces when creating character
matrices. I don't think all_strings can just discard the any trailing
whitespaces. That would carry the potential hazard of discarding
something that was real data. I suggest you just use cell arrays
instead, which save you from this kind of trouble.
regards
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
More information about the Bug-octave
mailing list