[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH V3] virt-diff: add new virt-diff tool



On Tue, Aug 21, 2012 at 04:04:54PM +0800, Wanlong Gao wrote:
[...]
> >> +  spid = fork ();
> >> +  if (spid == -1) {
> >> +    perror ("fork");
> >> +    exit (EXIT_FAILURE);
> >> +  }
> >> +  if (spid == 0) {
> >> +    if (guestfs_mount_local_run (sg) == -1)
> >> +      exit (EXIT_FAILURE);
> >> +    _exit (EXIT_SUCCESS);
> >> +  }
> >> +
> >> +  dpid = fork();
> >> +  if (dpid == -1) {
> >> +    perror ("fork");
> >> +    exit (EXIT_FAILURE);
> >> +  }
> >> +  if (dpid == 0) {
> >> +    if (guestfs_mount_local_run (dg) == -1)
> >> +      exit (EXIT_FAILURE);
> >> +    _exit (EXIT_SUCCESS);
> >> +  }
> >> +
> >> +  const char *dir = argv[optind];
> >> +  char system_arg[BUFSIZ];
> >> +  sprintf (system_arg, "diff -urN %s%s %s%s", stempdir, dir,
> >> +                                              dtempdir, dir);
> >> +  sleep (5);
> > 
> > ?
> 
> I think I'm waiting for guest launching?

No, that's the wrong thing to do.

The API is in two parts: First guestfs_mount_local prepares the mount
point.  Second guestfs_mount_local_run causes requests to be
processed.

You can access the mount point after guestfs_mount_local has returned.
Your process will block until guestfs_mount_local_run is called, but
that doesn't matter in this case (in fact, it's what you want).

Another thing: Don't use sprintf, ever.  With the wrong $TMPDIR that
code above is a security hole.  Since you need to quote 'dir' (since
it comes from user input) you're going to have to rewrite the whole
call to system(3) so that it uses fork + exec instead.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]