Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
0ed2aef
Documentation
arch
alpha
arc
arm
arm64
avr32
blackfin
c6x
cris
frv
h8300
hexagon
ia64
m32r
m68k
metag
microblaze
mips
mn10300
openrisc
parisc
powerpc
s390
score
sh
sparc
tile
um
drivers
Makefile
chan.h
chan_kern.c
chan_user.c
chan_user.h
cow.h
cow_sys.h
cow_user.c
daemon.h
daemon_kern.c
daemon_user.c
fd.c
harddog_kern.c
harddog_user.c
hostaudio_kern.c
line.c
line.h
mconsole.h
mconsole_kern.c
mconsole_kern.h
mconsole_user.c
mmapper_kern.c
net_kern.c
net_user.c
null.c
pcap_kern.c
pcap_user.c
pcap_user.h
port.h
port_kern.c
port_user.c
pty.c
random.c
slip.h
slip_common.c
slip_common.h
slip_kern.c
slip_user.c
slirp.h
slirp_kern.c
slirp_user.c
ssl.c
ssl.h
stderr_console.c
stdio_console.c
stdio_console.h
tty.c
ubd.h
ubd_kern.c
ubd_user.c
umcast.h
umcast_kern.c
umcast_user.c
vde.h
vde_kern.c
vde_user.c
xterm.c
xterm.h
xterm_kern.c
include
kernel
os-Linux
scripts
sys-ia64
sys-ppc
.gitignore
Kconfig.char
Kconfig.common
Kconfig.debug
Kconfig.net
Kconfig.rest
Kconfig.um
Makefile
Makefile-ia64
Makefile-os-Linux
Makefile-ppc
Makefile-skas
defconfig
unicore32
x86
xtensa
.gitignore
Kconfig
block
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
arch
/
um
/
drivers
/
chan_user.c
Blame
Blame
Latest commit
History
History
301 lines (258 loc) · 6.95 KB
Breadcrumbs
linux
/
arch
/
um
/
drivers
/
chan_user.c
Top
File metadata and controls
Code
Blame
301 lines (258 loc) · 6.95 KB
Raw
/* * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) * Licensed under the GPL */ #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <sched.h> #include <signal.h> #include <termios.h> #include <sys/ioctl.h> #include "chan_user.h" #include <os.h> #include <um_malloc.h> void generic_close(int fd, void *unused) { close(fd); } int generic_read(int fd, char *c_out, void *unused) { int n; n = read(fd, c_out, sizeof(*c_out)); if (n > 0) return n; else if (errno == EAGAIN) return 0; else if (n == 0) return -EIO; return -errno; } /* XXX Trivial wrapper around write */ int generic_write(int fd, const char *buf, int n, void *unused) { int err; err = write(fd, buf, n); if (err > 0) return err; else if (errno == EAGAIN) return 0; else if (err == 0) return -EIO; return -errno; } int generic_window_size(int fd, void *unused, unsigned short *rows_out, unsigned short *cols_out) { struct winsize size; int ret; if (ioctl(fd, TIOCGWINSZ, &size) < 0) return -errno; ret = ((*rows_out != size.ws_row) || (*cols_out != size.ws_col)); *rows_out = size.ws_row; *cols_out = size.ws_col; return ret; } void generic_free(void *data) { kfree(data); } int generic_console_write(int fd, const char *buf, int n) { sigset_t old, no_sigio; struct termios save, new; int err; if (isatty(fd)) { sigemptyset(&no_sigio); sigaddset(&no_sigio, SIGIO); if (sigprocmask(SIG_BLOCK, &no_sigio, &old)) goto error; CATCH_EINTR(err = tcgetattr(fd, &save)); if (err) goto error; new = save; /* * The terminal becomes a bit less raw, to handle \n also as * "Carriage Return", not only as "New Line". Otherwise, the new * line won't start at the first column. */ new.c_oflag |= OPOST; CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &new)); if (err) goto error; } err = generic_write(fd, buf, n, NULL); /* * Restore raw mode, in any case; we *must* ignore any error apart * EINTR, except for debug. */ if (isatty(fd)) { CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save)); sigprocmask(SIG_SETMASK, &old, NULL); } return err; error: return -errno; } /* * UML SIGWINCH handling * * The point of this is to handle SIGWINCH on consoles which have host * ttys and relay them inside UML to whatever might be running on the * console and cares about the window size (since SIGWINCH notifies * about terminal size changes). * * So, we have a separate thread for each host tty attached to a UML * device (side-issue - I'm annoyed that one thread can't have * multiple controlling ttys for the purpose of handling SIGWINCH, but * I imagine there are other reasons that doesn't make any sense). * * SIGWINCH can't be received synchronously, so you have to set up to * receive it as a signal. That being the case, if you are going to * wait for it, it is convenient to sit in sigsuspend() and wait for * the signal to bounce you out of it (see below for how we make sure * to exit only on SIGWINCH). */ static void winch_handler(int sig) { } struct winch_data { int pty_fd; int pipe_fd; }; static int winch_thread(void *arg) { struct winch_data *data = arg; sigset_t sigs; int pty_fd, pipe_fd; int count; char c = 1; pty_fd = data->pty_fd; pipe_fd = data->pipe_fd; count = write(pipe_fd, &c, sizeof(c)); if (count != sizeof(c)) printk(UM_KERN_ERR "winch_thread : failed to write " "synchronization byte, err = %d\n", -count); /* * We are not using SIG_IGN on purpose, so don't fix it as I thought to * do! If using SIG_IGN, the sigsuspend() call below would not stop on * SIGWINCH. */ signal(SIGWINCH, winch_handler); sigfillset(&sigs); /* Block all signals possible. */ if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) { printk(UM_KERN_ERR "winch_thread : sigprocmask failed, " "errno = %d\n", errno); exit(1); } /* In sigsuspend(), block anything else than SIGWINCH. */ sigdelset(&sigs, SIGWINCH); if (setsid() < 0) { printk(UM_KERN_ERR "winch_thread : setsid failed, errno = %d\n", errno); exit(1); } if (ioctl(pty_fd, TIOCSCTTY, 0) < 0) { printk(UM_KERN_ERR "winch_thread : TIOCSCTTY failed on " "fd %d err = %d\n", pty_fd, errno); exit(1); } if (tcsetpgrp(pty_fd, os_getpid()) < 0) { printk(UM_KERN_ERR "winch_thread : tcsetpgrp failed on " "fd %d err = %d\n", pty_fd, errno); exit(1); } /* * These are synchronization calls between various UML threads on the * host - since they are not different kernel threads, we cannot use * kernel semaphores. We don't use SysV semaphores because they are * persistent. */ count = read(pipe_fd, &c, sizeof(c)); if (count != sizeof(c)) printk(UM_KERN_ERR "winch_thread : failed to read " "synchronization byte, err = %d\n", errno); while(1) { /* * This will be interrupted by SIGWINCH only, since * other signals are blocked. */ sigsuspend(&sigs); count = write(pipe_fd, &c, sizeof(c)); if (count != sizeof(c)) printk(UM_KERN_ERR "winch_thread : write failed, " "err = %d\n", errno); } } static int winch_tramp(int fd, struct tty_port *port, int *fd_out, unsigned long *stack_out) { struct winch_data data; int fds[2], n, err; char c; err = os_pipe(fds, 1, 1); if (err < 0) { printk(UM_KERN_ERR "winch_tramp : os_pipe failed, err = %d\n", -err); goto out; } data = ((struct winch_data) { .pty_fd = fd, .pipe_fd = fds[1] } ); /* * CLONE_FILES so this thread doesn't hold open files which are open * now, but later closed in a different thread. This is a * problem with /dev/net/tun, which if held open by this * thread, prevents the TUN/TAP device from being reused. */ err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out); if (err < 0) { printk(UM_KERN_ERR "fork of winch_thread failed - errno = %d\n", -err); goto out_close; } *fd_out = fds[0]; n = read(fds[0], &c, sizeof(c)); if (n != sizeof(c)) { printk(UM_KERN_ERR "winch_tramp : failed to read " "synchronization byte\n"); printk(UM_KERN_ERR "read failed, err = %d\n", errno); printk(UM_KERN_ERR "fd %d will not support SIGWINCH\n", fd); err = -EINVAL; goto out_close; } if (os_set_fd_block(*fd_out, 0)) { printk(UM_KERN_ERR "winch_tramp: failed to set thread_fd " "non-blocking.\n"); goto out_close; } return err; out_close: close(fds[1]); close(fds[0]); out: return err; } void register_winch(int fd, struct tty_port *port) { unsigned long stack; int pid, thread, count, thread_fd = -1; char c = 1; if (!isatty(fd)) return; pid = tcgetpgrp(fd); if (is_skas_winch(pid, fd, port)) { register_winch_irq(-1, fd, -1, port, 0); return; } if (pid == -1) { thread = winch_tramp(fd, port, &thread_fd, &stack); if (thread < 0) return; register_winch_irq(thread_fd, fd, thread, port, stack); count = write(thread_fd, &c, sizeof(c)); if (count != sizeof(c)) printk(UM_KERN_ERR "register_winch : failed to write " "synchronization byte, err = %d\n", errno); } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
You can’t perform that action at this time.