XML Output: libxo - provide single API to output TXT, XML, JSON and HTML
Warner Losh
imp at bsdimp.com
Thu Aug 14 16:50:05 UTC 2014
On Aug 14, 2014, at 10:40 AM, Phil Shafer <phil at juniper.net> wrote:
> Warner Losh writes:
>> My question for people advocating this method: Why not require all
>> commands that generate this kind of output to support a standard
>> command line option that causes the command to print nothing and
>> return 0 if it supports reporting, or anything else if it doesn't
>> (return 0 with output, or return non-zero with or without output).
>
> It's a chicken and egg problem. I can't call the command with the
> option until I know that command can handle the option without
> generating an error, a core file, or rebooting the box. Until I
> know what the command will do, I can't invoke it safely.
If a userland command reboots the box in response to bad command
line options, that’s not your problem to fix: that’s a security issue
that needs to be fixed regardless of the method you chose. If the command
creates a core file, that’s a bug in that command. The command
could very easily create a core file when you call it with a valid
set of options too. Generating an error is 100% fine: in fact I count
on that happening.
> There's also the issue of find an option that all commands are not
> using, given that I can't change options for existing commands.
In my opinion, there’s no chicken and egg problem.
I specifically proposed a long option that isn’t present in any command,
and is likely to generate errors or at least output. The reason I proposed
the long option was so that 2 lines of code could be added to programs
that support it:
in some header:
#define LONG_OPTION_DEFINE “—supports-xml-output"
#include <some-header.h>
...
int main(int argc, char **argv)
{
/* local variables here */
if (argc == 2 && strcmp(argv[1], LONG_OPTION_DEFINE) == 0)
exit(0);
}
Which wouldn’t interfere with any other command line parsing these
programs do. —supports-xml-output isn’t likely a valid set of options
for any program that exists today, except for those that support xml.
The protocol is simple: redirect stdout and stderr to pipes, invoke
the command, if the exit status is 0 and there’s no output on the pipes,
then the command supports your protocol. If there’s output, or if the
exit status isn’t 0, then the program doesn’t.
Warner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20140814/4cd70233/attachment.sig>
More information about the freebsd-arch
mailing list