diff --git a/release/sysinstall/Makefile b/release/sysinstall/Makefile index 06470aa83ecb..357ca6eaba14 100644 --- a/release/sysinstall/Makefile +++ b/release/sysinstall/Makefile @@ -30,6 +30,9 @@ LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio makedevs.c: Makefile rtermcap keymap.h rm -f makedevs.tmp echo '#include ' > makedevs.tmp + ./rtermcap ansi | \ + file2c 'const char termcap_ansi[] = {' ',0};' \ + >> makedevs.tmp ./rtermcap cons25 | \ file2c 'const char termcap_cons25[] = {' ',0};' \ >> makedevs.tmp diff --git a/release/sysinstall/sysinstall.h b/release/sysinstall/sysinstall.h index 11e6fc5e4ac1..d190a2878868 100644 --- a/release/sysinstall/sysinstall.h +++ b/release/sysinstall/sysinstall.h @@ -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[]; diff --git a/release/sysinstall/system.c b/release/sysinstall/system.c index 22a705299318..61a27c4ef294 100644 --- a/release/sysinstall/system.c +++ b/release/sysinstall/system.c @@ -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); diff --git a/release/sysinstall/termcap.c b/release/sysinstall/termcap.c index 992cb60ee607..fa9c19ff2a1e 100644 --- a/release/sysinstall/termcap.c +++ b/release/sysinstall/termcap.c @@ -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) diff --git a/usr.sbin/sade/Makefile b/usr.sbin/sade/Makefile index 06470aa83ecb..357ca6eaba14 100644 --- a/usr.sbin/sade/Makefile +++ b/usr.sbin/sade/Makefile @@ -30,6 +30,9 @@ LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio makedevs.c: Makefile rtermcap keymap.h rm -f makedevs.tmp echo '#include ' > makedevs.tmp + ./rtermcap ansi | \ + file2c 'const char termcap_ansi[] = {' ',0};' \ + >> makedevs.tmp ./rtermcap cons25 | \ file2c 'const char termcap_cons25[] = {' ',0};' \ >> makedevs.tmp diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h index 11e6fc5e4ac1..d190a2878868 100644 --- a/usr.sbin/sade/sade.h +++ b/usr.sbin/sade/sade.h @@ -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[]; diff --git a/usr.sbin/sade/system.c b/usr.sbin/sade/system.c index 22a705299318..61a27c4ef294 100644 --- a/usr.sbin/sade/system.c +++ b/usr.sbin/sade/system.c @@ -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); diff --git a/usr.sbin/sade/termcap.c b/usr.sbin/sade/termcap.c index 992cb60ee607..fa9c19ff2a1e 100644 --- a/usr.sbin/sade/termcap.c +++ b/usr.sbin/sade/termcap.c @@ -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) diff --git a/usr.sbin/sysinstall/Makefile b/usr.sbin/sysinstall/Makefile index 06470aa83ecb..357ca6eaba14 100644 --- a/usr.sbin/sysinstall/Makefile +++ b/usr.sbin/sysinstall/Makefile @@ -30,6 +30,9 @@ LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio makedevs.c: Makefile rtermcap keymap.h rm -f makedevs.tmp echo '#include ' > makedevs.tmp + ./rtermcap ansi | \ + file2c 'const char termcap_ansi[] = {' ',0};' \ + >> makedevs.tmp ./rtermcap cons25 | \ file2c 'const char termcap_cons25[] = {' ',0};' \ >> makedevs.tmp diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h index 11e6fc5e4ac1..d190a2878868 100644 --- a/usr.sbin/sysinstall/sysinstall.h +++ b/usr.sbin/sysinstall/sysinstall.h @@ -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[]; diff --git a/usr.sbin/sysinstall/system.c b/usr.sbin/sysinstall/system.c index 22a705299318..61a27c4ef294 100644 --- a/usr.sbin/sysinstall/system.c +++ b/usr.sbin/sysinstall/system.c @@ -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); diff --git a/usr.sbin/sysinstall/termcap.c b/usr.sbin/sysinstall/termcap.c index 992cb60ee607..fa9c19ff2a1e 100644 --- a/usr.sbin/sysinstall/termcap.c +++ b/usr.sbin/sysinstall/termcap.c @@ -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)