mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-22 08:53:41 +01:00
Make serial console based installs actually work by:
1. Detecting the split /dev/ttyv0 / /dev/console case, e.g. you've booted with the -h flag and you have a VGA card also. 2. Adding an extra "menu" for selecting terminal type and adding ANSI to the list of compiled-in terms. 3. Opening the proper file descriptors before disowning ourselves. Requested by: pst
This commit is contained in:
parent
ad8eb2f9de
commit
b6aad04900
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27798
@ -30,6 +30,9 @@ LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio
|
||||
makedevs.c: Makefile rtermcap keymap.h
|
||||
rm -f makedevs.tmp
|
||||
echo '#include <sys/types.h>' > makedevs.tmp
|
||||
./rtermcap ansi | \
|
||||
file2c 'const char termcap_ansi[] = {' ',0};' \
|
||||
>> makedevs.tmp
|
||||
./rtermcap cons25 | \
|
||||
file2c 'const char termcap_cons25[] = {' ',0};' \
|
||||
>> makedevs.tmp
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated to essentially a complete rewrite.
|
||||
*
|
||||
* $Id: sysinstall.h,v 1.137 1997/06/22 09:45:40 jkh Exp $
|
||||
* $Id: sysinstall.h,v 1.138 1997/07/16 05:22:42 jkh Exp $
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@ -556,6 +556,7 @@ extern int diskLabelCommit(dialogMenuItem *self);
|
||||
extern int lndir(char *from, char *to);
|
||||
|
||||
/* makedevs.c (auto-generated) */
|
||||
extern const char termcap_ansi[];
|
||||
extern const char termcap_vt100[];
|
||||
extern const char termcap_cons25[];
|
||||
extern const char termcap_cons25_m[];
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: system.c,v 1.80 1997/04/28 10:31:14 jkh Exp $
|
||||
* $Id: system.c,v 1.81 1997/05/27 18:56:03 jkh Exp $
|
||||
*
|
||||
* Jordan Hubbard
|
||||
*
|
||||
@ -69,16 +69,37 @@ systemInitialize(int argc, char **argv)
|
||||
|
||||
/* Are we running as init? */
|
||||
if (getpid() == 1) {
|
||||
int fd, type;
|
||||
|
||||
RunningAsInit = 1;
|
||||
setsid();
|
||||
close(0);
|
||||
if (open("/dev/ttyv0", O_RDWR) < 0)
|
||||
open("/dev/console", O_RDWR);
|
||||
fd = open("/dev/ttyv0", O_RDWR);
|
||||
if (fd == -1)
|
||||
fd = open("/dev/console", O_RDWR); /* fallback */
|
||||
else
|
||||
OnVTY = TRUE;
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
type = 0; /* normal */
|
||||
if (OnVTY) {
|
||||
int fd2;
|
||||
|
||||
if ((fd2 = open("/dev/console", O_RDWR)) != -1) {
|
||||
if (ioctl(fd2, CONS_CURSORTYPE, &type) == -1) {
|
||||
OnVTY = FALSE;
|
||||
close(fd); close(fd2);
|
||||
open("/dev/console", O_RDWR);
|
||||
}
|
||||
else
|
||||
close(fd2);
|
||||
}
|
||||
}
|
||||
close(1); dup(0);
|
||||
close(2); dup(0);
|
||||
printf("%s running as init\n", argv[0]);
|
||||
RunningAsInit = 1;
|
||||
printf("%s running as init on %s\n", argv[0], OnVTY ? "vty0" : "serial console");
|
||||
i = ioctl(0, TIOCSCTTY, (char *)NULL);
|
||||
setlogin("root");
|
||||
setenv("PATH", "/stand:/bin:/sbin:/usr/sbin:/usr/bin:/mnt/bin:/mnt/sbin:/mnt/usr/sbin:/mnt/usr/bin:/usr/X11R6/bin", 1);
|
||||
|
@ -21,6 +21,50 @@
|
||||
#define VTY_STATUS_LINE 24
|
||||
#define TTY_STATUS_LINE 23
|
||||
|
||||
static void
|
||||
prompt_term(char **termp, char **termcapp)
|
||||
{
|
||||
char str[80];
|
||||
static struct {
|
||||
const char *term, *termcap;
|
||||
} lookup[] = { { "ansi", termcap_ansi },
|
||||
{ "vt100", termcap_vt100 },
|
||||
{ "cons25", termcap_cons25 },
|
||||
{ "cons25-m", termcap_cons25_m } };
|
||||
|
||||
if (RunningAsInit) {
|
||||
while (1) {
|
||||
int i;
|
||||
|
||||
printf("\nThese are the predefined terminal types available to\n");
|
||||
printf("sysinstall when running stand-alone. Please choose the\n");
|
||||
printf("closest match for your particular terminal.\n\n");
|
||||
printf("1 ...................... Standard ANSI terminal.\n");
|
||||
printf("2 ...................... VT100 or compatible terminal.\n");
|
||||
printf("3 ...................... FreeBSD system console (color).\n");
|
||||
printf("4 ...................... FreeBSD system console (monochrome).\n\n");
|
||||
printf("Your choice: (1-4) ");
|
||||
fflush(stdout);
|
||||
fgets(str, 80, stdin);
|
||||
i = str[0] - '0';
|
||||
if (i > 0 && i < 5) {
|
||||
*termp = (char *)lookup[i - 1].term;
|
||||
*termcapp = (char *)lookup[i - 1].termcap;
|
||||
break;
|
||||
}
|
||||
else
|
||||
printf("\007Invalid choice, please try again.\n\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\nPlease set your TERM variable before running this program.\n");
|
||||
printf("Defaulting to an ANSI compatible terminal - please press RETURN\n");
|
||||
fgets(str, 80, stdin); /* Just to make it interactive */
|
||||
*termp = (char *)"ansi";
|
||||
*termcapp = (char *)termcap_ansi;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
set_termcap(void)
|
||||
{
|
||||
@ -31,7 +75,7 @@ set_termcap(void)
|
||||
term = getenv("TERM");
|
||||
stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);
|
||||
|
||||
if (getpid() != 1) {
|
||||
if (!RunningAsInit) {
|
||||
if (getenv("SYSINSTALL_DEBUG"))
|
||||
DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
||||
else
|
||||
@ -42,9 +86,12 @@ set_termcap(void)
|
||||
|
||||
if (!OnVTY || (stat < 0)) {
|
||||
if (!term) {
|
||||
if (setenv("TERM", "vt100", 1) < 0)
|
||||
char *term, *termcap;
|
||||
|
||||
prompt_term(&term, &termcap);
|
||||
if (setenv("TERM", term, 1) < 0)
|
||||
return -1;
|
||||
if (setenv("TERMCAP", termcap_vt100, 1) < 0)
|
||||
if (setenv("TERMCAP", termcap, 1) < 0)
|
||||
return -1;
|
||||
}
|
||||
if (DebugFD == -1)
|
||||
|
@ -30,6 +30,9 @@ LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio
|
||||
makedevs.c: Makefile rtermcap keymap.h
|
||||
rm -f makedevs.tmp
|
||||
echo '#include <sys/types.h>' > makedevs.tmp
|
||||
./rtermcap ansi | \
|
||||
file2c 'const char termcap_ansi[] = {' ',0};' \
|
||||
>> makedevs.tmp
|
||||
./rtermcap cons25 | \
|
||||
file2c 'const char termcap_cons25[] = {' ',0};' \
|
||||
>> makedevs.tmp
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated to essentially a complete rewrite.
|
||||
*
|
||||
* $Id: sysinstall.h,v 1.137 1997/06/22 09:45:40 jkh Exp $
|
||||
* $Id: sysinstall.h,v 1.138 1997/07/16 05:22:42 jkh Exp $
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@ -556,6 +556,7 @@ extern int diskLabelCommit(dialogMenuItem *self);
|
||||
extern int lndir(char *from, char *to);
|
||||
|
||||
/* makedevs.c (auto-generated) */
|
||||
extern const char termcap_ansi[];
|
||||
extern const char termcap_vt100[];
|
||||
extern const char termcap_cons25[];
|
||||
extern const char termcap_cons25_m[];
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: system.c,v 1.80 1997/04/28 10:31:14 jkh Exp $
|
||||
* $Id: system.c,v 1.81 1997/05/27 18:56:03 jkh Exp $
|
||||
*
|
||||
* Jordan Hubbard
|
||||
*
|
||||
@ -69,16 +69,37 @@ systemInitialize(int argc, char **argv)
|
||||
|
||||
/* Are we running as init? */
|
||||
if (getpid() == 1) {
|
||||
int fd, type;
|
||||
|
||||
RunningAsInit = 1;
|
||||
setsid();
|
||||
close(0);
|
||||
if (open("/dev/ttyv0", O_RDWR) < 0)
|
||||
open("/dev/console", O_RDWR);
|
||||
fd = open("/dev/ttyv0", O_RDWR);
|
||||
if (fd == -1)
|
||||
fd = open("/dev/console", O_RDWR); /* fallback */
|
||||
else
|
||||
OnVTY = TRUE;
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
type = 0; /* normal */
|
||||
if (OnVTY) {
|
||||
int fd2;
|
||||
|
||||
if ((fd2 = open("/dev/console", O_RDWR)) != -1) {
|
||||
if (ioctl(fd2, CONS_CURSORTYPE, &type) == -1) {
|
||||
OnVTY = FALSE;
|
||||
close(fd); close(fd2);
|
||||
open("/dev/console", O_RDWR);
|
||||
}
|
||||
else
|
||||
close(fd2);
|
||||
}
|
||||
}
|
||||
close(1); dup(0);
|
||||
close(2); dup(0);
|
||||
printf("%s running as init\n", argv[0]);
|
||||
RunningAsInit = 1;
|
||||
printf("%s running as init on %s\n", argv[0], OnVTY ? "vty0" : "serial console");
|
||||
i = ioctl(0, TIOCSCTTY, (char *)NULL);
|
||||
setlogin("root");
|
||||
setenv("PATH", "/stand:/bin:/sbin:/usr/sbin:/usr/bin:/mnt/bin:/mnt/sbin:/mnt/usr/sbin:/mnt/usr/bin:/usr/X11R6/bin", 1);
|
||||
|
@ -21,6 +21,50 @@
|
||||
#define VTY_STATUS_LINE 24
|
||||
#define TTY_STATUS_LINE 23
|
||||
|
||||
static void
|
||||
prompt_term(char **termp, char **termcapp)
|
||||
{
|
||||
char str[80];
|
||||
static struct {
|
||||
const char *term, *termcap;
|
||||
} lookup[] = { { "ansi", termcap_ansi },
|
||||
{ "vt100", termcap_vt100 },
|
||||
{ "cons25", termcap_cons25 },
|
||||
{ "cons25-m", termcap_cons25_m } };
|
||||
|
||||
if (RunningAsInit) {
|
||||
while (1) {
|
||||
int i;
|
||||
|
||||
printf("\nThese are the predefined terminal types available to\n");
|
||||
printf("sysinstall when running stand-alone. Please choose the\n");
|
||||
printf("closest match for your particular terminal.\n\n");
|
||||
printf("1 ...................... Standard ANSI terminal.\n");
|
||||
printf("2 ...................... VT100 or compatible terminal.\n");
|
||||
printf("3 ...................... FreeBSD system console (color).\n");
|
||||
printf("4 ...................... FreeBSD system console (monochrome).\n\n");
|
||||
printf("Your choice: (1-4) ");
|
||||
fflush(stdout);
|
||||
fgets(str, 80, stdin);
|
||||
i = str[0] - '0';
|
||||
if (i > 0 && i < 5) {
|
||||
*termp = (char *)lookup[i - 1].term;
|
||||
*termcapp = (char *)lookup[i - 1].termcap;
|
||||
break;
|
||||
}
|
||||
else
|
||||
printf("\007Invalid choice, please try again.\n\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\nPlease set your TERM variable before running this program.\n");
|
||||
printf("Defaulting to an ANSI compatible terminal - please press RETURN\n");
|
||||
fgets(str, 80, stdin); /* Just to make it interactive */
|
||||
*termp = (char *)"ansi";
|
||||
*termcapp = (char *)termcap_ansi;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
set_termcap(void)
|
||||
{
|
||||
@ -31,7 +75,7 @@ set_termcap(void)
|
||||
term = getenv("TERM");
|
||||
stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);
|
||||
|
||||
if (getpid() != 1) {
|
||||
if (!RunningAsInit) {
|
||||
if (getenv("SYSINSTALL_DEBUG"))
|
||||
DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
||||
else
|
||||
@ -42,9 +86,12 @@ set_termcap(void)
|
||||
|
||||
if (!OnVTY || (stat < 0)) {
|
||||
if (!term) {
|
||||
if (setenv("TERM", "vt100", 1) < 0)
|
||||
char *term, *termcap;
|
||||
|
||||
prompt_term(&term, &termcap);
|
||||
if (setenv("TERM", term, 1) < 0)
|
||||
return -1;
|
||||
if (setenv("TERMCAP", termcap_vt100, 1) < 0)
|
||||
if (setenv("TERMCAP", termcap, 1) < 0)
|
||||
return -1;
|
||||
}
|
||||
if (DebugFD == -1)
|
||||
|
@ -30,6 +30,9 @@ LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio
|
||||
makedevs.c: Makefile rtermcap keymap.h
|
||||
rm -f makedevs.tmp
|
||||
echo '#include <sys/types.h>' > makedevs.tmp
|
||||
./rtermcap ansi | \
|
||||
file2c 'const char termcap_ansi[] = {' ',0};' \
|
||||
>> makedevs.tmp
|
||||
./rtermcap cons25 | \
|
||||
file2c 'const char termcap_cons25[] = {' ',0};' \
|
||||
>> makedevs.tmp
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated to essentially a complete rewrite.
|
||||
*
|
||||
* $Id: sysinstall.h,v 1.137 1997/06/22 09:45:40 jkh Exp $
|
||||
* $Id: sysinstall.h,v 1.138 1997/07/16 05:22:42 jkh Exp $
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@ -556,6 +556,7 @@ extern int diskLabelCommit(dialogMenuItem *self);
|
||||
extern int lndir(char *from, char *to);
|
||||
|
||||
/* makedevs.c (auto-generated) */
|
||||
extern const char termcap_ansi[];
|
||||
extern const char termcap_vt100[];
|
||||
extern const char termcap_cons25[];
|
||||
extern const char termcap_cons25_m[];
|
||||
|
@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: system.c,v 1.80 1997/04/28 10:31:14 jkh Exp $
|
||||
* $Id: system.c,v 1.81 1997/05/27 18:56:03 jkh Exp $
|
||||
*
|
||||
* Jordan Hubbard
|
||||
*
|
||||
@ -69,16 +69,37 @@ systemInitialize(int argc, char **argv)
|
||||
|
||||
/* Are we running as init? */
|
||||
if (getpid() == 1) {
|
||||
int fd, type;
|
||||
|
||||
RunningAsInit = 1;
|
||||
setsid();
|
||||
close(0);
|
||||
if (open("/dev/ttyv0", O_RDWR) < 0)
|
||||
open("/dev/console", O_RDWR);
|
||||
fd = open("/dev/ttyv0", O_RDWR);
|
||||
if (fd == -1)
|
||||
fd = open("/dev/console", O_RDWR); /* fallback */
|
||||
else
|
||||
OnVTY = TRUE;
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
type = 0; /* normal */
|
||||
if (OnVTY) {
|
||||
int fd2;
|
||||
|
||||
if ((fd2 = open("/dev/console", O_RDWR)) != -1) {
|
||||
if (ioctl(fd2, CONS_CURSORTYPE, &type) == -1) {
|
||||
OnVTY = FALSE;
|
||||
close(fd); close(fd2);
|
||||
open("/dev/console", O_RDWR);
|
||||
}
|
||||
else
|
||||
close(fd2);
|
||||
}
|
||||
}
|
||||
close(1); dup(0);
|
||||
close(2); dup(0);
|
||||
printf("%s running as init\n", argv[0]);
|
||||
RunningAsInit = 1;
|
||||
printf("%s running as init on %s\n", argv[0], OnVTY ? "vty0" : "serial console");
|
||||
i = ioctl(0, TIOCSCTTY, (char *)NULL);
|
||||
setlogin("root");
|
||||
setenv("PATH", "/stand:/bin:/sbin:/usr/sbin:/usr/bin:/mnt/bin:/mnt/sbin:/mnt/usr/sbin:/mnt/usr/bin:/usr/X11R6/bin", 1);
|
||||
|
@ -21,6 +21,50 @@
|
||||
#define VTY_STATUS_LINE 24
|
||||
#define TTY_STATUS_LINE 23
|
||||
|
||||
static void
|
||||
prompt_term(char **termp, char **termcapp)
|
||||
{
|
||||
char str[80];
|
||||
static struct {
|
||||
const char *term, *termcap;
|
||||
} lookup[] = { { "ansi", termcap_ansi },
|
||||
{ "vt100", termcap_vt100 },
|
||||
{ "cons25", termcap_cons25 },
|
||||
{ "cons25-m", termcap_cons25_m } };
|
||||
|
||||
if (RunningAsInit) {
|
||||
while (1) {
|
||||
int i;
|
||||
|
||||
printf("\nThese are the predefined terminal types available to\n");
|
||||
printf("sysinstall when running stand-alone. Please choose the\n");
|
||||
printf("closest match for your particular terminal.\n\n");
|
||||
printf("1 ...................... Standard ANSI terminal.\n");
|
||||
printf("2 ...................... VT100 or compatible terminal.\n");
|
||||
printf("3 ...................... FreeBSD system console (color).\n");
|
||||
printf("4 ...................... FreeBSD system console (monochrome).\n\n");
|
||||
printf("Your choice: (1-4) ");
|
||||
fflush(stdout);
|
||||
fgets(str, 80, stdin);
|
||||
i = str[0] - '0';
|
||||
if (i > 0 && i < 5) {
|
||||
*termp = (char *)lookup[i - 1].term;
|
||||
*termcapp = (char *)lookup[i - 1].termcap;
|
||||
break;
|
||||
}
|
||||
else
|
||||
printf("\007Invalid choice, please try again.\n\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\nPlease set your TERM variable before running this program.\n");
|
||||
printf("Defaulting to an ANSI compatible terminal - please press RETURN\n");
|
||||
fgets(str, 80, stdin); /* Just to make it interactive */
|
||||
*termp = (char *)"ansi";
|
||||
*termcapp = (char *)termcap_ansi;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
set_termcap(void)
|
||||
{
|
||||
@ -31,7 +75,7 @@ set_termcap(void)
|
||||
term = getenv("TERM");
|
||||
stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);
|
||||
|
||||
if (getpid() != 1) {
|
||||
if (!RunningAsInit) {
|
||||
if (getenv("SYSINSTALL_DEBUG"))
|
||||
DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
||||
else
|
||||
@ -42,9 +86,12 @@ set_termcap(void)
|
||||
|
||||
if (!OnVTY || (stat < 0)) {
|
||||
if (!term) {
|
||||
if (setenv("TERM", "vt100", 1) < 0)
|
||||
char *term, *termcap;
|
||||
|
||||
prompt_term(&term, &termcap);
|
||||
if (setenv("TERM", term, 1) < 0)
|
||||
return -1;
|
||||
if (setenv("TERMCAP", termcap_vt100, 1) < 0)
|
||||
if (setenv("TERMCAP", termcap, 1) < 0)
|
||||
return -1;
|
||||
}
|
||||
if (DebugFD == -1)
|
||||
|
Loading…
Reference in New Issue
Block a user