1995-04-27 14:50:35 +02:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1995-09-18 18:53:06 +02:00
|
|
|
* $Id: system.c,v 1.44 1995/06/11 19:30:10 rgrimes Exp $
|
1995-04-27 14:50:35 +02: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 18:58:58 +02: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 14:50:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinstall.h"
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/reboot.h>
|
1995-05-06 01:47:47 +02:00
|
|
|
#include <machine/console.h>
|
1995-04-27 14:50:35 +02:00
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-04-29 21:33:06 +02:00
|
|
|
#include <sys/wait.h>
|
1995-04-27 14:50:35 +02:00
|
|
|
|
1995-05-06 01:47:47 +02: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.
|
|
|
|
*/
|
1995-04-27 14:50:35 +02:00
|
|
|
static void
|
|
|
|
handle_intr(int sig)
|
|
|
|
{
|
1995-05-06 01:47:47 +02:00
|
|
|
if (!msgYesNo("Are you sure you want to abort the installation?"))
|
|
|
|
systemShutdown();
|
1995-04-27 14:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize system defaults */
|
|
|
|
void
|
|
|
|
systemInitialize(int argc, char **argv)
|
|
|
|
{
|
1995-05-19 18:58:58 +02:00
|
|
|
int i;
|
|
|
|
|
1995-04-27 14:50:35 +02:00
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
globalsInit();
|
|
|
|
|
|
|
|
/* Are we running as init? */
|
|
|
|
if (getpid() == 1) {
|
|
|
|
setsid();
|
1995-06-11 21:33:05 +02:00
|
|
|
close(0); open("/dev/ttyv0", O_RDWR);
|
|
|
|
close(1); dup(0);
|
|
|
|
close(2); dup(0);
|
1995-05-10 20:59:51 +02:00
|
|
|
printf("%s running as init\n", argv[0]);
|
1995-04-27 14:50:35 +02:00
|
|
|
|
1995-05-26 10:41:52 +02:00
|
|
|
i = ioctl(0, TIOCSCTTY, (char *)NULL);
|
1995-04-27 14:50:35 +02:00
|
|
|
setlogin("root");
|
1995-06-11 21:33:05 +02: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 14:50:35 +02:00
|
|
|
setbuf(stdin, 0);
|
|
|
|
setbuf(stderr, 0);
|
|
|
|
}
|
|
|
|
|
1995-05-10 20:59:51 +02:00
|
|
|
if (set_termcap() == -1) {
|
|
|
|
printf("Can't find terminal entry\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
1995-04-27 14:50:35 +02:00
|
|
|
|
|
|
|
/* XXX - libdialog has particularly bad return value checking */
|
|
|
|
init_dialog();
|
|
|
|
/* If we haven't crashed I guess dialog is running ! */
|
|
|
|
DialogActive = TRUE;
|
|
|
|
|
|
|
|
signal(SIGINT, handle_intr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close down and prepare to exit */
|
|
|
|
void
|
|
|
|
systemShutdown(void)
|
|
|
|
{
|
|
|
|
if (DialogActive) {
|
|
|
|
end_dialog();
|
|
|
|
DialogActive = FALSE;
|
|
|
|
}
|
|
|
|
/* REALLY exit! */
|
1995-05-26 23:00:43 +02:00
|
|
|
if (RunningAsInit) {
|
|
|
|
/* Put the console back */
|
1995-06-11 21:33:05 +02:00
|
|
|
ioctl(0, VT_ACTIVATE, 2);
|
1995-04-27 14:50:35 +02:00
|
|
|
reboot(RB_HALT);
|
1995-05-26 23:00:43 +02:00
|
|
|
}
|
1995-04-29 21:33:06 +02:00
|
|
|
else
|
|
|
|
exit(1);
|
1995-04-27 14:50:35 +02:00
|
|
|
}
|
|
|
|
|
1995-04-29 21:33:06 +02:00
|
|
|
/* Run some general command */
|
1995-04-27 14:50:35 +02:00
|
|
|
int
|
|
|
|
systemExecute(char *command)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
dialog_clear();
|
|
|
|
dialog_update();
|
|
|
|
end_dialog();
|
|
|
|
DialogActive = FALSE;
|
|
|
|
status = system(command);
|
|
|
|
DialogActive = TRUE;
|
|
|
|
dialog_clear();
|
|
|
|
dialog_update();
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1995-04-29 21:33:06 +02:00
|
|
|
/* Display a file in a filebox */
|
|
|
|
int
|
|
|
|
systemDisplayFile(char *file)
|
|
|
|
{
|
1995-05-01 23:56:32 +02:00
|
|
|
char *fname = NULL;
|
|
|
|
char buf[FILENAME_MAX];
|
1995-05-16 13:37:27 +02:00
|
|
|
WINDOW *w;
|
1995-04-29 21:33:06 +02:00
|
|
|
|
1995-05-01 23:56:32 +02:00
|
|
|
fname = systemHelpFile(file, buf);
|
1995-04-29 21:33:06 +02:00
|
|
|
if (!fname) {
|
|
|
|
snprintf(buf, FILENAME_MAX, "The %s file is not provided on this particular floppy image.", file);
|
1995-05-01 23:56:32 +02:00
|
|
|
use_helpfile(NULL);
|
|
|
|
use_helpline(NULL);
|
1995-05-16 13:37:27 +02:00
|
|
|
w = dupwin(newscr);
|
1995-05-01 23:56:32 +02:00
|
|
|
dialog_mesgbox("Sorry!", buf, -1, -1);
|
1995-05-16 13:37:27 +02:00
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
delwin(w);
|
1995-04-29 21:33:06 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
1995-05-01 23:56:32 +02:00
|
|
|
use_helpfile(NULL);
|
|
|
|
use_helpline(NULL);
|
1995-05-16 13:37:27 +02:00
|
|
|
w = dupwin(newscr);
|
1995-04-29 21:33:06 +02:00
|
|
|
dialog_textbox(file, fname, LINES, COLS);
|
1995-05-16 13:37:27 +02:00
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
delwin(w);
|
1995-04-29 21:33:06 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1995-05-01 23:56:32 +02:00
|
|
|
|
|
|
|
char *
|
|
|
|
systemHelpFile(char *file, char *buf)
|
|
|
|
{
|
|
|
|
if (!file)
|
|
|
|
return NULL;
|
|
|
|
|
1995-09-18 18:53:06 +02:00
|
|
|
snprintf(buf, FILENAME_MAX, "/stand/help/%s.hlp", file);
|
|
|
|
if (file_readable(buf))
|
|
|
|
return buf;
|
1995-05-29 04:13:31 +02:00
|
|
|
return NULL;
|
1995-05-01 23:56:32 +02:00
|
|
|
}
|
1995-05-04 21:48:19 +02:00
|
|
|
|
|
|
|
void
|
1995-05-06 01:47:47 +02:00
|
|
|
systemChangeTerminal(char *color, const u_char c_term[],
|
|
|
|
char *mono, const u_char m_term[])
|
1995-05-04 21:48:19 +02:00
|
|
|
{
|
1995-05-19 18:58:58 +02:00
|
|
|
extern void init_acs(void);
|
|
|
|
|
1995-05-18 17:29:47 +02:00
|
|
|
if (OnVTY) {
|
1995-05-06 01:47:47 +02:00
|
|
|
if (ColorDisplay) {
|
|
|
|
setenv("TERM", color, 1);
|
|
|
|
setenv("TERMCAP", c_term, 1);
|
1995-05-18 17:29:47 +02:00
|
|
|
reset_shell_mode();
|
|
|
|
setterm(color);
|
|
|
|
init_acs();
|
|
|
|
cbreak(); noecho();
|
1995-05-06 01:47:47 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
setenv("TERM", mono, 1);
|
|
|
|
setenv("TERMCAP", m_term, 1);
|
1995-05-18 17:29:47 +02:00
|
|
|
reset_shell_mode();
|
|
|
|
setterm(mono);
|
|
|
|
init_acs();
|
|
|
|
cbreak(); noecho();
|
1995-05-06 01:47:47 +02:00
|
|
|
}
|
|
|
|
}
|
1995-06-11 21:33:05 +02:00
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
dialog_clear();
|
1995-05-04 21:48:19 +02:00
|
|
|
}
|
|
|
|
|
1995-05-20 21:12:13 +02:00
|
|
|
int
|
|
|
|
vsystem(char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
1995-05-26 21:28:06 +02:00
|
|
|
int pstat;
|
1995-05-20 21:12:13 +02:00
|
|
|
pid_t pid;
|
|
|
|
int omask;
|
|
|
|
sig_t intsave, quitsave;
|
1995-05-21 03:56:03 +02:00
|
|
|
char *cmd,*p;
|
|
|
|
int i,magic=0;
|
1995-05-20 21:12:13 +02:00
|
|
|
|
|
|
|
cmd = (char *)malloc(FILENAME_MAX);
|
|
|
|
cmd[0] = '\0';
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(cmd, FILENAME_MAX, fmt, args);
|
|
|
|
va_end(args);
|
1995-05-29 13:01:42 +02:00
|
|
|
|
1995-05-21 03:56:03 +02:00
|
|
|
/* Find out if this command needs the wizardry of the shell */
|
|
|
|
for (p="<>|'`=\"()" ; *p; p++)
|
1995-05-29 13:01:42 +02:00
|
|
|
if (strchr(cmd, *p))
|
|
|
|
magic++;
|
1995-05-20 21:12:13 +02:00
|
|
|
omask = sigblock(sigmask(SIGCHLD));
|
1995-05-29 13:01:42 +02:00
|
|
|
if (isDebug())
|
|
|
|
msgDebug("Executing command `%s' (Magic=%d)\n", cmd, magic);
|
1995-05-20 21:12:13 +02:00
|
|
|
switch(pid = fork()) {
|
|
|
|
case -1: /* error */
|
|
|
|
(void)sigsetmask(omask);
|
|
|
|
i = 127;
|
|
|
|
|
|
|
|
case 0: /* child */
|
|
|
|
(void)sigsetmask(omask);
|
|
|
|
if (DebugFD != -1) {
|
1995-05-29 13:01:42 +02:00
|
|
|
if (OnVTY && isDebug())
|
1995-05-20 21:12:13 +02:00
|
|
|
msgInfo("Command output is on debugging screen - type ALT-F2 to see it");
|
|
|
|
dup2(DebugFD, 0);
|
|
|
|
dup2(DebugFD, 1);
|
|
|
|
dup2(DebugFD, 2);
|
|
|
|
}
|
1995-05-29 04:13:31 +02:00
|
|
|
#ifdef NOT_A_GOOD_IDEA_CRUNCHED_BINARY
|
1995-05-21 03:56:03 +02:00
|
|
|
if (magic) {
|
1995-05-29 13:01:42 +02:00
|
|
|
char *argv[100];
|
|
|
|
i = 0;
|
|
|
|
argv[i++] = "crunch";
|
|
|
|
argv[i++] = "sh";
|
|
|
|
argv[i++] = "-c";
|
|
|
|
argv[i++] = cmd;
|
|
|
|
argv[i] = 0;
|
|
|
|
exit(crunched_main(i,argv));
|
1995-05-21 03:56:03 +02:00
|
|
|
} else {
|
1995-05-29 13:01:42 +02:00
|
|
|
char *argv[100];
|
|
|
|
i = 0;
|
|
|
|
argv[i++] = "crunch";
|
|
|
|
while (cmd && *cmd) {
|
|
|
|
argv[i] = strsep(&cmd," \t");
|
|
|
|
if (*argv[i])
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
argv[i] = 0;
|
|
|
|
if (crunched_here(argv[1]))
|
|
|
|
exit(crunched_main(i,argv));
|
|
|
|
else
|
|
|
|
execvp(argv[1],argv+1);
|
|
|
|
kill(getpid(),9);
|
1995-05-18 11:02:06 +02:00
|
|
|
}
|
1995-05-21 03:56:03 +02:00
|
|
|
#else /* !CRUNCHED_BINARY */
|
1995-05-18 04:42:33 +02:00
|
|
|
execl("/stand/sh", "sh", "-c", cmd, (char *)NULL);
|
1995-05-21 03:56:03 +02:00
|
|
|
kill(getpid(),9);
|
|
|
|
#endif /* CRUNCHED_BINARY */
|
1995-05-18 04:42:33 +02:00
|
|
|
}
|
|
|
|
intsave = signal(SIGINT, SIG_IGN);
|
|
|
|
quitsave = signal(SIGQUIT, SIG_IGN);
|
1995-05-26 21:28:06 +02:00
|
|
|
pid = waitpid(pid, &pstat, 0);
|
1995-05-18 04:42:33 +02:00
|
|
|
(void)sigsetmask(omask);
|
|
|
|
(void)signal(SIGINT, intsave);
|
|
|
|
(void)signal(SIGQUIT, quitsave);
|
1995-05-26 21:28:06 +02:00
|
|
|
i = (pid == -1) ? -1 : WEXITSTATUS(pstat);
|
1995-05-29 13:01:42 +02:00
|
|
|
if (isDebug())
|
|
|
|
msgDebug("Command `%s' returns status of %d\n", cmd, i);
|
1995-05-06 11:34:24 +02:00
|
|
|
free(cmd);
|
|
|
|
return i;
|
1995-05-21 01:33:14 +02:00
|
|
|
}
|