Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/distrib/utils/sysinst provide a way to ignore tty-generated ...
details: https://anonhg.NetBSD.org/src/rev/3786373af914
branches: trunk
changeset: 473918:3786373af914
user: cgd <cgd%NetBSD.org@localhost>
date: Tue Jun 22 00:43:57 1999 +0000
description:
provide a way to ignore tty-generated signals (INTR and QUIT) and/or
forward them on to subprocesses. nice when running a subprocess in
a display window to allow the user to kill the subprocess w/o nuking
sysinst itself. add handling for QUIT, which gets handled the same
as intr. add handling for HUP which just cleans up. More signals
should be handled.
diffstat:
distrib/utils/sysinst/defs.h | 4 ++-
distrib/utils/sysinst/main.c | 45 ++++++++++++++++++++++++++++++++++++++-----
distrib/utils/sysinst/run.c | 21 ++++++++++++++++++-
3 files changed, 61 insertions(+), 9 deletions(-)
diffs (161 lines):
diff -r bb55bdee7ef6 -r 3786373af914 distrib/utils/sysinst/defs.h
--- a/distrib/utils/sysinst/defs.h Mon Jun 21 22:31:32 1999 +0000
+++ b/distrib/utils/sysinst/defs.h Tue Jun 22 00:43:57 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.42 1999/06/20 06:08:13 cgd Exp $ */
+/* $NetBSD: defs.h,v 1.43 1999/06/22 00:43:57 cgd Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -91,6 +91,8 @@
EXTERN int yesno;
EXTERN int ignorerror;
+EXTERN int ttysig_ignore;
+EXTERN pid_t ttysig_forward;
EXTERN int layoutkind;
EXTERN int sizemult INIT(1);
EXTERN char *multname;
diff -r bb55bdee7ef6 -r 3786373af914 distrib/utils/sysinst/main.c
--- a/distrib/utils/sysinst/main.c Mon Jun 21 22:31:32 1999 +0000
+++ b/distrib/utils/sysinst/main.c Tue Jun 22 00:43:57 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.17 1999/06/20 06:08:14 cgd Exp $ */
+/* $NetBSD: main.c,v 1.18 1999/06/22 00:43:57 cgd Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -56,7 +56,8 @@
int main __P((int argc, char **argv));
static void usage __P((void));
-static void inthandler __P((int));
+static void miscsighandler __P((int));
+static void ttysighandler __P((int));
static void cleanup __P((void));
static void process_f_flag __P((char *));
@@ -125,9 +126,11 @@
}
msg_window(win);
- /* Watch for SIGINT and clean up */
- (void)signal(SIGINT, inthandler);
+ /* Watch for signals and clean up */
(void)atexit(cleanup);
+ (void)signal(SIGINT, ttysighandler);
+ (void)signal(SIGQUIT, ttysighandler);
+ (void)signal(SIGHUP, miscsighandler);
/* Menu processing */
process_menu(MENU_netbsd);
@@ -167,11 +170,41 @@
/* ARGSUSED */
static void
-inthandler(notused)
- int notused;
+miscsighandler(signo)
+ int signo;
+{
+
+ /*
+ * we need to cleanup(), but it was already scheduled with atexit(),
+ * so it'll be invoked on exit().
+ */
+ exit(1);
+}
+
+static void
+ttysighandler(signo)
+ int signo;
{
/*
+ * if we want to ignore a TTY signal (SIGINT or SIGQUIT), then we
+ * just return. If we want to forward a TTY signal, we forward it
+ * to the specified process group.
+ *
+ * This functionality is used when setting up and displaying child
+ * output so that the child gets the signal and presumably dies,
+ * but sysinst continues. We use this rather than actually ignoring
+ * the signals, because that will be be passed on to a child
+ * through fork/exec, whereas special handlers get reset on exec..
+ */
+ if (ttysig_ignore)
+ return;
+ if (ttysig_forward) {
+ killpg(ttysig_forward, signo);
+ return;
+ }
+
+ /*
* we need to cleanup(), but it was already scheduled with atexit(),
* so it'll be invoked on exit().
*/
diff -r bb55bdee7ef6 -r 3786373af914 distrib/utils/sysinst/run.c
--- a/distrib/utils/sysinst/run.c Mon Jun 21 22:31:32 1999 +0000
+++ b/distrib/utils/sysinst/run.c Tue Jun 22 00:43:57 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: run.c,v 1.20 1999/06/21 02:55:27 cgd Exp $ */
+/* $NetBSD: run.c,v 1.21 1999/06/22 00:43:57 cgd Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -287,8 +287,12 @@
rtt.c_lflag &= ~ECHO;
(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt);
+ /* ignore tty signals until we're done with subprocess setup */
+ ttysig_ignore = 1;
+
switch(child=fork()) {
case -1:
+ ttysig_ignore = 0;
return -1;
break;
case 0:
@@ -325,7 +329,13 @@
warn("execvp %s", argzero);
_exit(EXIT_FAILURE);
break; /* end of child */
- default: break;
+ default:
+ /*
+ * we've set up the subprocess. forward tty signals to its * process group.
+ */
+ ttysig_forward = child;
+ ttysig_ignore = 0;
+ break;
}
close(dataflow[1]);
FD_ZERO(&active_fd_set);
@@ -342,6 +352,8 @@
}
read_fd_set = active_fd_set;
if (select(FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0) {
+ if (errno == EINTR)
+ goto loop;
perror("select");
if (logging)
(void)fprintf(log, "select failure: %s\n", strerror(errno));
@@ -376,6 +388,7 @@
}
}
}
+loop:
pid = wait4(child, &status, WNOHANG, 0);
if (pid == child && (WIFEXITED(status) || WIFSIGNALED(status)))
break;
@@ -386,7 +399,11 @@
if (logging)
fflush(log);
+ /* from here on out, we take tty signals ourselves */
+ ttysig_forward = 0;
+
(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt);
+
if (WIFEXITED(status))
return(WEXITSTATUS(status));
else if (WIFSIGNALED(status))
Home |
Main Index |
Thread Index |
Old Index