Tony ([info]quikchange) wrote,
@ 2007-03-31 10:18:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Current mood: annoyed
Current music:Down by the Riverside - Raffi
Entry tags:geeky, vmware

xterm and execv
The xterm application, which is distributed with most X11 implementations, sports a -e flag that accepts a command followed by a sequence of arguments, all of which are space-delimited. I'd been exploiting this feature to ensure that when I programatically executed console apps inside a Linux VM, the user could interact with them. All I had to do was run xterm with the -e flag and follow that with the location of the console app and its arguments (e.g. xterm -e "xeyes -center red"). Everything had been working fine when I tried this on modern Linux distros but today one of the QA people tried it on Redhat 8, which was released in 2002, and saw a nasty error message complaining that the execvp syscall could not find the specified file.

Curious about the cause of this problem, I tried manually running xterm under strace with the same arguments. This revealed that the xterm binary in XFree86 4.2 that was part of Redhat 8 simply tries to call execvp with the entire quoted string as the first argument. Since that string contained space-delimited arguments appended to the binary's name, it couldn't be resolved as a valid pathname by execvp. That made sense but it didn't explain why it worked in newer releases of xterm. Trying the same thing with the xterm binary on my Ubuntu 6.10 system revealed that xterm now falls back on passing the entire quoted string to the shell for execution if the call to execve fails. Since bash knows to deal with the space-delimited arguments, that works fine.

I was trivially able to solve the problem by removing the quotes.



(Post a new comment)


[info]kinthelt
2007-03-31 06:06 pm UTC (link)
Nice debugging work!

Though I tend to agree with the behaviour of XFree86 4.2. The string should not be quoted, since once the '-e' flag is found, the rest of the line is treated as arguments to execvp. In this case, the quotes makes the arguments act as a single argument.

The fallback to using the shell is probably more of a hack. There is no reason for that type of behaviour. Especially when you consider that quoting of characters is shell-dependent. Each shell could conceivably treat quotes differently.

(Reply to this)(Thread)


[info]quikchange
2007-04-01 01:00 am UTC (link)
I guess this is a case where iteratively applying the robustness principle can generate backward-compatibility issues.

(Reply to this)(Parent)(Thread)


[info]grosskur
2007-04-02 06:05 am UTC (link)
The robustness principle is, in general, complete garbage. There should be only one way to encode each object. See DJB's tips on protocol design for more detail.

(Reply to this)(Parent)(Thread)


[info]quikchange
2007-04-02 01:53 pm UTC (link)
Hey, I use Netstrings in my code :-)

(Reply to this)(Parent)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…