1995-04-27 12:50:35 +00:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-04-27 12:50:35 +00:00
|
|
|
*
|
|
|
|
* Jordan Hubbard
|
|
|
|
*
|
|
|
|
* My contributions are in the public domain.
|
|
|
|
*
|
|
|
|
* Parts of this file are also blatently stolen from Poul-Henning Kamp's
|
1995-05-19 16:58:58 +00:00
|
|
|
* previous version of sysinstall, and as such fall under his "BEERWARE license"
|
|
|
|
* so buy him a beer if you like it! Buy him a beer for me, too!
|
|
|
|
* Heck, get him completely drunk and send me pictures! :-)
|
1995-04-27 12:50:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinstall.h"
|
|
|
|
#include <signal.h>
|
1999-09-04 16:01:15 +00:00
|
|
|
#include <termios.h>
|
1995-04-27 12:50:35 +00:00
|
|
|
#include <sys/reboot.h>
|
2000-10-08 21:34:00 +00:00
|
|
|
#include <sys/consio.h>
|
1995-04-27 12:50:35 +00:00
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
1999-01-08 09:13:00 +00:00
|
|
|
#include <sys/stat.h>
|
2000-03-25 04:23:08 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
1995-04-27 12:50:35 +00:00
|
|
|
|
1996-07-05 08:36:02 +00:00
|
|
|
|
|
|
|
/* Where we stick our temporary expanded doc file */
|
1999-01-08 09:13:00 +00:00
|
|
|
#define DOC_TMP_DIR "/tmp/.doc"
|
|
|
|
#define DOC_TMP_FILE "/tmp/.doc/doc.tmp"
|
1996-07-05 08:36:02 +00:00
|
|
|
|
1996-12-29 05:51:40 +00:00
|
|
|
static pid_t ehs_pid;
|
|
|
|
|
1995-05-05 23:47:47 +00:00
|
|
|
/*
|
|
|
|
* Handle interrupt signals - this probably won't work in all cases
|
|
|
|
* due to our having bogotified the internal state of dialog or curses,
|
|
|
|
* but we'll give it a try.
|
|
|
|
*/
|
2000-10-29 09:57:50 +00:00
|
|
|
static int
|
|
|
|
intr_continue(dialogMenuItem *self)
|
|
|
|
{
|
2001-09-14 08:39:22 +00:00
|
|
|
return DITEM_LEAVE_MENU;
|
2000-10-29 09:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
intr_reboot(dialogMenuItem *self)
|
|
|
|
{
|
2001-09-14 08:39:22 +00:00
|
|
|
systemShutdown(-1);
|
|
|
|
/* NOTREACHED */
|
|
|
|
return 0;
|
2000-10-29 09:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
intr_restart(dialogMenuItem *self)
|
|
|
|
{
|
2001-09-30 00:43:32 +00:00
|
|
|
int ret, fd, fdmax;
|
|
|
|
|
|
|
|
mediaClose();
|
2001-09-22 18:10:56 +00:00
|
|
|
free_variables();
|
2001-09-30 00:43:32 +00:00
|
|
|
fdmax = getdtablesize();
|
|
|
|
for (fd = 3; fd < fdmax; fd++)
|
|
|
|
close(fd);
|
2001-10-12 07:36:34 +00:00
|
|
|
ret = execl(StartName, StartName, "-restart", (char *)NULL);
|
2001-09-22 18:10:56 +00:00
|
|
|
msgDebug("execl failed (%s)\n", strerror(errno));
|
2001-09-14 08:39:22 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
return -1;
|
2000-10-29 09:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static dialogMenuItem intrmenu[] = {
|
2001-09-14 08:39:22 +00:00
|
|
|
{ "Abort", "Abort the installation", NULL, intr_reboot },
|
|
|
|
{ "Restart", "Restart the installation program", NULL, intr_restart },
|
|
|
|
{ "Continue", "Continue the installation", NULL, intr_continue },
|
2000-10-29 09:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1995-04-27 12:50:35 +00:00
|
|
|
static void
|
|
|
|
handle_intr(int sig)
|
|
|
|
{
|
1996-10-01 12:13:29 +00:00
|
|
|
WINDOW *save = savescr();
|
|
|
|
|
2000-10-29 09:57:50 +00:00
|
|
|
use_helpline(NULL);
|
|
|
|
use_helpfile(NULL);
|
|
|
|
if (OnVTY) {
|
|
|
|
ioctl(0, VT_ACTIVATE, 1); /* Switch back */
|
|
|
|
msgInfo(NULL);
|
|
|
|
}
|
|
|
|
(void)dialog_menu("Installation interrupt",
|
|
|
|
"Do you want to abort the installation?",
|
|
|
|
-1, -1, 3, -3, intrmenu, NULL, NULL, NULL);
|
|
|
|
restorescr(save);
|
1995-04-27 12:50:35 +00:00
|
|
|
}
|
|
|
|
|
2001-09-06 09:53:53 +00:00
|
|
|
/*
|
|
|
|
* Harvest children if we are init.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
reap_children(int sig)
|
|
|
|
{
|
|
|
|
int errbak = errno;
|
2001-09-14 08:39:22 +00:00
|
|
|
|
|
|
|
while (waitpid(-1, NULL, WNOHANG) > 0)
|
2001-09-06 09:53:53 +00:00
|
|
|
;
|
|
|
|
errno = errbak;
|
|
|
|
}
|
|
|
|
|
1996-07-05 08:36:02 +00:00
|
|
|
/* Expand a file into a convenient location, nuking it each time */
|
|
|
|
static char *
|
|
|
|
expand(char *fname)
|
|
|
|
{
|
1998-09-30 11:44:29 +00:00
|
|
|
char *gunzip = RunningAsInit ? "/stand/gunzip" : "/usr/bin/gunzip";
|
|
|
|
|
1999-01-08 09:13:00 +00:00
|
|
|
if (!directory_exists(DOC_TMP_DIR)) {
|
|
|
|
Mkdir(DOC_TMP_DIR);
|
|
|
|
if (chown(DOC_TMP_DIR, 0, 0) < 0)
|
|
|
|
return NULL;
|
|
|
|
if (chmod(DOC_TMP_DIR, S_IRWXU) < 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
unlink(DOC_TMP_FILE);
|
1998-09-30 13:36:53 +00:00
|
|
|
if (!file_readable(fname) || vsystem("%s < %s > %s", gunzip, fname, DOC_TMP_FILE))
|
1996-07-05 08:36:02 +00:00
|
|
|
return NULL;
|
|
|
|
return DOC_TMP_FILE;
|
|
|
|
}
|
|
|
|
|
1995-04-27 12:50:35 +00:00
|
|
|
/* Initialize system defaults */
|
|
|
|
void
|
|
|
|
systemInitialize(int argc, char **argv)
|
|
|
|
{
|
2001-09-22 22:25:35 +00:00
|
|
|
size_t i;
|
|
|
|
int boothowto;
|
2000-10-29 09:57:50 +00:00
|
|
|
sigset_t signalset;
|
1999-07-20 07:39:22 +00:00
|
|
|
|
1995-04-27 12:50:35 +00:00
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
globalsInit();
|
|
|
|
|
2000-02-25 20:55:15 +00:00
|
|
|
i = sizeof(boothowto);
|
|
|
|
if (!sysctlbyname("debug.boothowto", &boothowto, &i, NULL, NULL) &&
|
|
|
|
(i == sizeof(boothowto)) && (boothowto & RB_VERBOSE))
|
|
|
|
variable_set2(VAR_DEBUG, "YES", 0);
|
|
|
|
|
1995-04-27 12:50:35 +00:00
|
|
|
/* Are we running as init? */
|
|
|
|
if (getpid() == 1) {
|
2001-10-23 17:31:11 +00:00
|
|
|
int fd;
|
1997-07-31 11:08:47 +00:00
|
|
|
|
|
|
|
RunningAsInit = 1;
|
1995-04-27 12:50:35 +00:00
|
|
|
setsid();
|
1996-09-26 21:07:11 +00:00
|
|
|
close(0);
|
1997-07-31 11:08:47 +00:00
|
|
|
fd = open("/dev/ttyv0", O_RDWR);
|
2000-10-30 23:46:12 +00:00
|
|
|
if (fd == -1) {
|
1997-07-31 11:08:47 +00:00
|
|
|
fd = open("/dev/console", O_RDWR); /* fallback */
|
2000-10-30 23:46:12 +00:00
|
|
|
variable_set2(VAR_FIXIT_TTY, "serial", 0); /* give fixit a hint */
|
|
|
|
} else
|
1996-09-26 21:07:11 +00:00
|
|
|
OnVTY = TRUE;
|
1997-07-31 11:08:47 +00:00
|
|
|
/*
|
|
|
|
* To make _sure_ we're on a VTY and don't have /dev/console switched
|
|
|
|
* away to a serial port or something, attempt to set the cursor appearance.
|
|
|
|
*/
|
|
|
|
if (OnVTY) {
|
2001-10-23 17:31:11 +00:00
|
|
|
int fd2, type;
|
1997-07-31 11:08:47 +00:00
|
|
|
|
2001-10-23 17:31:11 +00:00
|
|
|
type = 0; /* normal */
|
1997-07-31 11:08:47 +00:00
|
|
|
if ((fd2 = open("/dev/console", O_RDWR)) != -1) {
|
|
|
|
if (ioctl(fd2, CONS_CURSORTYPE, &type) == -1) {
|
|
|
|
OnVTY = FALSE;
|
2000-10-30 23:46:12 +00:00
|
|
|
variable_set2(VAR_FIXIT_TTY, "serial", 0); /* Tell Fixit
|
|
|
|
the console
|
|
|
|
type */
|
1997-07-31 11:08:47 +00:00
|
|
|
close(fd); close(fd2);
|
|
|
|
open("/dev/console", O_RDWR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
close(fd2);
|
|
|
|
}
|
|
|
|
}
|
1995-06-11 19:33:05 +00:00
|
|
|
close(1); dup(0);
|
|
|
|
close(2); dup(0);
|
1997-07-31 11:08:47 +00:00
|
|
|
printf("%s running as init on %s\n", argv[0], OnVTY ? "vty0" : "serial console");
|
1999-09-02 00:51:16 +00:00
|
|
|
ioctl(0, TIOCSCTTY, (char *)NULL);
|
1995-04-27 12:50:35 +00:00
|
|
|
setlogin("root");
|
1995-06-11 19:33:05 +00:00
|
|
|
setenv("PATH", "/stand:/bin:/sbin:/usr/sbin:/usr/bin:/mnt/bin:/mnt/sbin:/mnt/usr/sbin:/mnt/usr/bin:/usr/X11R6/bin", 1);
|
1995-04-27 12:50:35 +00:00
|
|
|
setbuf(stdin, 0);
|
|
|
|
setbuf(stderr, 0);
|
1999-09-02 00:51:16 +00:00
|
|
|
#ifdef __alpha__
|
|
|
|
i = 0;
|
|
|
|
sysctlbyname("machdep.unaligned_print", NULL, 0, &i, sizeof(i));
|
|
|
|
#endif
|
2001-11-01 23:32:46 +00:00
|
|
|
#if 0
|
2001-09-06 09:53:53 +00:00
|
|
|
signal(SIGCHLD, reap_children);
|
2001-11-01 23:32:46 +00:00
|
|
|
#endif
|
1995-04-27 12:50:35 +00:00
|
|
|
}
|
1996-12-11 19:35:26 +00:00
|
|
|
else {
|
|
|
|
char hname[256];
|
|
|
|
|
|
|
|
/* Initalize various things for a multi-user environment */
|
|
|
|
if (!gethostname(hname, sizeof hname))
|
1999-02-14 21:26:29 +00:00
|
|
|
variable_set2(VAR_HOSTNAME, hname, 0);
|
1996-12-11 19:35:26 +00:00
|
|
|
}
|
1995-04-27 12:50:35 +00:00
|
|
|
|
1995-05-10 18:59:51 +00:00
|
|
|
if (set_termcap() == -1) {
|
|
|
|
printf("Can't find terminal entry\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
1995-04-27 12:50:35 +00:00
|
|
|
|
|
|
|
/* XXX - libdialog has particularly bad return value checking */
|
|
|
|
init_dialog();
|
1996-04-25 17:31:27 +00:00
|
|
|
|
1995-04-27 12:50:35 +00:00
|
|
|
/* If we haven't crashed I guess dialog is running ! */
|
|
|
|
DialogActive = TRUE;
|
|
|
|
|
1995-12-07 10:34:59 +00:00
|
|
|
/* Make sure HOME is set for those utilities that need it */
|
|
|
|
if (!getenv("HOME"))
|
|
|
|
setenv("HOME", "/", 1);
|
1995-04-27 12:50:35 +00:00
|
|
|
signal(SIGINT, handle_intr);
|
2000-10-29 09:57:50 +00:00
|
|
|
/*
|
|
|
|
* Make sure we can be interrupted even if we were re-executed
|
|
|
|
* from an interrupt.
|
|
|
|
*/
|
|
|
|
sigemptyset(&signalset);
|
|
|
|
sigaddset(&signalset, SIGINT);
|
|
|
|
sigprocmask(SIG_UNBLOCK, &signalset, NULL);
|
|
|
|
|
1999-01-08 09:13:00 +00:00
|
|
|
(void)vsystem("rm -rf %s", DOC_TMP_DIR);
|
1995-04-27 12:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Close down and prepare to exit */
|
|
|
|
void
|
1996-05-16 11:47:46 +00:00
|
|
|
systemShutdown(int status)
|
1995-04-27 12:50:35 +00:00
|
|
|
{
|
1996-05-16 11:47:46 +00:00
|
|
|
/* If some media is open, close it down */
|
1999-02-15 00:49:33 +00:00
|
|
|
if (status >=0)
|
|
|
|
mediaClose();
|
1996-05-16 11:47:46 +00:00
|
|
|
|
1997-04-28 10:31:14 +00:00
|
|
|
/* write out any changes to rc.conf .. */
|
1999-02-09 22:18:10 +00:00
|
|
|
configRC_conf();
|
1997-02-10 19:44:08 +00:00
|
|
|
|
1996-05-16 11:47:46 +00:00
|
|
|
/* Shut down the dialog library */
|
1995-04-27 12:50:35 +00:00
|
|
|
if (DialogActive) {
|
|
|
|
end_dialog();
|
|
|
|
DialogActive = FALSE;
|
|
|
|
}
|
1996-05-16 11:47:46 +00:00
|
|
|
|
|
|
|
/* Shut down curses */
|
|
|
|
endwin();
|
|
|
|
|
1999-01-08 09:13:00 +00:00
|
|
|
/* If we have a temporary doc dir lying around, nuke it */
|
|
|
|
(void)vsystem("rm -rf %s", DOC_TMP_DIR);
|
1996-07-05 08:36:02 +00:00
|
|
|
|
1995-04-27 12:50:35 +00:00
|
|
|
/* REALLY exit! */
|
1995-05-26 21:00:43 +00:00
|
|
|
if (RunningAsInit) {
|
|
|
|
/* Put the console back */
|
1995-06-11 19:33:05 +00:00
|
|
|
ioctl(0, VT_ACTIVATE, 2);
|
1999-01-08 00:14:22 +00:00
|
|
|
#ifdef __alpha__
|
|
|
|
reboot(RB_HALT);
|
|
|
|
#else
|
1995-12-07 10:34:59 +00:00
|
|
|
reboot(0);
|
1999-01-08 00:14:22 +00:00
|
|
|
#endif
|
1995-05-26 21:00:43 +00:00
|
|
|
}
|
1995-04-29 19:33:06 +00:00
|
|
|
else
|
1996-05-16 11:47:46 +00:00
|
|
|
exit(status);
|
1995-04-27 12:50:35 +00:00
|
|
|
}
|
|
|
|
|
1995-04-29 19:33:06 +00:00
|
|
|
/* Run some general command */
|
1995-04-27 12:50:35 +00:00
|
|
|
int
|
|
|
|
systemExecute(char *command)
|
|
|
|
{
|
|
|
|
int status;
|
1995-12-07 10:34:59 +00:00
|
|
|
struct termios foo;
|
1999-12-14 04:25:29 +00:00
|
|
|
WINDOW *w = savescr();
|
1995-04-27 12:50:35 +00:00
|
|
|
|
1999-12-14 04:25:29 +00:00
|
|
|
dialog_clear();
|
1995-04-27 12:50:35 +00:00
|
|
|
dialog_update();
|
|
|
|
end_dialog();
|
|
|
|
DialogActive = FALSE;
|
1995-12-07 10:34:59 +00:00
|
|
|
if (tcgetattr(0, &foo) != -1) {
|
|
|
|
foo.c_cc[VERASE] = '\010';
|
|
|
|
tcsetattr(0, TCSANOW, &foo);
|
|
|
|
}
|
1996-04-28 20:54:11 +00:00
|
|
|
if (!Fake)
|
|
|
|
status = system(command);
|
|
|
|
else {
|
|
|
|
status = 0;
|
|
|
|
msgDebug("systemExecute: Faked execution of `%s'\n", command);
|
|
|
|
}
|
1995-04-27 12:50:35 +00:00
|
|
|
DialogActive = TRUE;
|
1999-12-14 04:25:29 +00:00
|
|
|
restorescr(w);
|
1995-04-27 12:50:35 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2000-07-18 09:14:06 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
1995-12-07 10:34:59 +00:00
|
|
|
/* Display a help file in a filebox */
|
1995-04-29 19:33:06 +00:00
|
|
|
int
|
1995-12-07 10:34:59 +00:00
|
|
|
systemDisplayHelp(char *file)
|
1995-04-29 19:33:06 +00:00
|
|
|
{
|
1995-05-01 21:56:32 +00:00
|
|
|
char *fname = NULL;
|
|
|
|
char buf[FILENAME_MAX];
|
1996-04-26 18:19:38 +00:00
|
|
|
int ret = 0;
|
1999-12-14 04:25:29 +00:00
|
|
|
WINDOW *w = savescr();
|
|
|
|
|
1995-05-01 21:56:32 +00:00
|
|
|
fname = systemHelpFile(file, buf);
|
1995-04-29 19:33:06 +00:00
|
|
|
if (!fname) {
|
|
|
|
snprintf(buf, FILENAME_MAX, "The %s file is not provided on this particular floppy image.", file);
|
1995-05-01 21:56:32 +00:00
|
|
|
use_helpfile(NULL);
|
|
|
|
use_helpline(NULL);
|
|
|
|
dialog_mesgbox("Sorry!", buf, -1, -1);
|
1996-04-26 18:19:38 +00:00
|
|
|
ret = 1;
|
1995-04-29 19:33:06 +00:00
|
|
|
}
|
|
|
|
else {
|
1995-05-01 21:56:32 +00:00
|
|
|
use_helpfile(NULL);
|
|
|
|
use_helpline(NULL);
|
1995-04-29 19:33:06 +00:00
|
|
|
dialog_textbox(file, fname, LINES, COLS);
|
|
|
|
}
|
1999-12-14 04:25:29 +00:00
|
|
|
restorescr(w);
|
1996-04-26 18:19:38 +00:00
|
|
|
return ret;
|
1995-04-29 19:33:06 +00:00
|
|
|
}
|
1995-05-01 21:56:32 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
systemHelpFile(char *file, char *buf)
|
|
|
|
{
|
|
|
|
if (!file)
|
|
|
|
return NULL;
|
2000-02-25 20:55:15 +00:00
|
|
|
if (file[0] == '/')
|
|
|
|
return file;
|
1996-07-05 08:36:02 +00:00
|
|
|
snprintf(buf, FILENAME_MAX, "/stand/help/%s.hlp.gz", file);
|
1998-11-03 03:38:56 +00:00
|
|
|
if (file_readable(buf))
|
|
|
|
return expand(buf);
|
|
|
|
snprintf(buf, FILENAME_MAX, "/stand/help/%s.TXT.gz", file);
|
1995-09-18 16:53:06 +00:00
|
|
|
if (file_readable(buf))
|
1996-07-05 08:36:02 +00:00
|
|
|
return expand(buf);
|
2001-01-17 19:51:08 +00:00
|
|
|
snprintf(buf, FILENAME_MAX, "/usr/src/usr.sbin/sysinstall/help/%s.hlp", file);
|
1998-11-03 03:38:56 +00:00
|
|
|
if (file_readable(buf))
|
|
|
|
return buf;
|
2001-01-17 19:51:08 +00:00
|
|
|
snprintf(buf, FILENAME_MAX, "/usr/src/usr.sbin/sysinstall/help/%s.TXT", file);
|
1996-05-16 11:47:46 +00:00
|
|
|
if (file_readable(buf))
|
|
|
|
return buf;
|
1995-05-29 02:13:31 +00:00
|
|
|
return NULL;
|
1995-05-01 21:56:32 +00:00
|
|
|
}
|
1995-05-04 19:48:19 +00:00
|
|
|
|
|
|
|
void
|
1995-05-05 23:47:47 +00:00
|
|
|
systemChangeTerminal(char *color, const u_char c_term[],
|
|
|
|
char *mono, const u_char m_term[])
|
1995-05-04 19:48:19 +00:00
|
|
|
{
|
1995-05-18 15:29:47 +00:00
|
|
|
if (OnVTY) {
|
1999-12-12 04:58:02 +00:00
|
|
|
int setupterm(char *color, int, int *);
|
|
|
|
|
1995-05-05 23:47:47 +00:00
|
|
|
if (ColorDisplay) {
|
|
|
|
setenv("TERM", color, 1);
|
|
|
|
setenv("TERMCAP", c_term, 1);
|
1995-05-18 15:29:47 +00:00
|
|
|
reset_shell_mode();
|
|
|
|
setterm(color);
|
|
|
|
cbreak(); noecho();
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
setenv("TERM", mono, 1);
|
|
|
|
setenv("TERMCAP", m_term, 1);
|
1995-05-18 15:29:47 +00:00
|
|
|
reset_shell_mode();
|
|
|
|
setterm(mono);
|
|
|
|
cbreak(); noecho();
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
1995-06-11 19:33:05 +00:00
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
dialog_clear();
|
1995-05-04 19:48:19 +00:00
|
|
|
}
|
|
|
|
|
1995-05-20 19:12:13 +00:00
|
|
|
int
|
|
|
|
vsystem(char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
1995-05-26 19:28:06 +00:00
|
|
|
int pstat;
|
1995-05-20 19:12:13 +00:00
|
|
|
pid_t pid;
|
|
|
|
int omask;
|
|
|
|
sig_t intsave, quitsave;
|
1995-12-07 10:34:59 +00:00
|
|
|
char *cmd;
|
|
|
|
int i;
|
1995-05-20 19:12:13 +00:00
|
|
|
|
1996-04-28 01:07:27 +00:00
|
|
|
cmd = (char *)alloca(FILENAME_MAX);
|
1995-05-20 19:12:13 +00:00
|
|
|
cmd[0] = '\0';
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(cmd, FILENAME_MAX, fmt, args);
|
|
|
|
va_end(args);
|
1995-05-29 11:01:42 +00:00
|
|
|
|
1995-05-20 19:12:13 +00:00
|
|
|
omask = sigblock(sigmask(SIGCHLD));
|
1996-04-28 20:54:11 +00:00
|
|
|
if (Fake) {
|
|
|
|
msgDebug("vsystem: Faked execution of `%s'\n", cmd);
|
|
|
|
return 0;
|
|
|
|
}
|
1995-05-29 11:01:42 +00:00
|
|
|
if (isDebug())
|
1995-12-07 10:34:59 +00:00
|
|
|
msgDebug("Executing command `%s'\n", cmd);
|
|
|
|
pid = fork();
|
|
|
|
if (pid == -1) {
|
1995-05-20 19:12:13 +00:00
|
|
|
(void)sigsetmask(omask);
|
|
|
|
i = 127;
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
|
|
|
else if (!pid) { /* Junior */
|
1995-05-20 19:12:13 +00:00
|
|
|
(void)sigsetmask(omask);
|
|
|
|
if (DebugFD != -1) {
|
|
|
|
dup2(DebugFD, 0);
|
|
|
|
dup2(DebugFD, 1);
|
|
|
|
dup2(DebugFD, 2);
|
|
|
|
}
|
1996-04-28 03:27:26 +00:00
|
|
|
else {
|
|
|
|
close(1); open("/dev/null", O_WRONLY);
|
|
|
|
dup2(1, 2);
|
|
|
|
}
|
|
|
|
if (!RunningAsInit)
|
|
|
|
execl("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL);
|
|
|
|
else
|
|
|
|
execl("/stand/sh", "/stand/sh", "-c", cmd, (char *)NULL);
|
1995-12-07 10:34:59 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
intsave = signal(SIGINT, SIG_IGN);
|
|
|
|
quitsave = signal(SIGQUIT, SIG_IGN);
|
|
|
|
pid = waitpid(pid, &pstat, 0);
|
|
|
|
(void)sigsetmask(omask);
|
|
|
|
(void)signal(SIGINT, intsave);
|
|
|
|
(void)signal(SIGQUIT, quitsave);
|
|
|
|
i = (pid == -1) ? -1 : WEXITSTATUS(pstat);
|
|
|
|
if (isDebug())
|
|
|
|
msgDebug("Command `%s' returns status of %d\n", cmd, i);
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
systemCreateHoloshell(void)
|
|
|
|
{
|
2000-07-18 09:14:06 +00:00
|
|
|
int waitstatus;
|
|
|
|
|
|
|
|
if ((FixItMode || OnVTY) && RunningAsInit) {
|
1996-12-29 05:51:40 +00:00
|
|
|
|
|
|
|
if (ehs_pid != 0) {
|
|
|
|
int pstat;
|
|
|
|
|
|
|
|
if (kill(ehs_pid, 0) == 0) {
|
|
|
|
|
2000-12-14 02:49:02 +00:00
|
|
|
if (msgNoYes("There seems to be an emergency holographic shell\n"
|
1999-09-02 00:51:16 +00:00
|
|
|
"already running on VTY 4.\n\n"
|
1996-12-29 05:51:40 +00:00
|
|
|
"Kill it and start a new one?"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* try cleaning up as much as possible */
|
|
|
|
(void) kill(ehs_pid, SIGHUP);
|
|
|
|
sleep(1);
|
|
|
|
(void) kill(ehs_pid, SIGKILL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* avoid too many zombies */
|
|
|
|
(void) waitpid(ehs_pid, &pstat, WNOHANG);
|
|
|
|
}
|
|
|
|
|
2000-10-30 23:46:12 +00:00
|
|
|
if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
|
2000-07-18 09:14:06 +00:00
|
|
|
systemSuspendDialog(); /* must be before the fork() */
|
1996-12-29 05:51:40 +00:00
|
|
|
if ((ehs_pid = fork()) == 0) {
|
1995-12-07 10:34:59 +00:00
|
|
|
int i, fd;
|
|
|
|
struct termios foo;
|
|
|
|
extern int login_tty(int);
|
|
|
|
|
1996-12-11 19:35:26 +00:00
|
|
|
ioctl(0, TIOCNOTTY, NULL);
|
1996-12-12 08:23:51 +00:00
|
|
|
for (i = getdtablesize(); i >= 0; --i)
|
1995-12-07 10:34:59 +00:00
|
|
|
close(i);
|
2000-10-30 23:46:12 +00:00
|
|
|
if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
|
2000-07-18 09:14:06 +00:00
|
|
|
fd = open("/dev/console", O_RDWR);
|
2000-10-30 23:46:12 +00:00
|
|
|
else
|
|
|
|
fd = open("/dev/ttyv3", O_RDWR);
|
1995-12-07 10:34:59 +00:00
|
|
|
ioctl(0, TIOCSCTTY, &fd);
|
|
|
|
dup2(0, 1);
|
|
|
|
dup2(0, 2);
|
1996-12-11 19:35:26 +00:00
|
|
|
DebugFD = 2;
|
1995-12-07 10:34:59 +00:00
|
|
|
if (login_tty(fd) == -1)
|
|
|
|
msgDebug("Doctor: I can't set the controlling terminal.\n");
|
|
|
|
signal(SIGTTOU, SIG_IGN);
|
|
|
|
if (tcgetattr(fd, &foo) != -1) {
|
|
|
|
foo.c_cc[VERASE] = '\010';
|
|
|
|
if (tcsetattr(fd, TCSANOW, &foo) == -1)
|
|
|
|
msgDebug("Doctor: I'm unable to set the erase character.\n");
|
1995-05-29 11:01:42 +00:00
|
|
|
}
|
|
|
|
else
|
1995-12-07 10:34:59 +00:00
|
|
|
msgDebug("Doctor: I'm unable to get the terminal attributes!\n");
|
2000-10-30 23:46:12 +00:00
|
|
|
if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) {
|
2000-07-18 09:14:06 +00:00
|
|
|
printf("Type ``exit'' in this fixit shell to resume sysinstall.\n\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
1995-12-07 10:34:59 +00:00
|
|
|
execlp("sh", "-sh", 0);
|
|
|
|
msgDebug("Was unable to execute sh for Holographic shell!\n");
|
|
|
|
exit(1);
|
1995-05-18 09:02:06 +00:00
|
|
|
}
|
1996-04-29 21:15:44 +00:00
|
|
|
else {
|
2000-10-30 23:46:12 +00:00
|
|
|
if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
|
2000-07-18 09:14:06 +00:00
|
|
|
WINDOW *w = savescr();
|
1999-12-17 02:46:04 +00:00
|
|
|
|
2000-07-18 09:14:06 +00:00
|
|
|
msgNotify("Starting an emergency holographic shell on VTY4");
|
|
|
|
sleep(2);
|
|
|
|
restorescr(w);
|
|
|
|
}
|
2000-10-30 23:46:12 +00:00
|
|
|
else {
|
|
|
|
(void)waitpid(ehs_pid, &waitstatus, 0); /* we only wait for
|
|
|
|
shell to finish
|
|
|
|
it serial mode
|
|
|
|
since there is no
|
|
|
|
virtual console */
|
2000-07-18 09:14:06 +00:00
|
|
|
systemResumeDialog();
|
|
|
|
}
|
1996-04-29 21:15:44 +00:00
|
|
|
}
|
1995-05-18 02:42:33 +00:00
|
|
|
}
|
1995-05-20 23:33:14 +00:00
|
|
|
}
|