On Mon, Aug 24, 2009 at 06:16:06PM +0200, Jim Meyering wrote:
Richard W.M. Jones wrote:
On Mon, Aug 24, 2009 at 06:00:19PM +0200, Jim Meyering wrote:
@@ -186,6 +201,11 @@ main (int argc, char *argv[]) (argv[0][0] != '/' || strstr (argv[0], "/.libs/lt-") != NULL)) guestfs_set_path (g, "appliance:" GUESTFS_DEFAULT_PATH);
+ /* getopt_long uses argv[0], so give it the sanitized name, too. + But only temporarily. */ + char *real_argv0 = argv[0]; + argv[0] = bad_cast (program_name);
ACK. Do you think you could change that comment to make it really clear that this piece of code mustn't ever move above the path munging done in the preceeding lines.
Sure. Here's the incremental:
diff --git a/fish/fish.c b/fish/fish.c index e799f86..91c5dad 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -201,8 +201,12 @@ main (int argc, char *argv[]) (argv[0][0] != '/' || strstr (argv[0], "/.libs/lt-") != NULL)) guestfs_set_path (g, "appliance:" GUESTFS_DEFAULT_PATH);
- /* getopt_long uses argv[0], so give it the sanitized name, too. - But only temporarily. */ + /* CAUTION: we are careful to modify argv[0] here, only after + * using it just above. + * + * getopt_long uses argv[0], so give it the sanitized name. Save a copy + * of the original, in case it's needed in virt-inspector mode, below. + */ char *real_argv0 = argv[0]; argv[0] = bad_cast (program_name);
Yes, this comment is a great improvement I think. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v