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
e8b767f
Documentation
LICENSES
arch
alpha
arc
arm
arm64
csky
h8300
hexagon
ia64
m68k
microblaze
mips
nios2
openrisc
parisc
powerpc
riscv
s390
sh
sparc
um
configs
drivers
Kconfig
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
rtc.h
rtc_kern.c
rtc_user.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
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
vector_kern.c
vector_kern.h
vector_transports.c
vector_user.c
vector_user.h
vhost_user.h
virt-pci.c
virtio_uml.c
xterm.c
xterm.h
xterm_kern.c
include
kernel
os-Linux
scripts
.gitignore
Kbuild
Kconfig
Kconfig.debug
Makefile
Makefile-os-Linux
Makefile-skas
x86
xtensa
.gitignore
Kconfig
block
certs
crypto
drivers
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
arch
/
um
/
drivers
/
port_user.c
Blame
Blame
Latest commit
Glenn Washburn
and
Richard Weinberger
um: port_user: Improve error handling when port-helper is not found
Mar 11, 2022
3cb5a7f
·
Mar 11, 2022
History
History
217 lines (182 loc) · 4.07 KB
Breadcrumbs
linux
/
arch
/
um
/
drivers
/
port_user.c
Top
File metadata and controls
Code
Blame
217 lines (182 loc) · 4.07 KB
Raw
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <termios.h> #include <unistd.h> #include <netinet/in.h> #include "chan_user.h" #include <os.h> #include "port.h" #include <um_malloc.h> struct port_chan { int raw; struct termios tt; void *kernel_data; char dev[sizeof("32768\0")]; }; static void *port_init(char *str, int device, const struct chan_opts *opts) { struct port_chan *data; void *kern_data; char *end; int port; if (*str != ':') { printk(UM_KERN_ERR "port_init : channel type 'port' must " "specify a port number\n"); return NULL; } str++; port = strtoul(str, &end, 0); if ((*end != '\0') || (end == str)) { printk(UM_KERN_ERR "port_init : couldn't parse port '%s'\n", str); return NULL; } kern_data = port_data(port); if (kern_data == NULL) return NULL; data = uml_kmalloc(sizeof(*data), UM_GFP_KERNEL); if (data == NULL) goto err; *data = ((struct port_chan) { .raw = opts->raw, .kernel_data = kern_data }); sprintf(data->dev, "%d", port); return data; err: port_kern_free(kern_data); return NULL; } static void port_free(void *d) { struct port_chan *data = d; port_kern_free(data->kernel_data); kfree(data); } static int port_open(int input, int output, int primary, void *d, char **dev_out) { struct port_chan *data = d; int fd, err; fd = port_wait(data->kernel_data); if ((fd >= 0) && data->raw) { CATCH_EINTR(err = tcgetattr(fd, &data->tt)); if (err) return err; err = raw(fd); if (err) return err; } *dev_out = data->dev; return fd; } static void port_close(int fd, void *d) { struct port_chan *data = d; port_remove_dev(data->kernel_data); os_close_file(fd); } const struct chan_ops port_ops = { .type = "port", .init = port_init, .open = port_open, .close = port_close, .read = generic_read, .write = generic_write, .console_write = generic_console_write, .window_size = generic_window_size, .free = port_free, .winch = 1, }; int port_listen_fd(int port) { struct sockaddr_in addr; int fd, err, arg; fd = socket(PF_INET, SOCK_STREAM, 0); if (fd == -1) return -errno; arg = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof(arg)) < 0) { err = -errno; goto out; } addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { err = -errno; goto out; } if (listen(fd, 1) < 0) { err = -errno; goto out; } err = os_set_fd_block(fd, 0); if (err < 0) goto out; return fd; out: close(fd); return err; } struct port_pre_exec_data { int sock_fd; int pipe_fd; }; static void port_pre_exec(void *arg) { struct port_pre_exec_data *data = arg; dup2(data->sock_fd, 0); dup2(data->sock_fd, 1); dup2(data->sock_fd, 2); close(data->sock_fd); dup2(data->pipe_fd, 3); shutdown(3, SHUT_RD); close(data->pipe_fd); } int port_connection(int fd, int *socket, int *pid_out) { int new, err; char *env; char *argv[] = { "in.telnetd", "-L", OS_LIB_PATH "/uml/port-helper", NULL }; struct port_pre_exec_data data; if ((env = getenv("UML_PORT_HELPER"))) argv[2] = env; new = accept(fd, NULL, 0); if (new < 0) return -errno; err = os_access(argv[2], X_OK); if (err < 0) { printk(UM_KERN_ERR "port_connection : error accessing port-helper " "executable at %s: %s\n", argv[2], strerror(-err)); if (env == NULL) printk(UM_KERN_ERR "Set UML_PORT_HELPER environment " "variable to path to uml-utilities port-helper " "binary\n"); goto out_close; } err = os_pipe(socket, 0, 0); if (err < 0) goto out_close; data = ((struct port_pre_exec_data) { .sock_fd = new, .pipe_fd = socket[1] }); err = run_helper(port_pre_exec, &data, argv); if (err < 0) goto out_shutdown; *pid_out = err; return new; out_shutdown: shutdown(socket[0], SHUT_RDWR); close(socket[0]); shutdown(socket[1], SHUT_RDWR); close(socket[1]); out_close: close(new); return err; }
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
You can’t perform that action at this time.