From ambrisko@whistle.com  Fri Oct 27 10:30:10 2000
Return-Path: <ambrisko@whistle.com>
Received: from alpo.whistle.com (s206m1.whistle.com [207.76.206.1])
	by hub.freebsd.org (Postfix) with ESMTP id E992D37B4C5
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Oct 2000 10:30:09 -0700 (PDT)
Received: from whistle.com (crab.whistle.com [207.76.205.112])
	by alpo.whistle.com (8.9.1a/8.9.1) with ESMTP id KAA77603
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Oct 2000 10:26:42 -0700 (PDT)
Received: (from ambrisko@localhost)
	by whistle.com (8.9.3/8.9.1) id KAA23612;
	Fri, 27 Oct 2000 10:26:29 -0700 (PDT)
	(envelope-from ambrisko)
Message-Id: <200010271726.KAA23612@whistle.com>
Date: Fri, 27 Oct 2000 10:26:29 -0700 (PDT)
From: Doug Ambrisko <ambrisko@whistle.com>
Reply-To: ambrisko@whistle.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: Fixit doesn't quite work on serial console - sysinstall bug. <Synopsis of the problem (one line)>
X-Send-Pr-Version: 3.2

>Number:         22352
>Category:       bin
>Synopsis:       Fixit doesn't quite work on serial console - sysinstall bug.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 27 10:40:00 PDT 2000
>Closed-Date:    Mon Oct 30 16:03:53 PST 2000
>Last-Modified:  Mon Oct 30 16:04:02 PST 2000
>Originator:     Doug Ambrisko
>Release:        FreeBSD 4.1-STABLE
>Organization:
Whistle 
>Environment:
Doing a sysinstall on a serial console results in fixit not working.
	

>Description:
Changes have been made to support a concept of VAR_FIXIT_TTY being
standard or serial.  This change needs to be done to the entire system that
depends on this.  This way we don't have some code using OnVTY checks
and other doing 
	strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0
checks.  Also we need to set VAR_FIXIT_TTY to "serial" if we come up on
a serial console.  

Also fixed a dialog problem in that dialog was used when dialog was 
disabled causing some troubles such as not letting the cursor keys
work when exiting the fixit mode on media (ie. not the fixit shell but
for example fixit on a floppy).

I have tested this with under vmware in both serial and non-serial
use.
	

>How-To-Repeat:

	

>Fix:

Index: install.c
===================================================================
RCS file: /cvs/freebsd/src/release/sysinstall/install.c,v
retrieving revision 1.268.2.11
diff -c -r1.268.2.11 install.c
*** install.c	2000/09/16 09:08:44	1.268.2.11
--- install.c	2000/10/27 17:15:00
***************
*** 400,406 ****
  	msgConfirm("Couldn't symlink the /etc/ files!  I'm not sure I like this..");
      if (!file_readable(TERMCAP_FILE))
  	create_termcap();
!     if (!OnVTY)
  	systemSuspendDialog();	/* must be before the fork() */
      if (!(child = fork())) {
  	int i, fd, fdstop;
--- 400,406 ----
  	msgConfirm("Couldn't symlink the /etc/ files!  I'm not sure I like this..");
      if (!file_readable(TERMCAP_FILE))
  	create_termcap();
!     if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 
  	systemSuspendDialog();	/* must be before the fork() */
      if (!(child = fork())) {
  	int i, fd, fdstop;
***************
*** 408,422 ****
  	extern int login_tty(int);
  
  	ioctl(0, TIOCNOTTY, NULL);
! 	fdstop = strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0 ? 3 : 0;
! 	for (i = getdtablesize(); i >= fdstop; --i)
  	    close(i);
! 	if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
  	    fd = open("/dev/ttyv3", O_RDWR);
! 	    ioctl(0, TIOCSCTTY, &fd);
! 	    dup2(0, 1);
! 	    dup2(0, 2);
! 	}
  	DebugFD = 2;
  	if (login_tty(fd) == -1)
  	    msgDebug("fixit: I can't set the controlling terminal.\n");
--- 408,423 ----
  	extern int login_tty(int);
  
  	ioctl(0, TIOCNOTTY, NULL);
! 	for (i = getdtablesize(); i >= 0; --i)
  	    close(i);
! 
! 	if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 
! 	    fd = open("/dev/console", O_RDWR);
! 	else
  	    fd = open("/dev/ttyv3", O_RDWR);
! 	ioctl(0, TIOCSCTTY, &fd);
! 	dup2(0, 1);
! 	dup2(0, 2);
  	DebugFD = 2;
  	if (login_tty(fd) == -1)
  	    msgDebug("fixit: I can't set the controlling terminal.\n");
***************
*** 431,436 ****
--- 432,444 ----
  	    msgDebug("fixit shell: Unable to get terminal attributes!\n");
  	setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:"
  	       "/mnt2/stand:/mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin", 1);
+ 	if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) {
+ 	    printf("Waiting for fixit shell to exit.\n"
+ 		"When you are done, type ``exit'' to exit\n"
+ 		"the fixit shell and be returned here.\n\n");
+ 	    fflush(stdout);
+ 	}
+ 
  	/* use the .profile from the fixit medium */
  	setenv("HOME", "/mnt2", 1);
  	chdir("/mnt2");
***************
*** 439,455 ****
  	_exit(1);;
      }
      else {
- 	dialog_clear_norefresh();
  	if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
  	    msgNotify("Waiting for fixit shell to exit.  Go to VTY4 now by\n"
  		"typing ALT-F4.  When you are done, type ``exit'' to exit\n"
! 		"the fixit shell and be returned here.");
! 	} else {
! 	    msgNotify("Waiting for fixit shell to exit.\n"
! 		"When you are done, type ``exit'' to exit\n"
! 		"the fixit shell and be returned here.");
  	}
  	(void)waitpid(child, &waitstatus, 0);
      }
      dialog_clear();
  }
--- 447,461 ----
  	_exit(1);;
      }
      else {
  	if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
+ 	    dialog_clear_norefresh();
  	    msgNotify("Waiting for fixit shell to exit.  Go to VTY4 now by\n"
  		"typing ALT-F4.  When you are done, type ``exit'' to exit\n"
! 		"the fixit shell and be returned here\n.");
  	}
  	(void)waitpid(child, &waitstatus, 0);
+ 	if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
+ 	    systemResumeDialog();
      }
      dialog_clear();
  }
***************
*** 1047,1053 ****
      variable_set2(VAR_BROWSER_BINARY,		"/usr/local/bin/lynx", 0);
      variable_set2(VAR_FTP_STATE,		"passive", 0);
      variable_set2(VAR_NFS_SECURE,		"NO", -1);
!     variable_set2(VAR_FIXIT_TTY,		"standard", 0);
      variable_set2(VAR_PKG_TMPDIR,		"/usr/tmp", 0);
      variable_set2(VAR_MEDIA_TIMEOUT,		itoa(MEDIA_TIMEOUT), 0);
      if (getpid() != 1)
--- 1053,1062 ----
      variable_set2(VAR_BROWSER_BINARY,		"/usr/local/bin/lynx", 0);
      variable_set2(VAR_FTP_STATE,		"passive", 0);
      variable_set2(VAR_NFS_SECURE,		"NO", -1);
!     if (OnVTY)
! 	    variable_set2(VAR_FIXIT_TTY,		"standard", 0);
!     else
! 	    variable_set2(VAR_FIXIT_TTY,		"serial", 0);
      variable_set2(VAR_PKG_TMPDIR,		"/usr/tmp", 0);
      variable_set2(VAR_MEDIA_TIMEOUT,		itoa(MEDIA_TIMEOUT), 0);
      if (getpid() != 1)
Index: system.c
===================================================================
RCS file: /cvs/freebsd/src/release/sysinstall/system.c,v
retrieving revision 1.103.2.2
diff -c -r1.103.2.2 system.c
*** system.c	2000/07/18 09:16:43	1.103.2.2
--- system.c	2000/10/27 17:15:00
***************
*** 92,100 ****
  	setsid();
  	close(0);
  	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
--- 92,101 ----
  	setsid();
  	close(0);
  	fd = open("/dev/ttyv0", O_RDWR);
! 	if (fd == -1) {
  	    fd = open("/dev/console", O_RDWR);	/* fallback */
! 	    variable_set2(VAR_FIXIT_TTY, "serial", 0); /* give fixit a hint */
! 	} else
  	    OnVTY = TRUE;
  	/*
  	 * To make _sure_ we're on a VTY and don't have /dev/console switched
***************
*** 107,112 ****
--- 108,116 ----
  	    if ((fd2 = open("/dev/console", O_RDWR)) != -1) {
  		if (ioctl(fd2, CONS_CURSORTYPE, &type) == -1) {
  		    OnVTY = FALSE;
+ 		    variable_set2(VAR_FIXIT_TTY, "serial", 0); /* Tell Fixit
+ 								  the console
+ 								  type */
  		    close(fd); close(fd2);
  		    open("/dev/console", O_RDWR);
  		}
***************
*** 401,407 ****
  	    (void) waitpid(ehs_pid, &pstat, WNOHANG);
  	}
  
! 	if (!OnVTY)
  	    systemSuspendDialog();	/* must be before the fork() */
  	if ((ehs_pid = fork()) == 0) {
  	    int i, fd;
--- 405,411 ----
  	    (void) waitpid(ehs_pid, &pstat, WNOHANG);
  	}
  
! 	if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 
  	    systemSuspendDialog();	/* must be before the fork() */
  	if ((ehs_pid = fork()) == 0) {
  	    int i, fd;
***************
*** 411,420 ****
  	    ioctl(0, TIOCNOTTY, NULL);
  	    for (i = getdtablesize(); i >= 0; --i)
  		close(i);
! 	    if (OnVTY)
! 	        fd = open("/dev/ttyv3", O_RDWR);
! 	    else
  	        fd = open("/dev/console", O_RDWR);
  	    ioctl(0, TIOCSCTTY, &fd);
  	    dup2(0, 1);
  	    dup2(0, 2);
--- 415,424 ----
  	    ioctl(0, TIOCNOTTY, NULL);
  	    for (i = getdtablesize(); i >= 0; --i)
  		close(i);
! 	    if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 
  	        fd = open("/dev/console", O_RDWR);
+ 	    else
+ 	        fd = open("/dev/ttyv3", O_RDWR);
  	    ioctl(0, TIOCSCTTY, &fd);
  	    dup2(0, 1);
  	    dup2(0, 2);
***************
*** 429,435 ****
  	    }
  	    else
  		msgDebug("Doctor: I'm unable to get the terminal attributes!\n");
! 	    if (!OnVTY){
  	        printf("Type ``exit'' in this fixit shell to resume sysinstall.\n\n");
  		fflush(stdout);
  	    }
--- 433,439 ----
  	    }
  	    else
  		msgDebug("Doctor: I'm unable to get the terminal attributes!\n");
! 	    if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) {
  	        printf("Type ``exit'' in this fixit shell to resume sysinstall.\n\n");
  		fflush(stdout);
  	    }
***************
*** 438,452 ****
  	    exit(1);
  	}
  	else {
! 	    if (OnVTY) {
  	        WINDOW *w = savescr();
  
  	        msgNotify("Starting an emergency holographic shell on VTY4");
  	        sleep(2);
  	        restorescr(w);
  	    }
! 	    if (!OnVTY){
! 	        (void)waitpid(ehs_pid, &waitstatus, 0);
  	        systemResumeDialog();
  	    }
  	}
--- 442,460 ----
  	    exit(1);
  	}
  	else {
! 	    if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
  	        WINDOW *w = savescr();
  
  	        msgNotify("Starting an emergency holographic shell on VTY4");
  	        sleep(2);
  	        restorescr(w);
  	    }
! 	    else {
! 	        (void)waitpid(ehs_pid, &waitstatus, 0); /* we only wait for
! 							   shell to finish 
! 							   it serial mode
! 							   since there is no
! 							   virtual console */
  	        systemResumeDialog();
  	    }
  	}

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: jedgar 
Responsible-Changed-When: Sun Oct 29 04:39:38 PST 2000 
Responsible-Changed-Why:  
Misfiled PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22352 
State-Changed-From-To: open->closed 
State-Changed-By: jkh 
State-Changed-When: Mon Oct 30 16:03:53 PST 2000 
State-Changed-Why:  
Committed, thanks 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22352 
>Unformatted:
