aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers/chan_user.c
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-10-16 04:26:41 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:43:04 -0400
commite99525f9706900417f37721e601d2b414d41bfee (patch)
treefb407ea65a7c4c8bf457dd2ccab98842570cc62f /arch/um/drivers/chan_user.c
parent79f662334fefa2dd3fdf66c44a4d2dca5e378ab4 (diff)
uml: console subsystem tidying
This does a lot of cleanup on the UML console system. This patch should be entirely non-functional. The tidying is as follows: header cleanups - the includes should be closer to minimal and complete all printks now have a severity lots of style fixes fd_close is restructured a little in order to reduce the nesting some functions were calling the os_* wrappers when they can call libc directly port_accept had a unnecessary variable it also tested a pid unecessarily before killing it some functions were made static xterm_free is gone, as it was identical to generic_free Signed-off-by: Jeff Dike <jdike@linux.intel.com> Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um/drivers/chan_user.c')
-rw-r--r--arch/um/drivers/chan_user.c111
1 files changed, 58 insertions, 53 deletions
diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c
index 40271afa3ee2..77557e233f58 100644
--- a/arch/um/drivers/chan_user.c
+++ b/arch/um/drivers/chan_user.c
@@ -1,25 +1,19 @@
1/* 1/*
2 * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com) 2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include <unistd.h>
7#include <stdlib.h> 6#include <stdlib.h>
7#include <unistd.h>
8#include <errno.h> 8#include <errno.h>
9#include <termios.h>
10#include <string.h>
11#include <signal.h>
12#include <sched.h> 9#include <sched.h>
13#include <sys/stat.h> 10#include <signal.h>
11#include <termios.h>
14#include <sys/ioctl.h> 12#include <sys/ioctl.h>
15#include <sys/socket.h>
16#include "kern_util.h"
17#include "chan_user.h" 13#include "chan_user.h"
18#include "user.h"
19#include "os.h" 14#include "os.h"
20#include "choose-mode.h"
21#include "mode.h"
22#include "um_malloc.h" 15#include "um_malloc.h"
16#include "user.h"
23 17
24void generic_close(int fd, void *unused) 18void generic_close(int fd, void *unused)
25{ 19{
@@ -53,7 +47,7 @@ int generic_window_size(int fd, void *unused, unsigned short *rows_out,
53 struct winsize size; 47 struct winsize size;
54 int ret; 48 int ret;
55 49
56 if(ioctl(fd, TIOCGWINSZ, &size) < 0) 50 if (ioctl(fd, TIOCGWINSZ, &size) < 0)
57 return -errno; 51 return -errno;
58 52
59 ret = ((*rows_out != size.ws_row) || (*cols_out != size.ws_col)); 53 ret = ((*rows_out != size.ws_row) || (*cols_out != size.ws_col));
@@ -74,7 +68,7 @@ int generic_console_write(int fd, const char *buf, int n)
74 struct termios save, new; 68 struct termios save, new;
75 int err; 69 int err;
76 70
77 if(isatty(fd)){ 71 if (isatty(fd)) {
78 CATCH_EINTR(err = tcgetattr(fd, &save)); 72 CATCH_EINTR(err = tcgetattr(fd, &save));
79 if (err) 73 if (err)
80 goto error; 74 goto error;
@@ -90,11 +84,11 @@ int generic_console_write(int fd, const char *buf, int n)
90 err = generic_write(fd, buf, n, NULL); 84 err = generic_write(fd, buf, n, NULL);
91 /* Restore raw mode, in any case; we *must* ignore any error apart 85 /* Restore raw mode, in any case; we *must* ignore any error apart
92 * EINTR, except for debug.*/ 86 * EINTR, except for debug.*/
93 if(isatty(fd)) 87 if (isatty(fd))
94 CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save)); 88 CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
95 return(err); 89 return err;
96error: 90error:
97 return(-errno); 91 return -errno;
98} 92}
99 93
100/* 94/*
@@ -137,56 +131,62 @@ static int winch_thread(void *arg)
137 pty_fd = data->pty_fd; 131 pty_fd = data->pty_fd;
138 pipe_fd = data->pipe_fd; 132 pipe_fd = data->pipe_fd;
139 count = os_write_file(pipe_fd, &c, sizeof(c)); 133 count = os_write_file(pipe_fd, &c, sizeof(c));
140 if(count != sizeof(c)) 134 if (count != sizeof(c))
141 printk("winch_thread : failed to write synchronization " 135 printk(UM_KERN_ERR "winch_thread : failed to write "
142 "byte, err = %d\n", -count); 136 "synchronization byte, err = %d\n", -count);
143 137
144 /* We are not using SIG_IGN on purpose, so don't fix it as I thought to 138 /*
139 * We are not using SIG_IGN on purpose, so don't fix it as I thought to
145 * do! If using SIG_IGN, the sigsuspend() call below would not stop on 140 * do! If using SIG_IGN, the sigsuspend() call below would not stop on
146 * SIGWINCH. */ 141 * SIGWINCH.
142 */
147 143
148 signal(SIGWINCH, winch_handler); 144 signal(SIGWINCH, winch_handler);
149 sigfillset(&sigs); 145 sigfillset(&sigs);
150 /* Block all signals possible. */ 146 /* Block all signals possible. */
151 if(sigprocmask(SIG_SETMASK, &sigs, NULL) < 0){ 147 if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) {
152 printk("winch_thread : sigprocmask failed, errno = %d\n", 148 printk(UM_KERN_ERR "winch_thread : sigprocmask failed, "
153 errno); 149 "errno = %d\n", errno);
154 exit(1); 150 exit(1);
155 } 151 }
156 /* In sigsuspend(), block anything else than SIGWINCH. */ 152 /* In sigsuspend(), block anything else than SIGWINCH. */
157 sigdelset(&sigs, SIGWINCH); 153 sigdelset(&sigs, SIGWINCH);
158 154
159 if(setsid() < 0){ 155 if (setsid() < 0) {
160 printk("winch_thread : setsid failed, errno = %d\n", errno); 156 printk(UM_KERN_ERR "winch_thread : setsid failed, errno = %d\n",
157 errno);
161 exit(1); 158 exit(1);
162 } 159 }
163 160
164 err = os_new_tty_pgrp(pty_fd, os_getpid()); 161 err = os_new_tty_pgrp(pty_fd, os_getpid());
165 if(err < 0){ 162 if (err < 0) {
166 printk("winch_thread : new_tty_pgrp failed on fd %d, " 163 printk(UM_KERN_ERR "winch_thread : new_tty_pgrp failed on "
167 "err = %d\n", pty_fd, -err); 164 "fd %d err = %d\n", pty_fd, -err);
168 exit(1); 165 exit(1);
169 } 166 }
170 167
171 /* These are synchronization calls between various UML threads on the 168 /*
169 * These are synchronization calls between various UML threads on the
172 * host - since they are not different kernel threads, we cannot use 170 * host - since they are not different kernel threads, we cannot use
173 * kernel semaphores. We don't use SysV semaphores because they are 171 * kernel semaphores. We don't use SysV semaphores because they are
174 * persistent. */ 172 * persistent.
173 */
175 count = os_read_file(pipe_fd, &c, sizeof(c)); 174 count = os_read_file(pipe_fd, &c, sizeof(c));
176 if(count != sizeof(c)) 175 if (count != sizeof(c))
177 printk("winch_thread : failed to read synchronization byte, " 176 printk(UM_KERN_ERR "winch_thread : failed to read "
178 "err = %d\n", -count); 177 "synchronization byte, err = %d\n", -count);
179 178
180 while(1){ 179 while(1) {
181 /* This will be interrupted by SIGWINCH only, since 180 /*
181 * This will be interrupted by SIGWINCH only, since
182 * other signals are blocked. 182 * other signals are blocked.
183 */ 183 */
184 sigsuspend(&sigs); 184 sigsuspend(&sigs);
185 185
186 count = os_write_file(pipe_fd, &c, sizeof(c)); 186 count = os_write_file(pipe_fd, &c, sizeof(c));
187 if(count != sizeof(c)) 187 if (count != sizeof(c))
188 printk("winch_thread : write failed, err = %d\n", 188 printk(UM_KERN_ERR "winch_thread : write failed, "
189 -count); 189 "err = %d\n", -count);
190 } 190 }
191} 191}
192 192
@@ -198,36 +198,41 @@ static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out,
198 char c; 198 char c;
199 199
200 err = os_pipe(fds, 1, 1); 200 err = os_pipe(fds, 1, 1);
201 if(err < 0){ 201 if (err < 0) {
202 printk("winch_tramp : os_pipe failed, err = %d\n", -err); 202 printk(UM_KERN_ERR "winch_tramp : os_pipe failed, err = %d\n",
203 -err);
203 goto out; 204 goto out;
204 } 205 }
205 206
206 data = ((struct winch_data) { .pty_fd = fd, 207 data = ((struct winch_data) { .pty_fd = fd,
207 .pipe_fd = fds[1] } ); 208 .pipe_fd = fds[1] } );
208 /* CLONE_FILES so this thread doesn't hold open files which are open 209 /*
210 * CLONE_FILES so this thread doesn't hold open files which are open
209 * now, but later closed in a different thread. This is a 211 * now, but later closed in a different thread. This is a
210 * problem with /dev/net/tun, which if held open by this 212 * problem with /dev/net/tun, which if held open by this
211 * thread, prevents the TUN/TAP device from being reused. 213 * thread, prevents the TUN/TAP device from being reused.
212 */ 214 */
213 err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out); 215 err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out);
214 if(err < 0){ 216 if (err < 0) {
215 printk("fork of winch_thread failed - errno = %d\n", -err); 217 printk(UM_KERN_ERR "fork of winch_thread failed - errno = %d\n",
218 -err);
216 goto out_close; 219 goto out_close;
217 } 220 }
218 221
219 *fd_out = fds[0]; 222 *fd_out = fds[0];
220 n = os_read_file(fds[0], &c, sizeof(c)); 223 n = os_read_file(fds[0], &c, sizeof(c));
221 if(n != sizeof(c)){ 224 if (n != sizeof(c)) {
222 printk("winch_tramp : failed to read synchronization byte\n"); 225 printk(UM_KERN_ERR "winch_tramp : failed to read "
223 printk("read failed, err = %d\n", -n); 226 "synchronization byte\n");
224 printk("fd %d will not support SIGWINCH\n", fd); 227 printk(UM_KERN_ERR "read failed, err = %d\n", -n);
225 err = -EINVAL; 228 printk(UM_KERN_ERR "fd %d will not support SIGWINCH\n", fd);
229 err = -EINVAL;
226 goto out_close; 230 goto out_close;
227 } 231 }
228 232
229 if (os_set_fd_block(*fd_out, 0)) { 233 if (os_set_fd_block(*fd_out, 0)) {
230 printk("winch_tramp: failed to set thread_fd non-blocking.\n"); 234 printk(UM_KERN_ERR "winch_tramp: failed to set thread_fd "
235 "non-blocking.\n");
231 goto out_close; 236 goto out_close;
232 } 237 }
233 238
@@ -246,7 +251,7 @@ void register_winch(int fd, struct tty_struct *tty)
246 int pid, thread, count, thread_fd = -1; 251 int pid, thread, count, thread_fd = -1;
247 char c = 1; 252 char c = 1;
248 253
249 if(!isatty(fd)) 254 if (!isatty(fd))
250 return; 255 return;
251 256
252 pid = tcgetpgrp(fd); 257 pid = tcgetpgrp(fd);
@@ -259,8 +264,8 @@ void register_winch(int fd, struct tty_struct *tty)
259 register_winch_irq(thread_fd, fd, thread, tty, stack); 264 register_winch_irq(thread_fd, fd, thread, tty, stack);
260 265
261 count = os_write_file(thread_fd, &c, sizeof(c)); 266 count = os_write_file(thread_fd, &c, sizeof(c));
262 if(count != sizeof(c)) 267 if (count != sizeof(c))
263 printk("register_winch : failed to write " 268 printk(UM_KERN_ERR "register_winch : failed to write "
264 "synchronization byte, err = %d\n", -count); 269 "synchronization byte, err = %d\n", -count);
265 } 270 }
266} 271}