2 * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
13 #include <sys/ioctl.h>
14 #include <sys/socket.h>
15 #include "kern_util.h"
16 #include "user_util.h"
17 #include "chan_user.h"
21 #include "choose-mode.h"
24 int generic_console_write(int fd, const char *buf, int n, void *unused)
26 struct termios save, new;
30 CATCH_EINTR(err = tcgetattr(fd, &save));
34 /* The terminal becomes a bit less raw, to handle \n also as
35 * "Carriage Return", not only as "New Line". Otherwise, the new
36 * line won't start at the first column.*/
38 CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &new));
42 err = generic_write(fd, buf, n, NULL);
43 /* Restore raw mode, in any case; we *must* ignore any error apart
44 * EINTR, except for debug.*/
46 CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
52 static void winch_handler(int sig)
62 static int winch_thread(void *arg)
64 struct winch_data *data = arg;
70 os_close_file(data->close_me);
71 pty_fd = data->pty_fd;
72 pipe_fd = data->pipe_fd;
73 count = os_write_file(pipe_fd, &c, sizeof(c));
74 if(count != sizeof(c))
75 printk("winch_thread : failed to write synchronization "
76 "byte, err = %d\n", -count);
78 signal(SIGWINCH, winch_handler);
80 sigdelset(&sigs, SIGWINCH);
81 if(sigprocmask(SIG_SETMASK, &sigs, NULL) < 0){
82 printk("winch_thread : sigprocmask failed, errno = %d\n",
88 printk("winch_thread : setsid failed, errno = %d\n", errno);
92 err = os_new_tty_pgrp(pty_fd, os_getpid());
94 printk("winch_thread : new_tty_pgrp failed, err = %d\n", -err);
98 count = os_read_file(pipe_fd, &c, sizeof(c));
99 if(count != sizeof(c))
100 printk("winch_thread : failed to read synchronization byte, "
101 "err = %d\n", -count);
106 count = os_write_file(pipe_fd, &c, sizeof(c));
107 if(count != sizeof(c))
108 printk("winch_thread : write failed, err = %d\n",
113 static int winch_tramp(int fd, void *device_data, int *fd_out)
115 struct winch_data data;
117 int fds[2], pid, n, err;
120 err = os_pipe(fds, 1, 1);
122 printk("winch_tramp : os_pipe failed, err = %d\n", -err);
126 data = ((struct winch_data) { .pty_fd = fd,
128 .close_me = fds[0] } );
129 pid = run_helper_thread(winch_thread, &data, 0, &stack, 0);
131 printk("fork of winch_thread failed - errno = %d\n", errno);
135 os_close_file(fds[1]);
137 n = os_read_file(fds[0], &c, sizeof(c));
139 printk("winch_tramp : failed to read synchronization byte\n");
140 printk("read failed, err = %d\n", -n);
141 printk("fd %d will not support SIGWINCH\n", fd);
147 void register_winch(int fd, void *device_data)
149 int pid, thread, thread_fd;
157 if(!CHOOSE_MODE_PROC(is_tracer_winch, is_skas_winch, pid, fd,
158 device_data) && (pid == -1)){
159 thread = winch_tramp(fd, device_data, &thread_fd);
161 register_winch_irq(thread_fd, fd, thread, device_data);
163 count = os_write_file(thread_fd, &c, sizeof(c));
164 if(count != sizeof(c))
165 printk("register_winch : failed to write "
166 "synchronization byte, err = %d\n",
173 * Overrides for Emacs so that we follow Linus's tabbing style.
174 * Emacs will notice this stuff at the end of the file and automatically
175 * adjust the settings for this buffer only. This must remain at the end
177 * ---------------------------------------------------------------------------
179 * c-file-style: "linux"