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 void generic_close(int fd, void *unused)
29 int generic_read(int fd, char *c_out, void *unused)
33 n = os_read_file(fd, c_out, sizeof(*c_out));
42 /* XXX Trivial wrapper around os_write_file */
44 int generic_write(int fd, const char *buf, int n, void *unused)
46 return(os_write_file(fd, buf, n));
49 int generic_console_write(int fd, const char *buf, int n, void *unused)
51 struct termios save, new;
58 tcsetattr(fd, TCSAFLUSH, &new);
60 err = generic_write(fd, buf, n, NULL);
61 if(isatty(fd)) tcsetattr(fd, TCSAFLUSH, &save);
65 int generic_window_size(int fd, void *unused, unsigned short *rows_out,
66 unsigned short *cols_out)
71 ret = os_window_size(fd, &rows, &cols);
75 ret = ((*rows_out != rows) || (*cols_out != cols));
83 void generic_free(void *data)
88 static void winch_handler(int sig)
98 static int winch_thread(void *arg)
100 struct winch_data *data = arg;
106 os_close_file(data->close_me);
107 pty_fd = data->pty_fd;
108 pipe_fd = data->pipe_fd;
109 count = os_write_file(pipe_fd, &c, sizeof(c));
110 if(count != sizeof(c))
111 printk("winch_thread : failed to write synchronization "
112 "byte, err = %d\n", -count);
114 signal(SIGWINCH, winch_handler);
116 sigdelset(&sigs, SIGWINCH);
117 if(sigprocmask(SIG_SETMASK, &sigs, NULL) < 0){
118 printk("winch_thread : sigprocmask failed, errno = %d\n",
124 printk("winch_thread : setsid failed, errno = %d\n", errno);
128 err = os_new_tty_pgrp(pty_fd, os_getpid());
130 printk("winch_thread : new_tty_pgrp failed, err = %d\n", -err);
134 count = os_read_file(pipe_fd, &c, sizeof(c));
135 if(count != sizeof(c))
136 printk("winch_thread : failed to read synchronization byte, "
137 "err = %d\n", -count);
142 count = os_write_file(pipe_fd, &c, sizeof(c));
143 if(count != sizeof(c))
144 printk("winch_thread : write failed, err = %d\n",
149 static int winch_tramp(int fd, void *device_data, int *fd_out)
151 struct winch_data data;
153 int fds[2], pid, n, err;
156 err = os_pipe(fds, 1, 1);
158 printk("winch_tramp : os_pipe failed, err = %d\n", -err);
162 data = ((struct winch_data) { .pty_fd = fd,
164 .close_me = fds[0] } );
165 pid = run_helper_thread(winch_thread, &data, 0, &stack, 0);
167 printk("fork of winch_thread failed - errno = %d\n", errno);
171 os_close_file(fds[1]);
173 n = os_read_file(fds[0], &c, sizeof(c));
175 printk("winch_tramp : failed to read synchronization byte\n");
176 printk("read failed, err = %d\n", -n);
177 printk("fd %d will not support SIGWINCH\n", fd);
183 void register_winch(int fd, void *device_data)
185 int pid, thread, thread_fd;
193 if(!CHOOSE_MODE_PROC(is_tracer_winch, is_skas_winch, pid, fd,
194 device_data) && (pid == -1)){
195 thread = winch_tramp(fd, device_data, &thread_fd);
197 register_winch_irq(thread_fd, fd, thread, device_data);
199 count = os_write_file(thread_fd, &c, sizeof(c));
200 if(count != sizeof(c))
201 printk("register_winch : failed to write "
202 "synchronization byte, err = %d\n",
209 * Overrides for Emacs so that we follow Linus's tabbing style.
210 * Emacs will notice this stuff at the end of the file and automatically
211 * adjust the settings for this buffer only. This must remain at the end
213 * ---------------------------------------------------------------------------
215 * c-file-style: "linux"