Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F160128011
D53730.id166352.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
11 KB
Referenced Files
None
Subscribers
None
D53730.id166352.diff
View Options
diff --git a/usr.sbin/bhyve/aarch64/bhyverun_machdep.c b/usr.sbin/bhyve/aarch64/bhyverun_machdep.c
--- a/usr.sbin/bhyve/aarch64/bhyverun_machdep.c
+++ b/usr.sbin/bhyve/aarch64/bhyverun_machdep.c
@@ -168,7 +168,7 @@
pci_print_supported_devices();
exit(0);
} else if (pci_parse_slot(optarg) != 0)
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
else
break;
case 'S':
diff --git a/usr.sbin/bhyve/aarch64/vmexit.c b/usr.sbin/bhyve/aarch64/vmexit.c
--- a/usr.sbin/bhyve/aarch64/vmexit.c
+++ b/usr.sbin/bhyve/aarch64/vmexit.c
@@ -115,15 +115,15 @@
switch (how) {
case VM_SUSPEND_RESET:
- exit(0);
+ exit(BHYVE_EXIT_RESET);
case VM_SUSPEND_POWEROFF:
if (get_config_bool_default("destroy_on_poweroff", false))
vm_destroy(ctx);
- exit(1);
+ exit(BHYVE_EXIT_POWEROFF);
case VM_SUSPEND_HALT:
- exit(2);
+ exit(BHYVE_EXIT_HALT);
case VM_SUSPEND_DESTROY:
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
default:
fprintf(stderr, "vmexit_suspend: invalid reason %d\n", how);
exit(100);
diff --git a/usr.sbin/bhyve/amd64/bhyverun_machdep.c b/usr.sbin/bhyve/amd64/bhyverun_machdep.c
--- a/usr.sbin/bhyve/amd64/bhyverun_machdep.c
+++ b/usr.sbin/bhyve/amd64/bhyverun_machdep.c
@@ -186,7 +186,7 @@
pci_print_supported_devices();
exit(0);
} else if (pci_parse_slot(optarg) != 0)
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
else
break;
case 'S':
@@ -276,7 +276,7 @@
err = vm_get_capability(vcpu, VM_CAP_HALT_EXIT, &tmp);
if (err < 0) {
EPRINTLN("VM exit on HLT not supported");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
vm_set_capability(vcpu, VM_CAP_HALT_EXIT, 1);
}
@@ -288,7 +288,7 @@
err = vm_get_capability(vcpu, VM_CAP_PAUSE_EXIT, &tmp);
if (err < 0) {
EPRINTLN("SMP mux requested, no pause support");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
vm_set_capability(vcpu, VM_CAP_PAUSE_EXIT, 1);
}
@@ -300,7 +300,7 @@
if (err) {
EPRINTLN("Unable to set x2apic state (%d)", err);
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
vm_set_capability(vcpu, VM_CAP_ENABLE_INVPCID, 1);
diff --git a/usr.sbin/bhyve/amd64/fwctl.c b/usr.sbin/bhyve/amd64/fwctl.c
--- a/usr.sbin/bhyve/amd64/fwctl.c
+++ b/usr.sbin/bhyve/amd64/fwctl.c
@@ -368,7 +368,7 @@
/* Verify size */
if (value < 12) {
printf("msg size error");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
rinfo.req_size = value;
rinfo.req_count = 1;
diff --git a/usr.sbin/bhyve/amd64/vmexit.c b/usr.sbin/bhyve/amd64/vmexit.c
--- a/usr.sbin/bhyve/amd64/vmexit.c
+++ b/usr.sbin/bhyve/amd64/vmexit.c
@@ -409,17 +409,17 @@
switch (how) {
case VM_SUSPEND_RESET:
- exit(0);
+ exit(BHYVE_EXIT_RESET);
case VM_SUSPEND_POWEROFF:
if (get_config_bool_default("destroy_on_poweroff", false))
vm_destroy(ctx);
- exit(1);
+ exit(BHYVE_EXIT_POWEROFF);
case VM_SUSPEND_HALT:
- exit(2);
+ exit(BHYVE_EXIT_HALT);
case VM_SUSPEND_TRIPLEFAULT:
- exit(3);
+ exit(BHYVE_EXIT_TRIPLEFAULT);
case VM_SUSPEND_DESTROY:
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
default:
EPRINTLN("vmexit_suspend: invalid reason %d", how);
exit(100);
diff --git a/usr.sbin/bhyve/bhyverun.h b/usr.sbin/bhyve/bhyverun.h
--- a/usr.sbin/bhyve/bhyverun.h
+++ b/usr.sbin/bhyve/bhyverun.h
@@ -34,6 +34,12 @@
#define VMEXIT_CONTINUE (0)
#define VMEXIT_ABORT (-1)
+#define BHYVE_EXIT_RESET 0
+#define BHYVE_EXIT_POWEROFF 1
+#define BHYVE_EXIT_HALT 2
+#define BHYVE_EXIT_TRIPLEFAULT 3
+#define BHYVE_EXIT_ERROR 4
+
extern int guest_ncpus;
extern uint16_t cpu_cores, cpu_sockets, cpu_threads;
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -477,7 +477,7 @@
value = get_config_value_node(nvl, "cpus");
if (value == NULL) {
EPRINTLN("Missing CPU set for domain %d", dom);
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
parse_cpuset(dom, value, &cpus);
@@ -487,7 +487,7 @@
EPRINTLN(
"Unable to set vCPU %d affinity for domain %d: %s",
cpu, dom, strerror(errno));
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
}
}
@@ -504,7 +504,7 @@
EPRINTLN(
"Unable to set vCPU %d affinity for domain %d: %s",
cpu, 0, strerror(errno));
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
}
}
@@ -562,7 +562,7 @@
vm_loop(vi->ctx, vi->vcpu);
/* We get here if the VM was destroyed asynchronously. */
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
void
@@ -596,7 +596,7 @@
pthread_mutex_lock(&resetcpu_mtx);
if (!CPU_ISSET(vcpu, &cpumask)) {
EPRINTLN("Attempting to delete unknown cpu %d", vcpu);
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
CPU_CLR(vcpu, &cpumask);
@@ -645,7 +645,7 @@
if (exitcode >= VM_EXITCODE_MAX ||
vmexit_handlers[exitcode] == NULL) {
warnx("vm_loop: unexpected exitcode 0x%x", exitcode);
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
rc = (*vmexit_handlers[exitcode])(ctx, vcpu, &vmrun);
@@ -656,7 +656,7 @@
case VMEXIT_ABORT:
abort();
default:
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
}
EPRINTLN("vm_run error %d, errno %d", error, errno);
@@ -816,7 +816,7 @@
if (error) {
fprintf(stderr, "Failed to read checkpoint info from "
"file: '%s'.\n", restore_file);
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
vmname = lookup_vmname(&rstate);
if (vmname != NULL)
@@ -833,7 +833,7 @@
if (get_config_bool_default("config.dump", false)) {
dump_config();
- exit(1);
+ exit(BHYVE_EXIT_POWEROFF);
}
calc_topology();
@@ -855,7 +855,7 @@
if (guest_ncpus < 1) {
fprintf(stderr, "Invalid guest vCPUs (%d)\n", guest_ncpus);
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
#endif
@@ -864,7 +864,7 @@
if (guest_ncpus > max_vcpus) {
fprintf(stderr, "%d vCPUs requested but only %d available\n",
guest_ncpus, max_vcpus);
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
bhyve_init_vcpu(bsp);
@@ -898,17 +898,17 @@
init_mem(guest_ncpus);
init_bootrom(ctx);
if (bhyve_init_platform(ctx, bsp) != 0)
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
if (qemu_fwcfg_init(ctx) != 0) {
fprintf(stderr, "qemu fwcfg initialization error\n");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
if (qemu_fwcfg_add_file("opt/bhyve/hw.ncpu", sizeof(guest_ncpus),
&guest_ncpus) != 0) {
fprintf(stderr, "Could not add qemu fwcfg opt/bhyve/hw.ncpu\n");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
/*
@@ -917,11 +917,11 @@
if (init_pci(ctx) != 0) {
EPRINTLN("Device emulation initialization error: %s",
strerror(errno));
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
if (init_tpm(ctx) != 0) {
EPRINTLN("Failed to init TPM device");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
/*
@@ -946,37 +946,37 @@
FPRINTLN(stdout, "Pausing pci devs...");
if (vm_pause_devices() != 0) {
EPRINTLN("Failed to pause PCI device state.");
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
FPRINTLN(stdout, "Restoring vm mem...");
if (restore_vm_mem(ctx, &rstate) != 0) {
EPRINTLN("Failed to restore VM memory.");
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
FPRINTLN(stdout, "Restoring pci devs...");
if (vm_restore_devices(&rstate) != 0) {
EPRINTLN("Failed to restore PCI device state.");
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
FPRINTLN(stdout, "Restoring kernel structs...");
if (vm_restore_kern_structs(ctx, &rstate) != 0) {
EPRINTLN("Failed to restore kernel structs.");
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
FPRINTLN(stdout, "Resuming pci devs...");
if (vm_resume_devices() != 0) {
EPRINTLN("Failed to resume PCI device state.");
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
}
#endif
if (bhyve_init_platform_late(ctx, bsp) != 0)
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
/*
* Change the proc title to include the VM name.
@@ -1018,5 +1018,5 @@
*/
mevent_dispatch();
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c
--- a/usr.sbin/bhyve/gdb.c
+++ b/usr.sbin/bhyve/gdb.c
@@ -1105,7 +1105,7 @@
if (!gdb_active) {
EPRINTLN("vm_loop: unexpected VMEXIT_DEBUG");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
vcpuid = vcpu_id(vcpu);
pthread_mutex_lock(&gdb_lock);
diff --git a/usr.sbin/bhyve/mevent.c b/usr.sbin/bhyve/mevent.c
--- a/usr.sbin/bhyve/mevent.c
+++ b/usr.sbin/bhyve/mevent.c
@@ -55,6 +55,7 @@
#include <pthread.h>
#include <pthread_np.h>
+#include "bhyverun.h"
#include "mevent.h"
#define MEVENT_MAX 64
@@ -517,7 +518,7 @@
ret = pipe(mevent_pipefd);
if (ret < 0) {
perror("pipe");
- exit(0);
+ exit(BHYVE_EXIT_ERROR);
}
#ifndef WITHOUT_CAPSICUM
diff --git a/usr.sbin/bhyve/mevent_test.c b/usr.sbin/bhyve/mevent_test.c
--- a/usr.sbin/bhyve/mevent_test.c
+++ b/usr.sbin/bhyve/mevent_test.c
@@ -45,6 +45,7 @@
#include <pthread.h>
#include <unistd.h>
+#include "bhyverun.h"
#include "mevent.h"
#define TEST_PORT 4321
@@ -139,7 +140,7 @@
mev = mevent_add(fd, EVF_READ, echoer_callback, &sync);
if (mev == NULL) {
printf("Could not allocate echoer event\n");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
while (!pthread_cond_wait(&sync.e_cond, &sync.e_mt)) {
@@ -197,7 +198,7 @@
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("cannot create socket");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
sin.sin_len = sizeof(sin);
@@ -207,12 +208,12 @@
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
perror("cannot bind socket");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
if (listen(s, 1) < 0) {
perror("cannot listen socket");
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
}
(void) mevent_add(s, EVF_READ, acceptor_callback, NULL);
diff --git a/usr.sbin/bhyve/net_backend_slirp.c b/usr.sbin/bhyve/net_backend_slirp.c
--- a/usr.sbin/bhyve/net_backend_slirp.c
+++ b/usr.sbin/bhyve/net_backend_slirp.c
@@ -59,6 +59,7 @@
#include <string.h>
#include <unistd.h>
+#include "bhyverun.h"
#include "config.h"
#include "debug.h"
#include "libslirp.h"
@@ -372,7 +373,7 @@
error = poll(pollfds, npollfds, timeout);
if (error == -1 && errno != EINTR) {
EPRINTLN("poll: %s", strerror(errno));
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
pthread_mutex_lock(&priv->mtx);
slirp_pollfds_poll_p(priv->slirp, error == -1,
@@ -392,7 +393,7 @@
} while (n == 1);
if (n != -1 || errno != EAGAIN) {
EPRINTLN("read(wakeup): %s", strerror(errno));
- exit(1);
+ exit(BHYVE_EXIT_ERROR);
}
}
}
diff --git a/usr.sbin/bhyve/riscv/bhyverun_machdep.c b/usr.sbin/bhyve/riscv/bhyverun_machdep.c
--- a/usr.sbin/bhyve/riscv/bhyverun_machdep.c
+++ b/usr.sbin/bhyve/riscv/bhyverun_machdep.c
@@ -159,7 +159,7 @@
pci_print_supported_devices();
exit(0);
} else if (pci_parse_slot(optarg) != 0)
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
else
break;
case 'S':
diff --git a/usr.sbin/bhyve/riscv/vmexit.c b/usr.sbin/bhyve/riscv/vmexit.c
--- a/usr.sbin/bhyve/riscv/vmexit.c
+++ b/usr.sbin/bhyve/riscv/vmexit.c
@@ -114,15 +114,15 @@
switch (how) {
case VM_SUSPEND_RESET:
- exit(0);
+ exit(BHYVE_EXIT_RESET);
case VM_SUSPEND_POWEROFF:
if (get_config_bool_default("destroy_on_poweroff", false))
vm_destroy(ctx);
- exit(1);
+ exit(BHYVE_EXIT_POWEROFF);
case VM_SUSPEND_HALT:
- exit(2);
+ exit(BHYVE_EXIT_HALT);
case VM_SUSPEND_DESTROY:
- exit(4);
+ exit(BHYVE_EXIT_ERROR);
default:
fprintf(stderr, "vmexit_suspend: invalid reason %d\n", how);
exit(100);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jun 22, 3:18 PM (18 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34170120
Default Alt Text
D53730.id166352.diff (11 KB)
Attached To
Mode
D53730: bhyve: Eliminate exit status magic numbers
Attached
Detach File
Event Timeline
Log In to Comment