From 7090abf5251f1deda0ac0d82a07797f56bbb1343 Mon Sep 17 00:00:00 2001 From: "David E. O'Brien" Date: Tue, 18 Jul 2000 09:14:06 +0000 Subject: [PATCH] Allow the Fix-it functionality to detect that we are on a serial console, and DTRT rather than start the fixit shell on a non-existant vty. PR: 19837 Submitted by: Doug Ambrisko Approved by: JKH --- release/sysinstall/install.c | 5 ++++ release/sysinstall/sysinstall.h | 3 ++ release/sysinstall/system.c | 51 ++++++++++++++++++++++++++++---- usr.sbin/sade/install.c | 5 ++++ usr.sbin/sade/sade.h | 3 ++ usr.sbin/sade/system.c | 51 ++++++++++++++++++++++++++++---- usr.sbin/sysinstall/install.c | 5 ++++ usr.sbin/sysinstall/sysinstall.h | 3 ++ usr.sbin/sysinstall/system.c | 51 ++++++++++++++++++++++++++++---- 9 files changed, 159 insertions(+), 18 deletions(-) diff --git a/release/sysinstall/install.c b/release/sysinstall/install.c index ac3b01390c16..209c210e22b2 100644 --- a/release/sysinstall/install.c +++ b/release/sysinstall/install.c @@ -56,6 +56,7 @@ * Used by package.c */ int _interactiveHack; +int FixItMode = 0; static void create_termcap(void); static void fixit_common(void); @@ -248,8 +249,10 @@ installInitial(void) int installFixitHoloShell(dialogMenuItem *self) { + FixItMode = 1; systemCreateHoloshell(); return DITEM_SUCCESS; + FixItMode = 0; } int @@ -397,6 +400,8 @@ fixit_common(void) msgConfirm("Couldn't symlink the /etc/ files! I'm not sure I like this.."); if (!file_readable(TERMCAP_FILE)) create_termcap(); + if (!OnVTY) + systemSuspendDialog(); /* must be before the fork() */ if (!(child = fork())) { int i, fd, fdstop; struct termios foo; diff --git a/release/sysinstall/sysinstall.h b/release/sysinstall/sysinstall.h index e34735a74c90..abb2b8e147f7 100644 --- a/release/sysinstall/sysinstall.h +++ b/release/sysinstall/sysinstall.h @@ -402,6 +402,7 @@ extern DMenu MenuHTMLDoc; /* HTML Documentation menu */ extern DMenu MenuUsermgmt; /* User management menu */ extern DMenu MenuFixit; /* Fixit floppy/CDROM/shell menu */ extern DMenu MenuXF86Config; /* Select XFree86 configuration type */ +extern int FixItMode; /* FixItMode starts shell onc urrent device (ie Serial port) */ /* Stuff from libdialog which isn't properly declared outside */ extern void display_helpfile(void); @@ -711,6 +712,8 @@ extern void systemInitialize(int argc, char **argv); extern void systemShutdown(int status); extern int execExecute(char *cmd, char *name); extern int systemExecute(char *cmd); +extern void systemSuspendDialog(void); +extern void systemResumeDialog(void); extern int systemDisplayHelp(char *file); extern char *systemHelpFile(char *file, char *buf); extern void systemChangeFont(const u_char font[]); diff --git a/release/sysinstall/system.c b/release/sysinstall/system.c index d0daba3c1c91..6010e7a25f8d 100644 --- a/release/sysinstall/system.c +++ b/release/sysinstall/system.c @@ -217,6 +217,28 @@ systemExecute(char *command) return status; } +/* suspend/resume libdialog/curses screen */ +static WINDOW *oldW; + +void +systemSuspendDialog(void) +{ + + oldW = savescr(); + dialog_clear(); + dialog_update(); + end_dialog(); + DialogActive = FALSE; +} + +void +systemResumeDialog(void) +{ + + DialogActive = TRUE; + restorescr(oldW); +} + /* Display a help file in a filebox */ int systemDisplayHelp(char *file) @@ -355,7 +377,9 @@ vsystem(char *fmt, ...) void systemCreateHoloshell(void) { - if (OnVTY && RunningAsInit) { + int waitstatus; + + if ((FixItMode || OnVTY) && RunningAsInit) { if (ehs_pid != 0) { int pstat; @@ -377,6 +401,8 @@ systemCreateHoloshell(void) (void) waitpid(ehs_pid, &pstat, WNOHANG); } + if (!OnVTY) + systemSuspendDialog(); /* must be before the fork() */ if ((ehs_pid = fork()) == 0) { int i, fd; struct termios foo; @@ -385,7 +411,10 @@ systemCreateHoloshell(void) ioctl(0, TIOCNOTTY, NULL); for (i = getdtablesize(); i >= 0; --i) close(i); - fd = open("/dev/ttyv3", O_RDWR); + if (OnVTY) + fd = open("/dev/ttyv3", O_RDWR); + else + fd = open("/dev/console", O_RDWR); ioctl(0, TIOCSCTTY, &fd); dup2(0, 1); dup2(0, 2); @@ -400,16 +429,26 @@ systemCreateHoloshell(void) } else msgDebug("Doctor: I'm unable to get the terminal attributes!\n"); + if (!OnVTY){ + printf("Type ``exit'' in this fixit shell to resume sysinstall.\n\n"); + fflush(stdout); + } execlp("sh", "-sh", 0); msgDebug("Was unable to execute sh for Holographic shell!\n"); exit(1); } else { - WINDOW *w = savescr(); + if (OnVTY) { + WINDOW *w = savescr(); - msgNotify("Starting an emergency holographic shell on VTY4"); - sleep(2); - restorescr(w); + msgNotify("Starting an emergency holographic shell on VTY4"); + sleep(2); + restorescr(w); + } + if (!OnVTY){ + (void)waitpid(ehs_pid, &waitstatus, 0); + systemResumeDialog(); + } } } } diff --git a/usr.sbin/sade/install.c b/usr.sbin/sade/install.c index ac3b01390c16..209c210e22b2 100644 --- a/usr.sbin/sade/install.c +++ b/usr.sbin/sade/install.c @@ -56,6 +56,7 @@ * Used by package.c */ int _interactiveHack; +int FixItMode = 0; static void create_termcap(void); static void fixit_common(void); @@ -248,8 +249,10 @@ installInitial(void) int installFixitHoloShell(dialogMenuItem *self) { + FixItMode = 1; systemCreateHoloshell(); return DITEM_SUCCESS; + FixItMode = 0; } int @@ -397,6 +400,8 @@ fixit_common(void) msgConfirm("Couldn't symlink the /etc/ files! I'm not sure I like this.."); if (!file_readable(TERMCAP_FILE)) create_termcap(); + if (!OnVTY) + systemSuspendDialog(); /* must be before the fork() */ if (!(child = fork())) { int i, fd, fdstop; struct termios foo; diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h index e34735a74c90..abb2b8e147f7 100644 --- a/usr.sbin/sade/sade.h +++ b/usr.sbin/sade/sade.h @@ -402,6 +402,7 @@ extern DMenu MenuHTMLDoc; /* HTML Documentation menu */ extern DMenu MenuUsermgmt; /* User management menu */ extern DMenu MenuFixit; /* Fixit floppy/CDROM/shell menu */ extern DMenu MenuXF86Config; /* Select XFree86 configuration type */ +extern int FixItMode; /* FixItMode starts shell onc urrent device (ie Serial port) */ /* Stuff from libdialog which isn't properly declared outside */ extern void display_helpfile(void); @@ -711,6 +712,8 @@ extern void systemInitialize(int argc, char **argv); extern void systemShutdown(int status); extern int execExecute(char *cmd, char *name); extern int systemExecute(char *cmd); +extern void systemSuspendDialog(void); +extern void systemResumeDialog(void); extern int systemDisplayHelp(char *file); extern char *systemHelpFile(char *file, char *buf); extern void systemChangeFont(const u_char font[]); diff --git a/usr.sbin/sade/system.c b/usr.sbin/sade/system.c index d0daba3c1c91..6010e7a25f8d 100644 --- a/usr.sbin/sade/system.c +++ b/usr.sbin/sade/system.c @@ -217,6 +217,28 @@ systemExecute(char *command) return status; } +/* suspend/resume libdialog/curses screen */ +static WINDOW *oldW; + +void +systemSuspendDialog(void) +{ + + oldW = savescr(); + dialog_clear(); + dialog_update(); + end_dialog(); + DialogActive = FALSE; +} + +void +systemResumeDialog(void) +{ + + DialogActive = TRUE; + restorescr(oldW); +} + /* Display a help file in a filebox */ int systemDisplayHelp(char *file) @@ -355,7 +377,9 @@ vsystem(char *fmt, ...) void systemCreateHoloshell(void) { - if (OnVTY && RunningAsInit) { + int waitstatus; + + if ((FixItMode || OnVTY) && RunningAsInit) { if (ehs_pid != 0) { int pstat; @@ -377,6 +401,8 @@ systemCreateHoloshell(void) (void) waitpid(ehs_pid, &pstat, WNOHANG); } + if (!OnVTY) + systemSuspendDialog(); /* must be before the fork() */ if ((ehs_pid = fork()) == 0) { int i, fd; struct termios foo; @@ -385,7 +411,10 @@ systemCreateHoloshell(void) ioctl(0, TIOCNOTTY, NULL); for (i = getdtablesize(); i >= 0; --i) close(i); - fd = open("/dev/ttyv3", O_RDWR); + if (OnVTY) + fd = open("/dev/ttyv3", O_RDWR); + else + fd = open("/dev/console", O_RDWR); ioctl(0, TIOCSCTTY, &fd); dup2(0, 1); dup2(0, 2); @@ -400,16 +429,26 @@ systemCreateHoloshell(void) } else msgDebug("Doctor: I'm unable to get the terminal attributes!\n"); + if (!OnVTY){ + printf("Type ``exit'' in this fixit shell to resume sysinstall.\n\n"); + fflush(stdout); + } execlp("sh", "-sh", 0); msgDebug("Was unable to execute sh for Holographic shell!\n"); exit(1); } else { - WINDOW *w = savescr(); + if (OnVTY) { + WINDOW *w = savescr(); - msgNotify("Starting an emergency holographic shell on VTY4"); - sleep(2); - restorescr(w); + msgNotify("Starting an emergency holographic shell on VTY4"); + sleep(2); + restorescr(w); + } + if (!OnVTY){ + (void)waitpid(ehs_pid, &waitstatus, 0); + systemResumeDialog(); + } } } } diff --git a/usr.sbin/sysinstall/install.c b/usr.sbin/sysinstall/install.c index ac3b01390c16..209c210e22b2 100644 --- a/usr.sbin/sysinstall/install.c +++ b/usr.sbin/sysinstall/install.c @@ -56,6 +56,7 @@ * Used by package.c */ int _interactiveHack; +int FixItMode = 0; static void create_termcap(void); static void fixit_common(void); @@ -248,8 +249,10 @@ installInitial(void) int installFixitHoloShell(dialogMenuItem *self) { + FixItMode = 1; systemCreateHoloshell(); return DITEM_SUCCESS; + FixItMode = 0; } int @@ -397,6 +400,8 @@ fixit_common(void) msgConfirm("Couldn't symlink the /etc/ files! I'm not sure I like this.."); if (!file_readable(TERMCAP_FILE)) create_termcap(); + if (!OnVTY) + systemSuspendDialog(); /* must be before the fork() */ if (!(child = fork())) { int i, fd, fdstop; struct termios foo; diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h index e34735a74c90..abb2b8e147f7 100644 --- a/usr.sbin/sysinstall/sysinstall.h +++ b/usr.sbin/sysinstall/sysinstall.h @@ -402,6 +402,7 @@ extern DMenu MenuHTMLDoc; /* HTML Documentation menu */ extern DMenu MenuUsermgmt; /* User management menu */ extern DMenu MenuFixit; /* Fixit floppy/CDROM/shell menu */ extern DMenu MenuXF86Config; /* Select XFree86 configuration type */ +extern int FixItMode; /* FixItMode starts shell onc urrent device (ie Serial port) */ /* Stuff from libdialog which isn't properly declared outside */ extern void display_helpfile(void); @@ -711,6 +712,8 @@ extern void systemInitialize(int argc, char **argv); extern void systemShutdown(int status); extern int execExecute(char *cmd, char *name); extern int systemExecute(char *cmd); +extern void systemSuspendDialog(void); +extern void systemResumeDialog(void); extern int systemDisplayHelp(char *file); extern char *systemHelpFile(char *file, char *buf); extern void systemChangeFont(const u_char font[]); diff --git a/usr.sbin/sysinstall/system.c b/usr.sbin/sysinstall/system.c index d0daba3c1c91..6010e7a25f8d 100644 --- a/usr.sbin/sysinstall/system.c +++ b/usr.sbin/sysinstall/system.c @@ -217,6 +217,28 @@ systemExecute(char *command) return status; } +/* suspend/resume libdialog/curses screen */ +static WINDOW *oldW; + +void +systemSuspendDialog(void) +{ + + oldW = savescr(); + dialog_clear(); + dialog_update(); + end_dialog(); + DialogActive = FALSE; +} + +void +systemResumeDialog(void) +{ + + DialogActive = TRUE; + restorescr(oldW); +} + /* Display a help file in a filebox */ int systemDisplayHelp(char *file) @@ -355,7 +377,9 @@ vsystem(char *fmt, ...) void systemCreateHoloshell(void) { - if (OnVTY && RunningAsInit) { + int waitstatus; + + if ((FixItMode || OnVTY) && RunningAsInit) { if (ehs_pid != 0) { int pstat; @@ -377,6 +401,8 @@ systemCreateHoloshell(void) (void) waitpid(ehs_pid, &pstat, WNOHANG); } + if (!OnVTY) + systemSuspendDialog(); /* must be before the fork() */ if ((ehs_pid = fork()) == 0) { int i, fd; struct termios foo; @@ -385,7 +411,10 @@ systemCreateHoloshell(void) ioctl(0, TIOCNOTTY, NULL); for (i = getdtablesize(); i >= 0; --i) close(i); - fd = open("/dev/ttyv3", O_RDWR); + if (OnVTY) + fd = open("/dev/ttyv3", O_RDWR); + else + fd = open("/dev/console", O_RDWR); ioctl(0, TIOCSCTTY, &fd); dup2(0, 1); dup2(0, 2); @@ -400,16 +429,26 @@ systemCreateHoloshell(void) } else msgDebug("Doctor: I'm unable to get the terminal attributes!\n"); + if (!OnVTY){ + printf("Type ``exit'' in this fixit shell to resume sysinstall.\n\n"); + fflush(stdout); + } execlp("sh", "-sh", 0); msgDebug("Was unable to execute sh for Holographic shell!\n"); exit(1); } else { - WINDOW *w = savescr(); + if (OnVTY) { + WINDOW *w = savescr(); - msgNotify("Starting an emergency holographic shell on VTY4"); - sleep(2); - restorescr(w); + msgNotify("Starting an emergency holographic shell on VTY4"); + sleep(2); + restorescr(w); + } + if (!OnVTY){ + (void)waitpid(ehs_pid, &waitstatus, 0); + systemResumeDialog(); + } } } }