Annotation of prex-old/usr/server/proc/tty.c, Revision 1.1.1.1.2.1
1.1 nbrk 1: /*
2: * Copyright (c) 2007, Kohsuke Ohtani
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. Neither the name of the author nor the names of any co-contributors
14: * may be used to endorse or promote products derived from this software
15: * without specific prior written permission.
16: *
17: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27: * SUCH DAMAGE.
28: */
29:
1.1.1.1.2.1! nbrk 30: /*
! 31: * tty.c - TTY signal support
! 32: */
! 33:
1.1 nbrk 34: #include <prex/prex.h>
35: #include <server/proc.h>
36: #include <sys/list.h>
37:
38: #include <unistd.h>
39: #include <errno.h>
40: #include <stdlib.h>
41: #include <signal.h>
1.1.1.1.2.1! nbrk 42: #include <termios.h>
1.1 nbrk 43:
44: #include "proc.h"
45:
46: static device_t ttydev;
47:
1.1.1.1.2.1! nbrk 48: /*
! 49: * Send TTY signal.
! 50: */
1.1 nbrk 51: static void
1.1.1.1.2.1! nbrk 52: tty_signal(int sig)
1.1 nbrk 53: {
54: pid_t pid;
55:
1.1.1.1.2.1! nbrk 56: /*
! 57: * Get the process group that was active when
! 58: * the TTY signal was invoked.
! 59: */
! 60: if (device_ioctl(ttydev, TIOCGPGRP, &pid) != 0)
1.1 nbrk 61: return;
1.1.1.1.2.1! nbrk 62:
! 63: DPRINTF(("proc: tty_signal sig=%d\n", sig));
! 64: kill_pg(pid, sig);
1.1 nbrk 65: }
66:
1.1.1.1.2.1! nbrk 67: /*
! 68: * Catch TTY related signals and forward them
! 69: * to the appropriate processes.
! 70: */
1.1 nbrk 71: static void
1.1.1.1.2.1! nbrk 72: exception_handler(int sig)
1.1 nbrk 73: {
1.1.1.1.2.1! nbrk 74:
1.1 nbrk 75: /*
76: * Handle signals from tty input.
77: */
1.1.1.1.2.1! nbrk 78: switch (sig) {
1.1 nbrk 79: case SIGINT:
80: case SIGQUIT:
81: case SIGTSTP:
82: case SIGTTIN:
83: case SIGTTOU:
84: case SIGINFO:
85: case SIGWINCH:
86: case SIGIO:
87: if (ttydev != DEVICE_NULL)
1.1.1.1.2.1! nbrk 88: tty_signal(sig);
1.1 nbrk 89: break;
90: }
1.1.1.1.2.1! nbrk 91: exception_return();
1.1 nbrk 92: }
93:
1.1.1.1.2.1! nbrk 94: /*
! 95: * Initialize TTY.
! 96: *
! 97: * Since we manage the process group only in the process
! 98: * server, the TTY driver can not know anything about the
! 99: * process group. However, POSIX specification requires TTY
! 100: * driver to send a signal to the specific process group.
! 101: * So, we will catch all TTY related signals by this server
! 102: * and forward them to the actual process or process group.
! 103: */
1.1 nbrk 104: void
105: tty_init(void)
106: {
107: task_t self;
108:
109: /*
1.1.1.1.2.1! nbrk 110: * Setup exception to receive signals from tty.
1.1 nbrk 111: */
112: exception_setup(exception_handler);
113:
114: if (device_open("tty", 0, &ttydev) != 0)
115: ttydev = DEVICE_NULL;
116: else {
1.1.1.1.2.1! nbrk 117: /*
! 118: * Notify the TTY driver to send all tty related
! 119: * signals in system to this task.
! 120: */
1.1 nbrk 121: self = task_self();
1.1.1.1.2.1! nbrk 122: device_ioctl(ttydev, TIOCSETSIGT, &self);
1.1 nbrk 123: }
124: }
CVSweb