1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-18 02:19:39 +00:00

bhyvectl: print a better error message when vm_open() fails

libvmm: explicitly save and restore errno in vm_open()

Use errno to print a more descriptive error message when vm_open() fails

PR:             250671
Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D29109

(cherry picked from commit 6bb140e3ca)
(cherry picked from commit a7f81b488d)
This commit is contained in:
Marko 2021-03-06 21:19:30 -09:00 committed by Robert Wing
parent 6aee785518
commit 3f65cb8fda
2 changed files with 7 additions and 2 deletions

View File

@ -118,6 +118,7 @@ struct vmctx *
vm_open(const char *name)
{
struct vmctx *vm;
int saved_errno;
vm = malloc(sizeof(struct vmctx) + strlen(name) + 1);
assert(vm != NULL);
@ -133,7 +134,9 @@ vm_open(const char *name)
return (vm);
err:
vm_destroy(vm);
saved_errno = errno;
free(vm);
errno = saved_errno;
return (NULL);
}

View File

@ -1960,7 +1960,9 @@ main(int argc, char *argv[])
if (!error) {
ctx = vm_open(vmname);
if (ctx == NULL) {
printf("VM:%s is not created.\n", vmname);
fprintf(stderr,
"vm_open: %s could not be opened: %s\n",
vmname, strerror(errno));
exit (1);
}
}