[iwhd patch 2/2] error to stderr

Pete Zaitcev zaitcev at redhat.com
Thu Nov 18 15:45:41 UTC 2010


On Thu, 18 Nov 2010 09:14:17 -0500
Jeff Darcy <jdarcy at redhat.com> wrote:

> On 11/17/2010 07:30 PM, Pete Zaitcev wrote:
> > This is useless in production, since backend.c dups the same pipe to both
> > stderr and stdout. However it is marginally uselful in debugging if they
> > are redirected by a developer.
> > 
> > OK, I admit it: this feels more "correct".
> 
> ACK to both.  Good to see you're making this better.

These just to make patches smaller. I was looking at something like this:

diff --git a/dc-register-image b/dc-register-image
index 3192f32..a6a3ea8 100755
--- a/dc-register-image
+++ b/dc-register-image
@@ -29,10 +29,42 @@ ami_bkt=$1; shift
 kernel=$1; shift
 ramdisk=$1; shift
 
-# TBD: figure out what to do about these paths.
-export EC2_HOME=~/jdarcy/ec2-api-tools-1.3-53907
-export PATH=$PATH:$EC2_HOME/bin
-export JAVA_HOME=/usr
+# We do not accept anything like EC2_HOME because ec2 tools come from two
+# independent packages: ec2-register belongs to ec2-api-tools (Java; packaged
+# by RPMFusion for F12+) and ec2-bundle-image belongs to ec2-ami-tools
+# (Ruby; packaged by Amazon as a distro-clean noarch RPM). And their
+# prefixes can be different, because Amazon managed to use /usr/local.
+#
+# If you are one of the people who merge the two into something like
+# ~/jdarcy/ec2-api-tools-1.3-53907, we suggest symlinking them from ~/bin.
+
+which_it () {
+	cmd=$1
+	ret=$(/usr/bin/which $cmd 2>/dev/null)
+	if [ $? != 0 ]; then
+		if [ -x /usr/local/bin/$cmd ]; then
+			ret=/usr/local/bin/$cmd
+		elif [ -x ~/bin/$cmd ]; then
+			ret=~/bin/$cmd
+		fi
+	fi
+	if [ -z "$ret" ]; then
+		echo "ERROR missing_$cmd" >&2
+		exit 1
+	fi
+	echo $ret
+}
+
+ec2_bundle_image=$(which_it ec2-bundle-image)
+ec2_upload_bundle=$(which_it ec2-upload-bundle)
+ec2_register=$(which_it ec2-register)
+[ -z "$ec2_bundle_image" -o -z "$ec2_upload_bundle" -o -z "$ec2_register" ] && exit 1
+
+# Do not override JAVA_HOME silently from a script. If it is not set,
+# jpackage's /usr/share/java-utils/java-functions sets it for us.
+# This allows user to supply his own. This is not a good place to
+# institute a protection against environment-substitution attacks.
+#export JAVA_HOME=/usr
 
 tmpdir=$(mktemp -d -p $PWD/$bucket) || exit 1
 trap "rm -rf $tmpdir" EXIT
@@ -44,25 +76,25 @@ fi
 if [ "$ramdisk" != "_default_" ]; then
 	bundle_args="$bundle_args --ramdisk $ramdisk"
 fi
-$ECHO ec2-bundle-image -i $bucket/$object -d $tmpdir $bundle_args
+$ECHO $ec2_bundle_image -i $bucket/$object -d $tmpdir $bundle_args
 if [ $? != 0 ]; then
 	echo "ERROR bundling_failed" >&2
-	echo ec2-bundle-image -i $bucket/$object -d $tmpdir $bundle_args >&2
+	echo $ec2_bundle_image -i $bucket/$object -d $tmpdir $bundle_args >&2
 	exit 1
 fi
 
 upload_args="--batch --retry -b $ami_bkt -a $api_key -s $api_secret"
-$ECHO ec2-upload-bundle -m $tmpdir/$object.manifest.xml $upload_args
+$ECHO $ec2_upload_bundle -m $tmpdir/$object.manifest.xml $upload_args
 if [ $? != 0 ]; then
 	echo "ERROR uploading_failed" >&2
-	echo ec2-upload-bundle -m $tmpdir/$object.manifest.xml $upload_args >&2
+	echo $ec2_upload_bundle -m $tmpdir/$object.manifest.xml $upload_args >&2
 	exit 1
 fi
 
 register_args="-C $cert_file -K $key_file"
-$ECHO ec2-register $register_args $ami_bkt/$object.manifest.xml -n $object
+$ECHO $ec2_register $register_args $ami_bkt/$object.manifest.xml -n $object
 if [ $? != 0 ]; then
 	echo "ERROR registration_failed" >&2
-	echo ec2-register $register_args $ami_bkt/$object.manifest.xml -n $object >&2
+	echo $ec2_register $register_args $ami_bkt/$object.manifest.xml -n $object >&2
 	exit 1
 fi


It is someting I wanted to clear with you because I am trying to force
you to symlink your local install from your ~/bin _or_ switch to using
a combination of pre-packaged tools (e.g. yum install ec2-api-tools
and rpm -i ec2-ami-tools -- there's no repo for ec2-ami-tools).

-- Pete


More information about the iwhd-devel mailing list