1995-04-27 12:50:35 +00:00
|
|
|
/*
|
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.
|
|
|
|
*
|
2006-08-07 23:35:49 +00:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2006-08-07 23:35:49 +00:00
|
|
|
#include "sade.h"
|
1995-04-27 12:50:35 +00:00
|
|
|
#include <signal.h>
|
1999-09-04 16:01:15 +00:00
|
|
|
#include <termios.h>
|
2003-12-20 16:34:45 +00:00
|
|
|
#include <sys/param.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>
|
2003-12-20 16:34:45 +00:00
|
|
|
#include <sys/mount.h>
|
1999-01-08 09:13:00 +00:00
|
|
|
#include <sys/stat.h>
|
2000-03-25 04:23:08 +00:00
|
|
|
#include <sys/sysctl.h>
|
2003-12-20 16:34:45 +00:00
|
|
|
#include <ufs/ufs/ufsmount.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
|
|
|
|
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_restart(dialogMenuItem *self)
|
|
|
|
{
|
2001-09-30 00:43:32 +00:00
|
|
|
int ret, fd, fdmax;
|
|
|
|
|
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[] = {
|
2006-08-08 13:45:46 +00:00
|
|
|
{ "Restart", "Restart the program", NULL, intr_restart, NULL, NULL, 0, 0, 0, 0 },
|
|
|
|
{ "Continue", "Continue without restarting", NULL, intr_continue, NULL, NULL, 0, 0, 0, 0 },
|
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?",
|
2006-08-07 23:35:49 +00:00
|
|
|
-1, -1, 2, -2, intrmenu, NULL, NULL, NULL);
|
2000-10-29 09:57:50 +00:00
|
|
|
restorescr(save);
|
1995-04-27 12:50:35 +00:00
|
|
|
}
|
|
|
|
|
1996-07-05 08:36:02 +00:00
|
|
|
/* Expand a file into a convenient location, nuking it each time */
|
|
|
|
static char *
|
|
|
|
expand(char *fname)
|
|
|
|
{
|
2006-08-07 23:35:49 +00:00
|
|
|
char *gunzip = "/usr/bin/gunzip";
|
1998-09-30 11:44:29 +00:00
|
|
|
|
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);
|
2004-03-11 11:58:16 +00:00
|
|
|
if (!sysctlbyname("debug.boothowto", &boothowto, &i, NULL, 0) &&
|
2000-02-25 20:55:15 +00:00
|
|
|
(i == sizeof(boothowto)) && (boothowto & RB_VERBOSE))
|
|
|
|
variable_set2(VAR_DEBUG, "YES", 0);
|
|
|
|
|
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 */
|
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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2006-08-07 23:35:49 +00:00
|
|
|
printf("zzz");
|
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);
|
2002-08-09 07:44:43 +00:00
|
|
|
if (file_readable(buf))
|
|
|
|
return expand(buf);
|
|
|
|
snprintf(buf, FILENAME_MAX, "/stand/help/%s.hlp", 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);
|
2002-08-09 07:44:43 +00:00
|
|
|
if (file_readable(buf))
|
|
|
|
return expand(buf);
|
|
|
|
snprintf(buf, FILENAME_MAX, "/stand/help/%s.TXT", file);
|
1995-09-18 16:53:06 +00:00
|
|
|
if (file_readable(buf))
|
1996-07-05 08:36:02 +00:00
|
|
|
return expand(buf);
|
2008-05-11 17:23:57 +00:00
|
|
|
snprintf(buf, FILENAME_MAX, "/usr/src/usr.sbin/%s/help/%s.hlp", ProgName,
|
2008-05-11 07:13:08 +00:00
|
|
|
file);
|
1998-11-03 03:38:56 +00:00
|
|
|
if (file_readable(buf))
|
|
|
|
return buf;
|
2008-05-11 17:23:57 +00:00
|
|
|
snprintf(buf, FILENAME_MAX, "/usr/src/usr.sbin/%s/help/%s.TXT", ProgName,
|
2008-05-11 07:13:08 +00:00
|
|
|
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
|
|
|
|
1995-05-20 19:12:13 +00:00
|
|
|
int
|
2006-08-08 13:45:46 +00:00
|
|
|
vsystem(const char *fmt, ...)
|
1995-05-20 19:12:13 +00:00
|
|
|
{
|
|
|
|
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;
|
2005-08-05 13:39:08 +00:00
|
|
|
struct stat sb;
|
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);
|
|
|
|
}
|
2005-08-05 13:39:08 +00:00
|
|
|
if (stat("/stand/sh", &sb) == 0)
|
1996-04-28 03:27:26 +00:00
|
|
|
execl("/stand/sh", "/stand/sh", "-c", cmd, (char *)NULL);
|
2004-11-19 03:52:41 +00:00
|
|
|
else
|
|
|
|
execl("/bin/sh", "/bin/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;
|
|
|
|
}
|
|
|
|
|