[libvirt] [PATCH] Ensure binary is resolved wrt $PATH in virExec
Eric Blake
eblake at redhat.com
Tue Mar 15 17:41:24 UTC 2011
On 03/15/2011 11:14 AM, Daniel P. Berrange wrote:
> virExec would only resolved the binary to $PATH if no env
> variables were being set. Since there is no execvep() API
> in POSIX, we use virFindFileInPath to manually resolve
> the binary and then use execv() instead of execvp().
It might be worth a gnulib module for execvpe (of course, such a module
would fail with ENOSYS on mingw, so we'd still have to have a
WIN32-specific fallback for virExec). But that can be another day.
> +++ b/src/util/util.c
> @@ -475,6 +475,18 @@ __virExec(const char *const*argv,
> int childout = -1;
> int childerr = -1;
> int tmpfd;
> + const char *binary = NULL;
> +
> + if (argv[0][0] != '/') {
> + if (!(binary = virFindFileInPath(argv[0]))) {
> + virReportSystemError(ENOENT,
> + _("Cannot find '%s' in path"),
> + argv[0]);
> + return -1;
> + }
> + } else {
> + binary = argv[0];
> + }
>
> if ((null = open("/dev/null", O_RDWR)) < 0) {
> virReportSystemError(errno,
> @@ -694,9 +706,9 @@ __virExec(const char *const*argv,
> virLogReset();
>
> if (envp)
> - execve(argv[0], (char **) argv, (char**)envp);
> + execve(binary, (char **) argv, (char**)envp);
> else
> - execvp(argv[0], (char **) argv);
> + execv(binary, (char **) argv);
>
> virReportSystemError(errno,
> _("cannot execute binary %s"),
Memory leak in the parent, and in the child on failure to exec. (The
child leak is less important - it's about to _exit anyways). You need
this in at least the parent some point after the fork:
if (binary != argv[0])
VIR_FREE(binary);
ACK with that nit fixed.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110315/a7960487/attachment-0001.sig>
More information about the libvir-list
mailing list