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 static void winch_handler(int sig)
34 /* XXX This breaks horribly (by hanging UML) when moved to chan_kern.c -
37 int generic_console_write(int fd, const char *buf, int n, void *unused)
39 struct termios save, new;
46 tcsetattr(fd, TCSAFLUSH, &new);
48 err = generic_write(fd, buf, n, NULL);
49 if(isatty(fd)) tcsetattr(fd, TCSAFLUSH, &save);
53 static int winch_thread(void *arg)
55 struct winch_data *data = arg;
61 os_close_file(data->close_me);
62 pty_fd = data->pty_fd;
63 pipe_fd = data->pipe_fd;
64 count = os_write_file(pipe_fd, &c, sizeof(c));
65 if(count != sizeof(c))
66 printk("winch_thread : failed to write synchronization "
67 "byte, err = %d\n", -count);
69 signal(SIGWINCH, winch_handler);
71 sigdelset(&sigs, SIGWINCH);
72 if(sigprocmask(SIG_SETMASK, &sigs, NULL) < 0){
73 printk("winch_thread : sigprocmask failed, errno = %d\n",
79 printk("winch_thread : setsid failed, errno = %d\n", errno);
83 err = os_new_tty_pgrp(pty_fd, os_getpid());
85 printk("winch_thread : new_tty_pgrp failed, err = %d\n", -err);
89 count = os_read_file(pipe_fd, &c, sizeof(c));
90 if(count != sizeof(c))
91 printk("winch_thread : failed to read synchronization byte, "
92 "err = %d\n", -count);
97 count = os_write_file(pipe_fd, &c, sizeof(c));
98 if(count != sizeof(c))
99 printk("winch_thread : write failed, err = %d\n",
104 static int winch_tramp(int fd, void *device_data, int *fd_out)
106 struct winch_data data;
108 int fds[2], pid, n, err;
111 err = os_pipe(fds, 1, 1);
113 printk("winch_tramp : os_pipe failed, err = %d\n", -err);
117 data = ((struct winch_data) { .pty_fd = fd,
119 .close_me = fds[0] } );
120 pid = run_helper_thread(winch_thread, &data, 0, &stack, 0);
122 printk("fork of winch_thread failed - errno = %d\n", errno);
126 os_close_file(fds[1]);
128 n = os_read_file(fds[0], &c, sizeof(c));
130 printk("winch_tramp : failed to read synchronization byte\n");
131 printk("read failed, err = %d\n", -n);
132 printk("fd %d will not support SIGWINCH\n", fd);
138 void register_winch(int fd, void *device_data)
140 int pid, thread, thread_fd;
148 if(!CHOOSE_MODE_PROC(is_tracer_winch, is_skas_winch, pid, fd,
149 device_data) && (pid == -1)){
150 thread = winch_tramp(fd, device_data, &thread_fd);
152 register_winch_irq(thread_fd, fd, thread, device_data);
154 count = os_write_file(thread_fd, &c, sizeof(c));
155 if(count != sizeof(c))
156 printk("register_winch : failed to write "
157 "synchronization byte, err = %d\n",
164 * Overrides for Emacs so that we follow Linus's tabbing style.
165 * Emacs will notice this stuff at the end of the file and automatically
166 * adjust the settings for this buffer only. This must remain at the end
168 * ---------------------------------------------------------------------------
170 * c-file-style: "linux"