diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c --- a/usr.sbin/bhyveload/bhyveload.c +++ b/usr.sbin/bhyveload/bhyveload.c @@ -89,6 +89,16 @@ #define NDISKS 32 +/* + * Reason for our loader reload and reentry, though these aren't really used + * at the moment. + */ +enum { + /* 0 cannot be allocated; setjmp(3) return. */ + JMP_SWAPLOADER = 0x01, + JMP_REBOOT, +}; + static struct termios term, oldterm; static int disk_fd[NDISKS]; static int ndisks; @@ -543,6 +553,8 @@ { tcsetattr(consout_fd, TCSAFLUSH, &oldterm); + if (v == USERBOOT_EXIT_REBOOT) + longjmp(jb, JMP_REBOOT); exit(v); } @@ -628,7 +640,7 @@ if (asprintf(&loader, "userboot_%s.so", interp_req) == -1) err(EX_OSERR, "malloc"); - longjmp(jb, 1); + longjmp(jb, JMP_SWAPLOADER); } static struct loader_callbacks cb = { @@ -764,6 +776,8 @@ loader_hdl = fdlopen(fd, RTLD_LOCAL); if (!loader_hdl) errx(EX_OSERR, "dlopen: %s", dlerror()); + if (fd != explicit_loader_fd) + close(fd); } int