[quake3-bugzilla] [Bug 5080] [patch] code/sys/sys_unix.c:Sys_Dialog doesn't check exit codes properly
bugzilla-daemon at icculus.org
bugzilla-daemon at icculus.org
Sat Jul 16 22:45:11 EDT 2011
https://bugzilla.icculus.org/show_bug.cgi?id=5080
--- Comment #4 from q3urt.undead at gmail.com 2011-07-16 22:45:09 EDT ---
Tim: That's fine if you want to try to execute commands that don't exist.
However, < 64 is not safe. When I run xmessage, I get 101 when I click ok. I
think exit code 127 is always command not found because /bin/sh is a POSIX
shell. I don't have the spec in front of me, but my guess is that it's a
requirement. Does anyone have a copy of it? On Debian, you can use dash
instead of /bin/sh (bash) which is smaller but still meets the POSIX
requirements.
The system() man page covers these return codes conditions:
When an error occurs in system() such as fork() failure, -1
When /bin/sh cannot be executed and the string is not NULL, the exit status
will be exit(127).
When the passed in string is NULL, it returns nonzero if the shell is available
or zero if not. Could it return 127 here too since it's vague? Not worth
worrying about since we don't pass in NULL.
Otherwise, it uses the WEXITSTATUS(status) as specified in wait(2).
At this point, I think you have to look at the POSIX spec to see what it says a
/bin/sh must return when a command is not found. My guess is that it requires
127 which is what we see in practice when running a command string outside of
system().
I think these are the safe assumptions:
0 = yes/ok (but this isn't the only exit code that means yes/ok).
127 = command not found
I'm seeing 101 means yes/ok as well in xmessage. I think someone would have to
go through all of the ways you call xmessage, kdialog and zenity to see how
they respond to all of the ways you are invoking it.
It would be best to find out if there's a way to force all three commands to
use specific exit codes. For instance, instead of "-buttons OK", use "-buttons
OK:0" in xmessage. Then it returns 0 rather than 101 on yes/ok.
Since you want to run through all of the commands in ioquake3, you will also
want to redirect stdout and stderr of the processes so it doesn't clutter the
screen with "sh: <command> not found" messages.
Simon: You must be assuming something about the options because that is not
necessarily how ioquake3 calls it in practice. When I get the error condition
that I mention above, it uses the default path in the switch because I only
have an "OK" button. When you only have OK, it returns something else.
$ xmessage -center -buttons OK "Hi there"
$ echo $?
101
Now you could change ioquake3 to call it like this in order to force it to use
0:
$ xmessage -center -buttons OK:0 "Hi there"
$ echo $?
0
To summarize, you can assume 127 = command not found and then you need to force
all three commands to return certain return codes or go through them all and
find out what they return.
--
Configure bugmail: https://bugzilla.icculus.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the quake3-bugzilla
mailing list