2003-02-09 19:31:05 +03:00
|
|
|
/* $NetBSD: run.c,v 1.38 2003/02/09 16:31:05 martin Exp $ */
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1999-06-20 10:08:13 +04:00
|
|
|
* This product includes software developed for the NetBSD Project by
|
1997-09-27 03:02:53 +04:00
|
|
|
* Piermont Information Systems Inc.
|
|
|
|
* 4. The name of Piermont Information Systems Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* run.c -- routines to interact with other programs. */
|
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
/* XXX write return codes ignored. XXX */
|
|
|
|
|
|
|
|
#include <errno.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
1999-01-21 11:02:17 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <curses.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <util.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <sys/ioctl.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <sys/types.h>
|
1999-01-21 11:02:17 +03:00
|
|
|
#include <sys/wait.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "defs.h"
|
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
#include "menu_defs.h"
|
1997-11-02 06:45:27 +03:00
|
|
|
#include "msg_defs.h"
|
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
#define MAXBUF 256
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
#ifdef DEBUG
|
1997-09-27 04:09:22 +04:00
|
|
|
#define Xsystem(y) printf ("%s\n", y), 0
|
1997-09-27 03:02:53 +04:00
|
|
|
#else
|
|
|
|
#define Xsystem(y) system(y)
|
|
|
|
#endif
|
|
|
|
|
1997-11-02 06:45:27 +03:00
|
|
|
/*
|
|
|
|
* local prototypes
|
|
|
|
*/
|
2001-09-13 22:07:26 +04:00
|
|
|
static int launch_subwin (WINDOW *actionwin, char **args, struct winsize *win,
|
|
|
|
int display, const char **errstr);
|
2000-12-22 13:12:12 +03:00
|
|
|
int log_flip (menudesc *);
|
|
|
|
int script_flip (menudesc *);
|
1997-11-02 06:45:27 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
#define BUFSIZE 4096
|
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
char log_text[2][30] = {"Logging: Off", "Scripting: Off"};
|
|
|
|
|
|
|
|
menu_ent logmenu [2] = {
|
|
|
|
{ log_text[0], OPT_NOMENU, 0, log_flip},
|
|
|
|
{ log_text[1], OPT_NOMENU, 0, script_flip} };
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
do_logging(void)
|
|
|
|
{
|
|
|
|
int menu_no;
|
|
|
|
|
1999-06-21 00:26:42 +04:00
|
|
|
menu_no = new_menu ("Logging Functions", logmenu, 2, -1, 12,
|
|
|
|
0, 20, MC_SCROLL, NULL, NULL, "Pick an option to turn on or off.\n");
|
1999-01-21 11:02:17 +03:00
|
|
|
|
|
|
|
if (menu_no < 0) {
|
|
|
|
(void)fprintf(stderr, "Dynamic menu creation failed.\n");
|
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp, "Dynamic menu creation failed.\n");
|
1999-01-21 11:02:17 +03:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
process_menu(menu_no);
|
|
|
|
free_menu(menu_no);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-10 23:00:27 +03:00
|
|
|
/*ARGSUSED*/
|
2000-08-15 05:08:00 +04:00
|
|
|
log_flip(menudesc *m)
|
1999-01-21 11:02:17 +03:00
|
|
|
{
|
|
|
|
time_t tloc;
|
|
|
|
|
|
|
|
(void)time(&tloc);
|
|
|
|
if (logging == 1) {
|
|
|
|
sprintf(log_text[0], "Logging: Off");
|
|
|
|
logging = 0;
|
2002-12-05 04:17:15 +03:00
|
|
|
fprintf(logfp, "Log ended at: %s\n", asctime(localtime(&tloc)));
|
|
|
|
fflush(logfp);
|
|
|
|
fclose(logfp);
|
1999-01-21 11:02:17 +03:00
|
|
|
} else {
|
2002-12-05 04:17:15 +03:00
|
|
|
logfp = fopen("sysinst.log", "a");
|
|
|
|
if (logfp != NULL) {
|
2000-01-07 05:02:05 +03:00
|
|
|
sprintf(log_text[0], "Logging: On");
|
|
|
|
logging = 1;
|
2002-12-05 04:17:15 +03:00
|
|
|
fprintf(logfp,
|
|
|
|
"Log started at: %s\n", asctime(localtime(&tloc)));
|
|
|
|
fflush(logfp);
|
2000-01-07 05:02:05 +03:00
|
|
|
} else {
|
|
|
|
msg_display(MSG_openfail, "log file", strerror(errno));
|
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-10 23:00:27 +03:00
|
|
|
/*ARGSUSED*/
|
2000-08-15 05:08:00 +04:00
|
|
|
script_flip(menudesc *m)
|
1999-01-21 11:02:17 +03:00
|
|
|
{
|
|
|
|
time_t tloc;
|
|
|
|
|
|
|
|
(void)time(&tloc);
|
|
|
|
if (scripting == 1) {
|
|
|
|
sprintf(log_text[1], "Scripting: Off");
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "# Script ended at: %s\n", asctime(localtime(&tloc)));
|
1999-01-21 11:02:17 +03:00
|
|
|
scripting = 0;
|
|
|
|
fflush(script);
|
|
|
|
fclose(script);
|
|
|
|
} else {
|
|
|
|
script = fopen("sysinst.sh", "w");
|
2000-01-07 05:02:05 +03:00
|
|
|
if (script != NULL) {
|
|
|
|
sprintf(log_text[1], "Scripting: On");
|
|
|
|
scripting = 1;
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "#!/bin/sh\n");
|
|
|
|
scripting_fprintf(NULL, "# Script started at: %s\n",
|
2000-01-07 05:02:05 +03:00
|
|
|
asctime(localtime(&tloc)));
|
|
|
|
fflush(script);
|
|
|
|
} else {
|
|
|
|
msg_display(MSG_openfail, "script file", strerror(errno));
|
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
int
|
1998-06-20 17:05:48 +04:00
|
|
|
collect(int kind, char **buffer, const char *name, ...)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
size_t nbytes; /* Number of bytes in buffer. */
|
|
|
|
size_t fbytes; /* Number of bytes in file. */
|
|
|
|
struct stat st; /* stat information. */
|
|
|
|
int ch;
|
|
|
|
FILE *f;
|
|
|
|
char fileorcmd [STRSIZE];
|
|
|
|
va_list ap;
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
va_start(ap, name);
|
|
|
|
vsnprintf(fileorcmd, STRSIZE, name, ap);
|
|
|
|
va_end(ap);
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
if (kind == T_FILE) {
|
|
|
|
/* Get the file information. */
|
1998-06-20 17:05:48 +04:00
|
|
|
if (stat(fileorcmd, &st)) {
|
1997-09-27 03:02:53 +04:00
|
|
|
*buffer = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fbytes = (size_t)st.st_size;
|
|
|
|
|
|
|
|
/* Open the file. */
|
1998-06-20 17:05:48 +04:00
|
|
|
f = fopen(fileorcmd, "r");
|
1997-09-27 03:02:53 +04:00
|
|
|
if (f == NULL) {
|
|
|
|
*buffer = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Open the program. */
|
1998-06-20 17:05:48 +04:00
|
|
|
f = popen(fileorcmd, "r");
|
1997-09-27 03:02:53 +04:00
|
|
|
if (f == NULL) {
|
|
|
|
*buffer = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fbytes = BUFSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fbytes == 0)
|
|
|
|
fbytes = BUFSIZE;
|
|
|
|
|
|
|
|
/* Allocate the buffer size. */
|
1998-06-20 17:05:48 +04:00
|
|
|
*buffer = (char *)malloc(fbytes + 1);
|
1997-09-27 03:02:53 +04:00
|
|
|
if (!*buffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Read the buffer. */
|
|
|
|
nbytes = 0;
|
|
|
|
while (nbytes < fbytes && (ch = fgetc(f)) != EOF)
|
|
|
|
(*buffer)[nbytes++] = ch;
|
|
|
|
|
|
|
|
(*buffer)[nbytes] = 0;
|
|
|
|
|
|
|
|
if (kind == T_FILE)
|
|
|
|
fclose(f);
|
|
|
|
else
|
|
|
|
pclose(f);
|
|
|
|
|
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-02 06:45:27 +03:00
|
|
|
/*
|
|
|
|
* system(3), but with a debug wrapper.
|
1999-01-21 11:02:17 +03:00
|
|
|
* use only for curses sub-applications.
|
1997-11-02 06:45:27 +03:00
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
|
|
|
do_system(execstr)
|
|
|
|
const char *execstr;
|
1997-11-02 06:45:27 +03:00
|
|
|
{
|
|
|
|
register int ret;
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* The following may be more than one function call. Can't just
|
|
|
|
* "return Xsystem (command);"
|
|
|
|
*/
|
1997-11-02 06:45:27 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
ret = Xsystem(execstr);
|
|
|
|
return (ret);
|
1997-11-02 06:45:27 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-01-21 11:02:17 +03:00
|
|
|
* launch a program inside a subwindow, and report it's return status when done
|
1997-11-02 06:45:27 +03:00
|
|
|
*/
|
2001-09-13 22:07:26 +04:00
|
|
|
static int
|
|
|
|
launch_subwin(actionwin, args, win, flags, errstr)
|
1999-01-21 11:02:17 +03:00
|
|
|
WINDOW *actionwin;
|
|
|
|
char **args;
|
2000-10-12 03:47:55 +04:00
|
|
|
struct winsize *win;
|
|
|
|
int flags;
|
2001-09-13 22:07:26 +04:00
|
|
|
const char **errstr;
|
1997-11-02 06:45:27 +03:00
|
|
|
{
|
1999-01-21 11:02:17 +03:00
|
|
|
int xcor,ycor;
|
|
|
|
int n, i, j;
|
1999-03-22 12:02:47 +03:00
|
|
|
int selectfailed;
|
1999-01-21 11:02:17 +03:00
|
|
|
int status, master, slave;
|
|
|
|
fd_set active_fd_set, read_fd_set;
|
|
|
|
int dataflow[2];
|
|
|
|
pid_t child, subchild, pid;
|
|
|
|
char ibuf[MAXBUF], obuf[MAXBUF];
|
2000-10-12 03:47:55 +04:00
|
|
|
char pktdata;
|
1999-01-21 11:02:17 +03:00
|
|
|
struct termios rtt;
|
|
|
|
struct termios tt;
|
|
|
|
|
2001-09-13 22:07:26 +04:00
|
|
|
if (pipe(dataflow) < 0) {
|
|
|
|
*errstr = "pipe() failed";
|
|
|
|
return (1);
|
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
|
|
|
|
(void)tcgetattr(STDIN_FILENO, &tt);
|
2001-09-13 22:07:26 +04:00
|
|
|
if (openpty(&master, &slave, NULL, &tt, win) == -1) {
|
|
|
|
*errstr = "openpty() failed";
|
1999-01-21 11:02:17 +03:00
|
|
|
return(1);
|
2001-09-13 22:07:26 +04:00
|
|
|
}
|
|
|
|
|
2000-10-12 03:47:55 +04:00
|
|
|
#if 0
|
1999-01-21 11:02:17 +03:00
|
|
|
rtt = tt;
|
2000-10-12 03:47:55 +04:00
|
|
|
rtt.c_lflag |= (ICANON|ECHO);
|
1999-01-21 11:02:17 +03:00
|
|
|
(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt);
|
2000-10-12 03:47:55 +04:00
|
|
|
#endif
|
|
|
|
rtt = tt;
|
1999-01-21 11:02:17 +03:00
|
|
|
|
1999-06-22 04:43:57 +04:00
|
|
|
/* ignore tty signals until we're done with subprocess setup */
|
2000-01-19 12:44:01 +03:00
|
|
|
endwin();
|
1999-06-22 04:43:57 +04:00
|
|
|
ttysig_ignore = 1;
|
2000-10-12 03:47:55 +04:00
|
|
|
ioctl(master, TIOCPKT, &ttysig_ignore);
|
1999-06-22 04:43:57 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
switch(child=fork()) {
|
|
|
|
case -1:
|
1999-06-22 04:43:57 +04:00
|
|
|
ttysig_ignore = 0;
|
2000-01-19 12:44:01 +03:00
|
|
|
refresh();
|
2001-09-13 22:07:26 +04:00
|
|
|
*errstr = "fork() failed";
|
1999-01-21 11:02:17 +03:00
|
|
|
return -1;
|
1999-03-22 12:02:47 +03:00
|
|
|
case 0:
|
1999-01-21 11:02:17 +03:00
|
|
|
(void)close(STDIN_FILENO);
|
|
|
|
subchild = fork();
|
|
|
|
if (subchild == 0) {
|
|
|
|
close(dataflow[0]);
|
|
|
|
for (;;) {
|
|
|
|
n = read(master, obuf, sizeof(obuf));
|
|
|
|
if (n <= 0)
|
|
|
|
break;
|
2003-01-10 23:00:27 +03:00
|
|
|
write(dataflow[1], obuf, (size_t)n);
|
1999-01-21 11:02:17 +03:00
|
|
|
} /* while spinning */
|
|
|
|
_exit(EXIT_SUCCESS);
|
|
|
|
} /* subchild, child forks */
|
|
|
|
(void)close(master);
|
|
|
|
close(dataflow[1]);
|
|
|
|
close(dataflow[0]);
|
2000-10-12 03:47:55 +04:00
|
|
|
rtt = tt;
|
|
|
|
rtt.c_lflag |= (ICANON|ECHO);
|
|
|
|
(void)tcsetattr(slave, TCSANOW, &rtt);
|
1999-01-21 11:02:17 +03:00
|
|
|
login_tty(slave);
|
|
|
|
if (logging) {
|
2003-01-10 23:00:27 +03:00
|
|
|
fprintf(logfp, "executing:");
|
|
|
|
for (i = 0; args[i]; i++)
|
|
|
|
fprintf(logfp, " %s", args[i]);
|
|
|
|
fprintf(logfp, "\n");
|
2002-12-05 04:17:15 +03:00
|
|
|
fclose(logfp);
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
|
|
|
if (scripting) {
|
2003-01-10 23:00:27 +03:00
|
|
|
for (i = 0; args[i]; i++)
|
|
|
|
fprintf(script, "%s ", args[i]);
|
|
|
|
fprintf(script, "\n");
|
1999-01-21 11:02:17 +03:00
|
|
|
fclose(script);
|
|
|
|
}
|
2000-10-12 03:47:55 +04:00
|
|
|
/*
|
|
|
|
* If target_prefix == "", the chroot will fail, but
|
|
|
|
* that's ok, since we don't need it then.
|
|
|
|
*/
|
|
|
|
if ((flags & RUN_CHROOT) != 0)
|
|
|
|
chroot(target_prefix());
|
2003-01-10 23:00:27 +03:00
|
|
|
execvp(*args, args);
|
1999-03-11 19:48:27 +03:00
|
|
|
/* the parent will see this as the output from the
|
|
|
|
child */
|
2003-01-10 23:00:27 +03:00
|
|
|
warn("execvp %s", *args);
|
1999-03-11 19:48:27 +03:00
|
|
|
_exit(EXIT_FAILURE);
|
1999-03-22 12:02:47 +03:00
|
|
|
break; /* end of child */
|
1999-06-22 04:43:57 +04:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* we've set up the subprocess. forward tty signals to its * process group.
|
|
|
|
*/
|
|
|
|
ttysig_forward = child;
|
|
|
|
ttysig_ignore = 0;
|
2000-01-19 12:44:01 +03:00
|
|
|
refresh();
|
1999-06-22 04:43:57 +04:00
|
|
|
break;
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
|
|
|
close(dataflow[1]);
|
|
|
|
FD_ZERO(&active_fd_set);
|
|
|
|
FD_SET(dataflow[0], &active_fd_set);
|
|
|
|
FD_SET(STDIN_FILENO, &active_fd_set);
|
|
|
|
|
1999-03-22 12:02:47 +03:00
|
|
|
for (selectfailed = 0;;) {
|
|
|
|
if (selectfailed) {
|
2003-01-10 23:00:27 +03:00
|
|
|
char *mmsg = "select(2) failed but no child died?";
|
1999-03-22 12:02:47 +03:00
|
|
|
if(logging)
|
2003-01-10 23:00:27 +03:00
|
|
|
(void)fprintf(logfp, mmsg);
|
|
|
|
errx(1, mmsg);
|
1999-03-22 12:02:47 +03:00
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
read_fd_set = active_fd_set;
|
|
|
|
if (select(FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0) {
|
1999-06-22 04:43:57 +04:00
|
|
|
if (errno == EINTR)
|
|
|
|
goto loop;
|
2003-01-10 23:00:27 +03:00
|
|
|
warn("select");
|
1999-01-21 11:02:17 +03:00
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp,
|
|
|
|
"select failure: %s\n", strerror(errno));
|
1999-03-22 12:02:47 +03:00
|
|
|
++selectfailed;
|
|
|
|
} else for (i = 0; i < FD_SETSIZE; ++i) {
|
1999-01-21 11:02:17 +03:00
|
|
|
if (FD_ISSET (i, &read_fd_set)) {
|
|
|
|
n = read(i, ibuf, MAXBUF);
|
2003-01-10 23:00:27 +03:00
|
|
|
if (n <= 0) {
|
2003-02-09 19:31:05 +03:00
|
|
|
if (n < 0)
|
|
|
|
warn("read");
|
2003-01-10 23:00:27 +03:00
|
|
|
continue;
|
|
|
|
}
|
2000-10-12 03:47:55 +04:00
|
|
|
if (i == STDIN_FILENO) {
|
2003-01-10 23:00:27 +03:00
|
|
|
(void)write(master, ibuf, (size_t)n);
|
2000-10-12 03:47:55 +04:00
|
|
|
if ((rtt.c_lflag & ECHO) == 0)
|
|
|
|
goto enddisp;
|
|
|
|
}
|
|
|
|
pktdata = ibuf[0];
|
|
|
|
if (pktdata != 0 && i != STDIN_FILENO) {
|
|
|
|
if (pktdata & TIOCPKT_IOCTL)
|
2003-01-10 23:00:27 +03:00
|
|
|
memcpy(&rtt, ibuf, sizeof(rtt));
|
2000-10-12 03:47:55 +04:00
|
|
|
goto enddisp;
|
|
|
|
}
|
|
|
|
for (j=1; j < n; j++) {
|
|
|
|
if ((flags & RUN_DISPLAY) != 0) {
|
2000-01-19 12:44:01 +03:00
|
|
|
switch (ibuf[j]) {
|
|
|
|
case '\n':
|
1999-06-21 06:47:41 +04:00
|
|
|
getyx(actionwin, ycor, xcor);
|
2000-04-15 01:46:11 +04:00
|
|
|
if (ycor + 1 >= getmaxy(actionwin)) {
|
1999-06-21 06:31:17 +04:00
|
|
|
scroll(actionwin);
|
2000-04-15 01:46:11 +04:00
|
|
|
wmove(actionwin, getmaxy(actionwin) - 1, 0);
|
1999-06-21 06:31:17 +04:00
|
|
|
} else
|
1999-06-21 06:47:41 +04:00
|
|
|
wmove(actionwin, ycor + 1, 0);
|
2000-01-19 12:44:01 +03:00
|
|
|
break;
|
|
|
|
case '\r':
|
1999-06-21 06:47:41 +04:00
|
|
|
getyx(actionwin, ycor, xcor);
|
|
|
|
wmove(actionwin, ycor, 0);
|
2000-01-19 12:44:01 +03:00
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
getyx(actionwin, ycor, xcor);
|
|
|
|
if (xcor > 0)
|
|
|
|
wmove(actionwin, ycor, xcor - 1);
|
|
|
|
break;
|
|
|
|
default:
|
1999-01-21 11:02:17 +03:00
|
|
|
waddch(actionwin, ibuf[j]);
|
2000-01-19 12:44:01 +03:00
|
|
|
break;
|
|
|
|
}
|
1999-06-21 06:47:41 +04:00
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
putc(ibuf[j], logfp);
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
|
|
|
}
|
2000-10-12 03:47:55 +04:00
|
|
|
enddisp:
|
|
|
|
if ((flags & RUN_DISPLAY) != 0)
|
2000-01-19 12:44:01 +03:00
|
|
|
wrefresh(actionwin);
|
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
fflush(logfp);
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
1999-03-22 12:02:47 +03:00
|
|
|
}
|
1999-06-22 04:43:57 +04:00
|
|
|
loop:
|
1999-01-21 11:02:17 +03:00
|
|
|
pid = wait4(child, &status, WNOHANG, 0);
|
|
|
|
if (pid == child && (WIFEXITED(status) || WIFSIGNALED(status)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
close(dataflow[0]); /* clean up our leaks */
|
|
|
|
close(master);
|
|
|
|
close(slave);
|
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
fflush(logfp);
|
1999-01-21 11:02:17 +03:00
|
|
|
|
1999-06-22 04:43:57 +04:00
|
|
|
/* from here on out, we take tty signals ourselves */
|
|
|
|
ttysig_forward = 0;
|
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt);
|
1999-06-22 04:43:57 +04:00
|
|
|
|
2001-09-13 22:07:26 +04:00
|
|
|
if (WIFEXITED(status)) {
|
|
|
|
*errstr = "command failed";
|
1999-01-21 11:02:17 +03:00
|
|
|
return(WEXITSTATUS(status));
|
2001-09-13 22:07:26 +04:00
|
|
|
} else if (WIFSIGNALED(status)) {
|
|
|
|
*errstr = "command ended on signal";
|
1999-01-21 11:02:17 +03:00
|
|
|
return(WTERMSIG(status));
|
2001-09-13 22:07:26 +04:00
|
|
|
} else
|
1999-01-21 11:02:17 +03:00
|
|
|
return(0);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-11-02 06:45:27 +03:00
|
|
|
/*
|
1999-01-21 11:02:17 +03:00
|
|
|
* generic program runner. fatal and display can be set to
|
|
|
|
* 1 if you wish the output to be displayed, or an error to be
|
|
|
|
* fatal.
|
1997-11-02 06:45:27 +03:00
|
|
|
*/
|
1999-01-21 11:02:17 +03:00
|
|
|
|
|
|
|
int
|
2000-10-12 03:47:55 +04:00
|
|
|
run_prog(int flags, msg errmsg, const char *cmd, ...)
|
1997-11-02 06:45:27 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
1999-01-21 11:02:17 +03:00
|
|
|
struct winsize win;
|
1997-11-02 06:45:27 +03:00
|
|
|
int ret;
|
1999-01-21 11:02:17 +03:00
|
|
|
WINDOW *actionwin, *statuswin, *boxwin;
|
2003-01-10 23:00:27 +03:00
|
|
|
char buf2[MAXBUF], scmd[MAXBUF];
|
|
|
|
char *p, *args[256], **aps;
|
2001-09-13 22:07:26 +04:00
|
|
|
const char *errstr;
|
1999-01-21 11:02:17 +03:00
|
|
|
|
|
|
|
va_start(ap,cmd);
|
2003-01-10 23:00:27 +03:00
|
|
|
vsnprintf(buf2, sizeof(buf2), cmd, ap);
|
|
|
|
strcpy(scmd, buf2);
|
1999-01-21 11:02:17 +03:00
|
|
|
p = buf2;
|
|
|
|
|
|
|
|
/* 51 strings and it's blown! */
|
2003-01-10 23:00:27 +03:00
|
|
|
for (aps = args; aps < &args[sizeof(args) / sizeof(args[0])] &&
|
|
|
|
(*aps = strsep(&p, " ")) != NULL;)
|
1999-01-21 11:02:17 +03:00
|
|
|
if (**aps != '\0')
|
|
|
|
++aps;
|
|
|
|
|
|
|
|
(void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win);
|
1999-03-09 22:30:00 +03:00
|
|
|
/* Apparently, we sometimes get 0x0 back, and that's not useful */
|
|
|
|
if (win.ws_row == 0)
|
|
|
|
win.ws_row = 24;
|
|
|
|
if (win.ws_col == 0)
|
|
|
|
win.ws_col = 80;
|
|
|
|
|
2000-10-12 03:47:55 +04:00
|
|
|
if ((flags & RUN_SYSTEM) != 0) {
|
|
|
|
if ((flags & RUN_CHROOT) != 0)
|
|
|
|
chroot(target_prefix());
|
2003-01-10 23:00:27 +03:00
|
|
|
ret = system(scmd);
|
2000-10-12 03:47:55 +04:00
|
|
|
} else if ((flags & RUN_DISPLAY) != 0) {
|
2000-01-19 12:44:01 +03:00
|
|
|
wclear(stdscr);
|
|
|
|
clearok(stdscr, 1);
|
2000-10-12 03:47:55 +04:00
|
|
|
touchwin(stdscr);
|
2000-01-19 12:44:01 +03:00
|
|
|
refresh();
|
|
|
|
|
2000-10-12 03:47:55 +04:00
|
|
|
if ((flags & RUN_FULLSCREEN) != 0) {
|
2001-09-13 22:07:26 +04:00
|
|
|
ret = launch_subwin(stdscr, args, &win, flags, &errstr);
|
2000-10-12 03:47:55 +04:00
|
|
|
if (ret != 0) {
|
|
|
|
waddstr(stdscr, "Press any key to continue");
|
|
|
|
wrefresh(stdscr);
|
|
|
|
getchar();
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2000-01-13 21:52:21 +03:00
|
|
|
statuswin = subwin(stdscr, 3, win.ws_col, 0, 0);
|
1999-06-20 08:17:57 +04:00
|
|
|
if (statuswin == NULL) {
|
|
|
|
fprintf(stderr, "sysinst: failed to allocate"
|
|
|
|
" status window.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-19 12:44:01 +03:00
|
|
|
|
2000-01-19 11:46:26 +03:00
|
|
|
boxwin = subwin(stdscr, 1, win.ws_col, 3, 0);
|
1999-06-20 08:17:57 +04:00
|
|
|
if (boxwin == NULL) {
|
|
|
|
fprintf(stderr, "sysinst: failed to allocate"
|
|
|
|
" status box.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-19 12:44:01 +03:00
|
|
|
|
2000-01-13 21:52:21 +03:00
|
|
|
actionwin = subwin(stdscr, win.ws_row - 4, win.ws_col, 4, 0);
|
1999-06-20 08:17:57 +04:00
|
|
|
if (actionwin == NULL) {
|
|
|
|
fprintf(stderr, "sysinst: failed to allocate"
|
2000-10-12 03:47:55 +04:00
|
|
|
" output window.\n");
|
1999-06-20 08:17:57 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
scrollok(actionwin, TRUE);
|
|
|
|
|
2000-01-13 21:52:21 +03:00
|
|
|
win.ws_row -= 4;
|
1999-01-21 11:02:17 +03:00
|
|
|
|
2000-01-19 12:44:01 +03:00
|
|
|
wmove(statuswin, 0, 5);
|
|
|
|
waddstr(statuswin, "Status: ");
|
|
|
|
wstandout(statuswin);
|
|
|
|
waddstr(statuswin, "Running");
|
|
|
|
wstandend(statuswin);
|
|
|
|
wmove(statuswin, 1, 4);
|
|
|
|
waddstr(statuswin, "Command: ");
|
|
|
|
wstandout(statuswin);
|
2003-01-10 23:00:27 +03:00
|
|
|
waddstr(statuswin, scmd);
|
2000-01-19 12:44:01 +03:00
|
|
|
wstandend(statuswin);
|
1999-01-21 11:02:17 +03:00
|
|
|
wrefresh(statuswin);
|
|
|
|
|
2000-01-13 21:52:21 +03:00
|
|
|
wmove(boxwin, 0, 0);
|
|
|
|
{
|
|
|
|
int n, m;
|
|
|
|
for (n = win.ws_col; (m = min(n, 30)) > 0; n -= m)
|
|
|
|
waddstr(boxwin,
|
|
|
|
"------------------------------" + 30 - m);
|
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
wrefresh(boxwin);
|
|
|
|
|
|
|
|
wrefresh(actionwin);
|
|
|
|
|
2001-09-13 22:07:26 +04:00
|
|
|
ret = launch_subwin(actionwin, args, &win, flags, &errstr);
|
1999-01-21 11:02:17 +03:00
|
|
|
|
|
|
|
wmove(statuswin, 0, 13);
|
|
|
|
wstandout(statuswin);
|
2001-09-13 22:07:26 +04:00
|
|
|
if (ret) {
|
|
|
|
waddstr(statuswin, "Failed: ");
|
|
|
|
waddstr(statuswin, errstr);
|
|
|
|
} else
|
|
|
|
waddstr(statuswin, "Finished");
|
1999-01-21 11:02:17 +03:00
|
|
|
wstandend(statuswin);
|
2000-01-19 12:44:01 +03:00
|
|
|
waddstr(statuswin, " ");
|
1999-01-21 11:02:17 +03:00
|
|
|
wmove(statuswin, 2, 5);
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
if (ret != 0)
|
|
|
|
waddstr(statuswin, "Press any key to continue");
|
1999-01-21 11:02:17 +03:00
|
|
|
wrefresh(statuswin);
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
if (ret != 0)
|
|
|
|
(void)getchar();
|
1999-01-21 11:02:17 +03:00
|
|
|
|
|
|
|
/* clean things up */
|
|
|
|
delwin(actionwin);
|
|
|
|
delwin(boxwin);
|
|
|
|
delwin(statuswin);
|
2000-10-12 03:47:55 +04:00
|
|
|
done:
|
2000-01-19 12:44:01 +03:00
|
|
|
wclear(stdscr);
|
2000-10-12 03:47:55 +04:00
|
|
|
touchwin(stdscr);
|
2000-01-19 12:44:01 +03:00
|
|
|
clearok(stdscr, 1);
|
1999-01-21 11:02:17 +03:00
|
|
|
refresh();
|
|
|
|
} else { /* display */
|
2001-09-13 22:07:26 +04:00
|
|
|
ret = launch_subwin(NULL, args, &win, flags, &errstr);
|
1997-11-02 06:45:27 +03:00
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
va_end(ap);
|
2000-10-12 03:47:55 +04:00
|
|
|
if ((flags & RUN_FATAL) != 0 && ret != 0)
|
1999-01-21 11:02:17 +03:00
|
|
|
exit(ret);
|
1999-07-05 01:39:33 +04:00
|
|
|
if (ret && errmsg != MSG_NONE) {
|
2003-01-10 23:00:27 +03:00
|
|
|
msg_display(errmsg, scmd);
|
1999-04-09 14:24:38 +04:00
|
|
|
process_menu(MENU_ok);
|
|
|
|
}
|
|
|
|
return(ret);
|
1997-11-02 06:45:27 +03:00
|
|
|
}
|