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;
33 tcsetattr(fd
, TCSAFLUSH
, &new);
35 err
= generic_write(fd
, buf
, n
, NULL
);
36 if(isatty(fd
)) tcsetattr(fd
, TCSAFLUSH
, &save
);
40 static void winch_handler(int sig
)
50 static int winch_thread(void *arg
)
52 struct winch_data
*data
= arg
;
58 os_close_file(data
->close_me
);
59 pty_fd
= data
->pty_fd
;
60 pipe_fd
= data
->pipe_fd
;
61 count
= os_write_file(pipe_fd
, &c
, sizeof(c
));
62 if(count
!= sizeof(c
))
63 printk("winch_thread : failed to write synchronization "
64 "byte, err = %d\n", -count
);
66 signal(SIGWINCH
, winch_handler
);
68 sigdelset(&sigs
, SIGWINCH
);
69 if(sigprocmask(SIG_SETMASK
, &sigs
, NULL
) < 0){
70 printk("winch_thread : sigprocmask failed, errno = %d\n",
76 printk("winch_thread : setsid failed, errno = %d\n", errno
);
80 err
= os_new_tty_pgrp(pty_fd
, os_getpid());
82 printk("winch_thread : new_tty_pgrp failed, err = %d\n", -err
);
86 count
= os_read_file(pipe_fd
, &c
, sizeof(c
));
87 if(count
!= sizeof(c
))
88 printk("winch_thread : failed to read synchronization byte, "
89 "err = %d\n", -count
);
94 count
= os_write_file(pipe_fd
, &c
, sizeof(c
));
95 if(count
!= sizeof(c
))
96 printk("winch_thread : write failed, err = %d\n",
101 static int winch_tramp(int fd
, void *device_data
, int *fd_out
)
103 struct winch_data data
;
105 int fds
[2], pid
, n
, err
;
108 err
= os_pipe(fds
, 1, 1);
110 printk("winch_tramp : os_pipe failed, err = %d\n", -err
);
114 data
= ((struct winch_data
) { .pty_fd
= fd
,
116 .close_me
= fds
[0] } );
117 pid
= run_helper_thread(winch_thread
, &data
, 0, &stack
, 0);
119 printk("fork of winch_thread failed - errno = %d\n", errno
);
123 os_close_file(fds
[1]);
125 n
= os_read_file(fds
[0], &c
, sizeof(c
));
127 printk("winch_tramp : failed to read synchronization byte\n");
128 printk("read failed, err = %d\n", -n
);
129 printk("fd %d will not support SIGWINCH\n", fd
);
135 void register_winch(int fd
, void *device_data
)
137 int pid
, thread
, thread_fd
;
145 if(!CHOOSE_MODE_PROC(is_tracer_winch
, is_skas_winch
, pid
, fd
,
146 device_data
) && (pid
== -1)){
147 thread
= winch_tramp(fd
, device_data
, &thread_fd
);
149 register_winch_irq(thread_fd
, fd
, thread
, device_data
);
151 count
= os_write_file(thread_fd
, &c
, sizeof(c
));
152 if(count
!= sizeof(c
))
153 printk("register_winch : failed to write "
154 "synchronization byte, err = %d\n",
161 * Overrides for Emacs so that we follow Linus's tabbing style.
162 * Emacs will notice this stuff at the end of the file and automatically
163 * adjust the settings for this buffer only. This must remain at the end
165 * ---------------------------------------------------------------------------
167 * c-file-style: "linux"