From owner-freebsd-arch@FreeBSD.ORG Thu Aug 14 16:50:05 2014 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8FF17E0A for ; Thu, 14 Aug 2014 16:50:05 +0000 (UTC) Received: from mail-ig0-f171.google.com (mail-ig0-f171.google.com [209.85.213.171]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 534B5201C for ; Thu, 14 Aug 2014 16:50:05 +0000 (UTC) Received: by mail-ig0-f171.google.com with SMTP id l13so14165715iga.4 for ; Thu, 14 Aug 2014 09:50:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:content-type:mime-version:subject:from :in-reply-to:date:cc:message-id:references:to; bh=KbwhyFAQUB3rKs3mJo1iwYXzJGYbAtSlGxGnGPc88TU=; b=RJwW1eqWo1MpkVEtjlYF/VRwO4eiQ5hPoDDB4bO3DfA1KfHPb1vOd9tCglkRQ6qX1e YYf2Xn0TC+tjm9j0F/hL+AaEScXMeGMlUzv8fUdhoVXK99ne0j2rgzC2tWDtbnu4L6Ce T4yCzQNr6BKtFwbtIQsOAeUI3IiYDURH3ymc0V83SqrYMBT9ZR17ox9zR1C4c61swJ1S E1DcznYdJbfWLtz6VslWQqDABYhYLoUrsDpMQGdclAEC2Y1HcqPa/FkndDn7pxVtlPzC HvxfG8ebvfcLgZ7H53WOQxXVaYAX67U62QG4obXEk/pTawQavhPt7JK/EvGhQko1VC/K TjpA== X-Gm-Message-State: ALoCoQlBn7L5PLzTjfVJYEYGwA8GlxSHDw/HI0yfzd1K4yAM5OiIVZihR+8vcAo6HeiMZHRRPdpT X-Received: by 10.42.226.69 with SMTP id iv5mr16137178icb.43.1408035004750; Thu, 14 Aug 2014 09:50:04 -0700 (PDT) Received: from netflix-mac.bsdimp.com (50-78-194-198-static.hfc.comcastbusiness.net. [50.78.194.198]) by mx.google.com with ESMTPSA id hu9sm86307875igb.22.2014.08.14.09.50.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Aug 2014 09:50:03 -0700 (PDT) Sender: Warner Losh Content-Type: multipart/signed; boundary="Apple-Mail=_7B8A5A89-04AD-47AD-AF26-6952FEB25191"; protocol="application/pgp-signature"; micalg=pgp-sha512 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: XML Output: libxo - provide single API to output TXT, XML, JSON and HTML From: Warner Losh In-Reply-To: <201408141640.s7EGe422096656@idle.juniper.net> Date: Thu, 14 Aug 2014 10:50:02 -0600 Message-Id: References: <201408141640.s7EGe422096656@idle.juniper.net> To: Phil Shafer X-Mailer: Apple Mail (2.1878.6) Cc: Marcel Moolenaar , John-Mark Gurney , "Simon J. Gerraty" , arch@freebsd.org, Poul-Henning Kamp , freebsd-arch , Konstantin Belousov X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 16:50:05 -0000 --Apple-Mail=_7B8A5A89-04AD-47AD-AF26-6952FEB25191 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On Aug 14, 2014, at 10:40 AM, Phil Shafer 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). >=20 > 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=92s not your problem to fix: that=92s a security = issue that needs to be fixed regardless of the method you chose. If the = command creates a core file, that=92s 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=92s no chicken and egg problem. I specifically proposed a long option that isn=92t 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 =93=97supports-xml-output" #include ... int main(int argc, char **argv) { /* local variables here */ if (argc =3D=3D 2 && strcmp(argv[1], LONG_OPTION_DEFINE) =3D=3D = 0) exit(0); } Which wouldn=92t interfere with any other command line parsing these programs do. =97supports-xml-output isn=92t 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=92s no output on the = pipes, then the command supports your protocol. If there=92s output, or if the exit status isn=92t 0, then the program doesn=92t. Warner --Apple-Mail=_7B8A5A89-04AD-47AD-AF26-6952FEB25191 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJT7Oi6AAoJEGwc0Sh9sBEAYlUQANQHwNrH68xkotZi27YYQthA ETaicmy1rterMVV16yoPAUVYxj3fNtMFiajlbDhQtbopPu0HYLJHq6aH4Y6lTVzm uQSfsSnlMbQthiaN0TdalkWKXar+hTLCz5TXYMyofvfV1NLELvzvHyq1C1mXw4NW 0V7E+5fouZxc/SBgUFace8ZMKbMRL9PSj1dnI96zMQ28WwCeq4HbH297tVwV1sRk OmolUKJSONAczauPdoS9t7v5SsRPhVCfBE7Znm0UwEyKUEcKuTYd/VdFOxQw5Mkg 3ThYGHlgoJKNC3ztIcUxGqSUMJrQ3OUxcArzwXh/MGH/hQbz+01bk37ZXO95TvzT aP7NKDot0Yc9wf2R/J6uo21gflQCSBq94ZKJUxJbZY5ZyWDpWtaKrKsh8jvvb2j5 vzKQYmUFLsYuM9BhJVnXQryzgAL3geB4GPCkAmd8NfNFp2vvMAgNygjzDpxWTUzN uggBj5mxfX1zowKqi4DPqpHjSWpsF5PIH1GNv+KWDEkDtfj0UcOHM9dX2LFR939R uNzdPwRpDSonbfrMVzkOAOJtqTTgqq2DpjsCA2+5zF1k+/k09GU6zcSiDNdtNBeM K7pq7/ZlwqkuvXmfzV+++mzS0I4B0JAOFIHNGgK3rGBDM4eqfCJJYJaaaiBZeSGj ks1FWXpH2YXW0BHLdcMR =RWuk -----END PGP SIGNATURE----- --Apple-Mail=_7B8A5A89-04AD-47AD-AF26-6952FEB25191--