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>
This commit is contained in:
Jeff Dike
2007-10-16 01:26:41 -07:00
committed by Linus Torvalds
parent 79f662334f
commit e99525f970
9 changed files with 296 additions and 299 deletions

View File

@@ -1,28 +1,19 @@
/* /*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <linux/stddef.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tty.h> #include <linux/tty.h>
#include <linux/string.h>
#include <linux/tty_flip.h> #include <linux/tty_flip.h>
#include <asm/irq.h>
#include "chan_kern.h" #include "chan_kern.h"
#include "kern.h"
#include "irq_user.h"
#include "sigio.h"
#include "line.h"
#include "os.h" #include "os.h"
#ifdef CONFIG_NOCONFIG_CHAN #ifdef CONFIG_NOCONFIG_CHAN
static void *not_configged_init(char *str, int device, static void *not_configged_init(char *str, int device,
const struct chan_opts *opts) const struct chan_opts *opts)
{ {
printk("Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
return NULL; return NULL;
} }
@@ -30,34 +21,34 @@ static void *not_configged_init(char *str, int device,
static int not_configged_open(int input, int output, int primary, void *data, static int not_configged_open(int input, int output, int primary, void *data,
char **dev_out) char **dev_out)
{ {
printk("Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
return -ENODEV; return -ENODEV;
} }
static void not_configged_close(int fd, void *data) static void not_configged_close(int fd, void *data)
{ {
printk("Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
} }
static int not_configged_read(int fd, char *c_out, void *data) static int not_configged_read(int fd, char *c_out, void *data)
{ {
printk("Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
return -EIO; return -EIO;
} }
static int not_configged_write(int fd, const char *buf, int len, void *data) static int not_configged_write(int fd, const char *buf, int len, void *data)
{ {
printk("Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
return -EIO; return -EIO;
} }
static int not_configged_console_write(int fd, const char *buf, int len) static int not_configged_console_write(int fd, const char *buf, int len)
{ {
printk("Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
return -EIO; return -EIO;
} }
@@ -65,14 +56,14 @@ static int not_configged_console_write(int fd, const char *buf, int len)
static int not_configged_window_size(int fd, void *data, unsigned short *rows, static int not_configged_window_size(int fd, void *data, unsigned short *rows,
unsigned short *cols) unsigned short *cols)
{ {
printk("Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
return -ENODEV; return -ENODEV;
} }
static void not_configged_free(void *data) static void not_configged_free(void *data)
{ {
printk("Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
} }
@@ -91,7 +82,8 @@ static const struct chan_ops not_configged_ops = {
static void tty_receive_char(struct tty_struct *tty, char ch) static void tty_receive_char(struct tty_struct *tty, char ch)
{ {
if(tty == NULL) return; if (tty == NULL)
return;
if (I_IXON(tty) && !I_IXOFF(tty) && !tty->raw) { if (I_IXON(tty) && !I_IXOFF(tty) && !tty->raw) {
if (ch == STOP_CHAR(tty)) { if (ch == STOP_CHAR(tty)) {
@@ -303,6 +295,7 @@ int write_chan(struct list_head *chans, const char *buf, int len,
chan = list_entry(ele, struct chan, list); chan = list_entry(ele, struct chan, list);
if (!chan->output || (chan->ops->write == NULL)) if (!chan->output || (chan->ops->write == NULL))
continue; continue;
n = chan->ops->write(chan->fd, buf, len, chan->data); n = chan->ops->write(chan->fd, buf, len, chan->data);
if (chan->primary) { if (chan->primary) {
ret = n; ret = n;
@@ -323,8 +316,10 @@ int console_write_chan(struct list_head *chans, const char *buf, int len)
chan = list_entry(ele, struct chan, list); chan = list_entry(ele, struct chan, list);
if (!chan->output || (chan->ops->console_write == NULL)) if (!chan->output || (chan->ops->console_write == NULL))
continue; continue;
n = chan->ops->console_write(chan->fd, buf, len); n = chan->ops->console_write(chan->fd, buf, len);
if(chan->primary) ret = n; if (chan->primary)
ret = n;
} }
return ret; return ret;
} }
@@ -337,7 +332,8 @@ int console_open_chan(struct line *line, struct console *co)
if (err) if (err)
return err; return err;
printk("Console initialized on /dev/%s%d\n", co->name, co->index); printk(KERN_INFO "Console initialized on /dev/%s%d\n", co->name,
co->index);
return 0; return 0;
} }
@@ -368,7 +364,8 @@ static void free_one_chan(struct chan *chan, int delay_free_irq)
if (chan->ops->free != NULL) if (chan->ops->free != NULL)
(*chan->ops->free)(chan->data); (*chan->ops->free)(chan->data);
if(chan->primary && chan->output) ignore_sigio_fd(chan->fd); if (chan->primary && chan->output)
ignore_sigio_fd(chan->fd);
kfree(chan); kfree(chan);
} }
@@ -606,7 +603,8 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task,
list_for_each_safe(ele, next, chans) { list_for_each_safe(ele, next, chans) {
chan = list_entry(ele, struct chan, list); chan = list_entry(ele, struct chan, list);
if(!chan->input || (chan->ops->read == NULL)) continue; if (!chan->input || (chan->ops->read == NULL))
continue;
do { do {
if (tty && !tty_buffer_request_room(tty, 1)) { if (tty && !tty_buffer_request_room(tty, 1)) {
schedule_delayed_work(task, 1); schedule_delayed_work(task, 1);
@@ -617,7 +615,8 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task,
tty_receive_char(tty, c); tty_receive_char(tty, c);
} while (err > 0); } while (err > 0);
if(err == 0) reactivate_fd(chan->fd, irq); if (err == 0)
reactivate_fd(chan->fd, irq);
if (err == -EIO) { if (err == -EIO) {
if (chan->primary) { if (chan->primary) {
if (tty != NULL) if (tty != NULL)
@@ -629,5 +628,6 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task,
} }
} }
out: out:
if(tty) tty_flip_buffer_push(tty); if (tty)
tty_flip_buffer_push(tty);
} }

View File

@@ -1,25 +1,19 @@
/* /*
* Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com) * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <errno.h> #include <errno.h>
#include <termios.h>
#include <string.h>
#include <signal.h>
#include <sched.h> #include <sched.h>
#include <sys/stat.h> #include <signal.h>
#include <termios.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h>
#include "kern_util.h"
#include "chan_user.h" #include "chan_user.h"
#include "user.h"
#include "os.h" #include "os.h"
#include "choose-mode.h"
#include "mode.h"
#include "um_malloc.h" #include "um_malloc.h"
#include "user.h"
void generic_close(int fd, void *unused) void generic_close(int fd, void *unused)
{ {
@@ -92,9 +86,9 @@ int generic_console_write(int fd, const char *buf, int n)
* EINTR, except for debug.*/ * EINTR, except for debug.*/
if (isatty(fd)) if (isatty(fd))
CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save)); CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
return(err); return err;
error: error:
return(-errno); return -errno;
} }
/* /*
@@ -138,55 +132,61 @@ static int winch_thread(void *arg)
pipe_fd = data->pipe_fd; pipe_fd = data->pipe_fd;
count = os_write_file(pipe_fd, &c, sizeof(c)); count = os_write_file(pipe_fd, &c, sizeof(c));
if (count != sizeof(c)) if (count != sizeof(c))
printk("winch_thread : failed to write synchronization " printk(UM_KERN_ERR "winch_thread : failed to write "
"byte, err = %d\n", -count); "synchronization byte, err = %d\n", -count);
/* We are not using SIG_IGN on purpose, so don't fix it as I thought to /*
* 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 * do! If using SIG_IGN, the sigsuspend() call below would not stop on
* SIGWINCH. */ * SIGWINCH.
*/
signal(SIGWINCH, winch_handler); signal(SIGWINCH, winch_handler);
sigfillset(&sigs); sigfillset(&sigs);
/* Block all signals possible. */ /* Block all signals possible. */
if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) { if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) {
printk("winch_thread : sigprocmask failed, errno = %d\n", printk(UM_KERN_ERR "winch_thread : sigprocmask failed, "
errno); "errno = %d\n", errno);
exit(1); exit(1);
} }
/* In sigsuspend(), block anything else than SIGWINCH. */ /* In sigsuspend(), block anything else than SIGWINCH. */
sigdelset(&sigs, SIGWINCH); sigdelset(&sigs, SIGWINCH);
if (setsid() < 0) { if (setsid() < 0) {
printk("winch_thread : setsid failed, errno = %d\n", errno); printk(UM_KERN_ERR "winch_thread : setsid failed, errno = %d\n",
errno);
exit(1); exit(1);
} }
err = os_new_tty_pgrp(pty_fd, os_getpid()); err = os_new_tty_pgrp(pty_fd, os_getpid());
if (err < 0) { if (err < 0) {
printk("winch_thread : new_tty_pgrp failed on fd %d, " printk(UM_KERN_ERR "winch_thread : new_tty_pgrp failed on "
"err = %d\n", pty_fd, -err); "fd %d err = %d\n", pty_fd, -err);
exit(1); exit(1);
} }
/* These are synchronization calls between various UML threads on the /*
* These are synchronization calls between various UML threads on the
* host - since they are not different kernel threads, we cannot use * host - since they are not different kernel threads, we cannot use
* kernel semaphores. We don't use SysV semaphores because they are * kernel semaphores. We don't use SysV semaphores because they are
* persistent. */ * persistent.
*/
count = os_read_file(pipe_fd, &c, sizeof(c)); count = os_read_file(pipe_fd, &c, sizeof(c));
if (count != sizeof(c)) if (count != sizeof(c))
printk("winch_thread : failed to read synchronization byte, " printk(UM_KERN_ERR "winch_thread : failed to read "
"err = %d\n", -count); "synchronization byte, err = %d\n", -count);
while(1) { while(1) {
/* This will be interrupted by SIGWINCH only, since /*
* This will be interrupted by SIGWINCH only, since
* other signals are blocked. * other signals are blocked.
*/ */
sigsuspend(&sigs); sigsuspend(&sigs);
count = os_write_file(pipe_fd, &c, sizeof(c)); count = os_write_file(pipe_fd, &c, sizeof(c));
if (count != sizeof(c)) if (count != sizeof(c))
printk("winch_thread : write failed, err = %d\n", printk(UM_KERN_ERR "winch_thread : write failed, "
-count); "err = %d\n", -count);
} }
} }
@@ -199,35 +199,40 @@ static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out,
err = os_pipe(fds, 1, 1); err = os_pipe(fds, 1, 1);
if (err < 0) { if (err < 0) {
printk("winch_tramp : os_pipe failed, err = %d\n", -err); printk(UM_KERN_ERR "winch_tramp : os_pipe failed, err = %d\n",
-err);
goto out; goto out;
} }
data = ((struct winch_data) { .pty_fd = fd, data = ((struct winch_data) { .pty_fd = fd,
.pipe_fd = fds[1] } ); .pipe_fd = fds[1] } );
/* CLONE_FILES so this thread doesn't hold open files which are open /*
* CLONE_FILES so this thread doesn't hold open files which are open
* now, but later closed in a different thread. This is a * now, but later closed in a different thread. This is a
* problem with /dev/net/tun, which if held open by this * problem with /dev/net/tun, which if held open by this
* thread, prevents the TUN/TAP device from being reused. * thread, prevents the TUN/TAP device from being reused.
*/ */
err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out); err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out);
if (err < 0) { if (err < 0) {
printk("fork of winch_thread failed - errno = %d\n", -err); printk(UM_KERN_ERR "fork of winch_thread failed - errno = %d\n",
-err);
goto out_close; goto out_close;
} }
*fd_out = fds[0]; *fd_out = fds[0];
n = os_read_file(fds[0], &c, sizeof(c)); n = os_read_file(fds[0], &c, sizeof(c));
if (n != sizeof(c)) { if (n != sizeof(c)) {
printk("winch_tramp : failed to read synchronization byte\n"); printk(UM_KERN_ERR "winch_tramp : failed to read "
printk("read failed, err = %d\n", -n); "synchronization byte\n");
printk("fd %d will not support SIGWINCH\n", fd); printk(UM_KERN_ERR "read failed, err = %d\n", -n);
printk(UM_KERN_ERR "fd %d will not support SIGWINCH\n", fd);
err = -EINVAL; err = -EINVAL;
goto out_close; goto out_close;
} }
if (os_set_fd_block(*fd_out, 0)) { if (os_set_fd_block(*fd_out, 0)) {
printk("winch_tramp: failed to set thread_fd non-blocking.\n"); printk(UM_KERN_ERR "winch_tramp: failed to set thread_fd "
"non-blocking.\n");
goto out_close; goto out_close;
} }
@@ -260,7 +265,7 @@ void register_winch(int fd, struct tty_struct *tty)
count = os_write_file(thread_fd, &c, sizeof(c)); count = os_write_file(thread_fd, &c, sizeof(c));
if (count != sizeof(c)) if (count != sizeof(c))
printk("register_winch : failed to write " printk(UM_KERN_ERR "register_winch : failed to write "
"synchronization byte, err = %d\n", -count); "synchronization byte, err = %d\n", -count);
} }
} }

View File

@@ -1,17 +1,19 @@
/* /*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com) * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stdio.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <stdio.h>
#include <termios.h>
#include <errno.h> #include <errno.h>
#include "user.h" #include <termios.h>
#include <unistd.h>
#include "chan_user.h" #include "chan_user.h"
#include "os.h"
#include "um_malloc.h" #include "um_malloc.h"
#include "user.h"
#include "os.h"
#include "kern_constants.h"
struct fd_chan { struct fd_chan {
int fd; int fd;
@@ -27,21 +29,25 @@ static void *fd_init(char *str, int device, const struct chan_opts *opts)
int n; int n;
if (*str != ':') { if (*str != ':') {
printk("fd_init : channel type 'fd' must specify a file " printk(UM_KERN_ERR "fd_init : channel type 'fd' must specify a "
"descriptor\n"); "file descriptor\n");
return(NULL); return NULL;
} }
str++; str++;
n = strtoul(str, &end, 0); n = strtoul(str, &end, 0);
if ((*end != '\0') || (end == str)) { if ((*end != '\0') || (end == str)) {
printk("fd_init : couldn't parse file descriptor '%s'\n", str); printk(UM_KERN_ERR "fd_init : couldn't parse file descriptor "
return(NULL); "'%s'\n", str);
return NULL;
} }
data = kmalloc(sizeof(*data), UM_GFP_KERNEL); data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
if(data == NULL) return(NULL); if(data == NULL)
return NULL;
*data = ((struct fd_chan) { .fd = n, *data = ((struct fd_chan) { .fd = n,
.raw = opts->raw }); .raw = opts->raw });
return(data); return data;
} }
static int fd_open(int input, int output, int primary, void *d, char **dev_out) static int fd_open(int input, int output, int primary, void *d, char **dev_out)
@@ -52,15 +58,15 @@ static int fd_open(int input, int output, int primary, void *d, char **dev_out)
if (data->raw && isatty(data->fd)) { if (data->raw && isatty(data->fd)) {
CATCH_EINTR(err = tcgetattr(data->fd, &data->tt)); CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
if (err) if (err)
return(err); return err;
err = raw(data->fd); err = raw(data->fd);
if (err) if (err)
return(err); return err;
} }
sprintf(data->str, "%d", data->fd); sprintf(data->str, "%d", data->fd);
*dev_out = data->str; *dev_out = data->str;
return(data->fd); return data->fd;
} }
static void fd_close(int fd, void *d) static void fd_close(int fd, void *d)
@@ -68,14 +74,15 @@ static void fd_close(int fd, void *d)
struct fd_chan *data = d; struct fd_chan *data = d;
int err; int err;
if(data->raw && isatty(fd)){ if (!data->raw || !isatty(fd))
return;
CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt)); CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
if (err) if (err)
printk("Failed to restore terminal state - " printk(UM_KERN_ERR "Failed to restore terminal state - "
"errno = %d\n", -err); "errno = %d\n", -err);
data->raw = 0; data->raw = 0;
} }
}
const struct chan_ops fd_ops = { const struct chan_ops fd_ops = {
.type = "fd", .type = "fd",
@@ -89,14 +96,3 @@ const struct chan_ops fd_ops = {
.free = generic_free, .free = generic_free,
.winch = 1, .winch = 1,
}; };
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/

View File

@@ -1,31 +1,36 @@
/* /*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com) * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stdlib.h> #include <stddef.h>
#include <errno.h> #include <errno.h>
#include "chan_user.h" #include <fcntl.h>
#include "os.h" #include "os.h"
#include "chan_user.h"
/* This address is used only as a unique identifer */ /* This address is used only as a unique identifer */
static int null_chan; static int null_chan;
static void *null_init(char *str, int device, const struct chan_opts *opts) static void *null_init(char *str, int device, const struct chan_opts *opts)
{ {
return(&null_chan); return &null_chan;
} }
static int null_open(int input, int output, int primary, void *d, static int null_open(int input, int output, int primary, void *d,
char **dev_out) char **dev_out)
{ {
int fd;
*dev_out = NULL; *dev_out = NULL;
return(os_open_file(DEV_NULL, of_rdwr(OPENFLAGS()), 0));
fd = open(DEV_NULL, O_RDWR);
return (fd < 0) ? -errno : fd;
} }
static int null_read(int fd, char *c_out, void *unused) static int null_read(int fd, char *c_out, void *unused)
{ {
return(-ENODEV); return -ENODEV;
} }
static void null_free(void *data) static void null_free(void *data)
@@ -44,14 +49,3 @@ const struct chan_ops null_ops = {
.free = null_free, .free = null_free,
.winch = 0, .winch = 0,
}; };
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/

View File

@@ -1,24 +1,16 @@
/* /*
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include "linux/list.h" #include "linux/completion.h"
#include "linux/sched.h"
#include "linux/slab.h"
#include "linux/interrupt.h" #include "linux/interrupt.h"
#include "linux/spinlock.h" #include "linux/list.h"
#include "linux/errno.h"
#include "asm/atomic.h" #include "asm/atomic.h"
#include "asm/semaphore.h"
#include "asm/errno.h"
#include "kern_util.h"
#include "kern.h"
#include "irq_user.h"
#include "irq_kern.h"
#include "port.h"
#include "init.h" #include "init.h"
#include "irq_kern.h"
#include "os.h" #include "os.h"
#include "port.h"
struct port_list { struct port_list {
struct list_head list; struct list_head list;
@@ -81,7 +73,7 @@ static irqreturn_t pipe_interrupt(int irq, void *data)
static int port_accept(struct port_list *port) static int port_accept(struct port_list *port)
{ {
struct connection *conn; struct connection *conn;
int fd, socket[2], pid, ret = 0; int fd, socket[2], pid;
fd = port_connection(port->fd, socket, &pid); fd = port_connection(port->fd, socket, &pid);
if (fd < 0) { if (fd < 0) {
@@ -114,7 +106,7 @@ static int port_accept(struct port_list *port)
if (atomic_read(&port->wait_count) == 0) { if (atomic_read(&port->wait_count) == 0) {
os_write_file(fd, NO_WAITER_MSG, sizeof(NO_WAITER_MSG)); os_write_file(fd, NO_WAITER_MSG, sizeof(NO_WAITER_MSG));
printk("No one waiting for port\n"); printk(KERN_ERR "No one waiting for port\n");
} }
list_add(&conn->list, &port->pending); list_add(&conn->list, &port->pending);
return 1; return 1;
@@ -123,16 +115,15 @@ static int port_accept(struct port_list *port)
kfree(conn); kfree(conn);
out_close: out_close:
os_close_file(fd); os_close_file(fd);
if(pid != -1)
os_kill_process(pid, 1); os_kill_process(pid, 1);
out: out:
return ret; return 0;
} }
static DECLARE_MUTEX(ports_sem); static DECLARE_MUTEX(ports_sem);
static LIST_HEAD(ports); static LIST_HEAD(ports);
void port_work_proc(struct work_struct *unused) static void port_work_proc(struct work_struct *unused)
{ {
struct port_list *port; struct port_list *port;
struct list_head *ele; struct list_head *ele;
@@ -143,8 +134,10 @@ void port_work_proc(struct work_struct *unused)
port = list_entry(ele, struct port_list, list); port = list_entry(ele, struct port_list, list);
if (!port->has_connection) if (!port->has_connection)
continue; continue;
reactivate_fd(port->fd, ACCEPT_IRQ); reactivate_fd(port->fd, ACCEPT_IRQ);
while(port_accept(port)) ; while (port_accept(port))
;
port->has_connection = 0; port->has_connection = 0;
} }
local_irq_restore(flags); local_irq_restore(flags);
@@ -171,7 +164,8 @@ void *port_data(int port_num)
down(&ports_sem); down(&ports_sem);
list_for_each(ele, &ports) { list_for_each(ele, &ports) {
port = list_entry(ele, struct port_list, list); port = list_entry(ele, struct port_list, list);
if(port->port == port_num) goto found; if (port->port == port_num)
goto found;
} }
port = kmalloc(sizeof(struct port_list), GFP_KERNEL); port = kmalloc(sizeof(struct port_list), GFP_KERNEL);
if (port == NULL) { if (port == NULL) {
@@ -185,6 +179,7 @@ void *port_data(int port_num)
port_num, -fd); port_num, -fd);
goto out_free; goto out_free;
} }
if (um_request_irq(ACCEPT_IRQ, fd, IRQ_READ, port_interrupt, if (um_request_irq(ACCEPT_IRQ, fd, IRQ_READ, port_interrupt,
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM, IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
"port", port)) { "port", port)) {
@@ -258,7 +253,8 @@ int port_wait(void *data)
*/ */
free_irq(TELNETD_IRQ, conn); free_irq(TELNETD_IRQ, conn);
if(conn->fd >= 0) break; if (conn->fd >= 0)
break;
os_close_file(conn->fd); os_close_file(conn->fd);
kfree(conn); kfree(conn);
} }

View File

@@ -1,24 +1,20 @@
/* /*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com) * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stdio.h> #include <stdio.h>
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#include <termios.h> #include <termios.h>
#include <sys/socket.h> #include <unistd.h>
#include <sys/un.h>
#include <netinet/in.h> #include <netinet/in.h>
#include "kern_util.h"
#include "user.h"
#include "chan_user.h" #include "chan_user.h"
#include "port.h" #include "kern_constants.h"
#include "os.h" #include "os.h"
#include "port.h"
#include "um_malloc.h" #include "um_malloc.h"
#include "user.h"
struct port_chan { struct port_chan {
int raw; int raw;
@@ -35,14 +31,15 @@ static void *port_init(char *str, int device, const struct chan_opts *opts)
int port; int port;
if (*str != ':') { if (*str != ':') {
printk("port_init : channel type 'port' must specify a " printk(UM_KERN_ERR "port_init : channel type 'port' must "
"port number\n"); "specify a port number\n");
return NULL; return NULL;
} }
str++; str++;
port = strtoul(str, &end, 0); port = strtoul(str, &end, 0);
if ((*end != '\0') || (end == str)) { if ((*end != '\0') || (end == str)) {
printk("port_init : couldn't parse port '%s'\n", str); printk(UM_KERN_ERR "port_init : couldn't parse port '%s'\n",
str);
return NULL; return NULL;
} }
@@ -147,7 +144,7 @@ int port_listen_fd(int port)
return fd; return fd;
out: out:
os_close_file(fd); close(fd);
return err; return err;
} }
@@ -163,10 +160,10 @@ void port_pre_exec(void *arg)
dup2(data->sock_fd, 0); dup2(data->sock_fd, 0);
dup2(data->sock_fd, 1); dup2(data->sock_fd, 1);
dup2(data->sock_fd, 2); dup2(data->sock_fd, 2);
os_close_file(data->sock_fd); close(data->sock_fd);
dup2(data->pipe_fd, 3); dup2(data->pipe_fd, 3);
os_shutdown_socket(3, 1, 0); shutdown(3, SHUT_RD);
os_close_file(data->pipe_fd); close(data->pipe_fd);
} }
int port_connection(int fd, int *socket, int *pid_out) int port_connection(int fd, int *socket, int *pid_out)
@@ -176,9 +173,9 @@ int port_connection(int fd, int *socket, int *pid_out)
"/usr/lib/uml/port-helper", NULL }; "/usr/lib/uml/port-helper", NULL };
struct port_pre_exec_data data; struct port_pre_exec_data data;
new = os_accept_connection(fd); new = accept(fd, NULL, 0);
if (new < 0) if (new < 0)
return new; return -errno;
err = os_pipe(socket, 0, 0); err = os_pipe(socket, 0, 0);
if (err < 0) if (err < 0)
@@ -196,11 +193,11 @@ int port_connection(int fd, int *socket, int *pid_out)
return new; return new;
out_shutdown: out_shutdown:
os_shutdown_socket(socket[0], 1, 1); shutdown(socket[0], SHUT_RDWR);
os_close_file(socket[0]); close(socket[0]);
os_shutdown_socket(socket[1], 1, 1); shutdown(socket[1], SHUT_RDWR);
os_close_file(socket[1]); close(socket[1]);
out_close: out_close:
os_close_file(new); close(new);
return err; return err;
} }

View File

@@ -56,11 +56,11 @@ static int pts_open(int input, int output, int primary, void *d,
if (data->raw) { if (data->raw) {
CATCH_EINTR(err = tcgetattr(fd, &data->tt)); CATCH_EINTR(err = tcgetattr(fd, &data->tt));
if (err) if (err)
return err; goto out_close;
err = raw(fd); err = raw(fd);
if (err) if (err)
return err; goto out_close;
} }
dev = ptsname(fd); dev = ptsname(fd);
@@ -71,6 +71,10 @@ static int pts_open(int input, int output, int primary, void *d,
(*data->announce)(dev, data->dev); (*data->announce)(dev, data->dev);
return fd; return fd;
out_close:
close(fd);
return err;
} }
static int getmaster(char *line) static int getmaster(char *line)
@@ -121,9 +125,11 @@ static int pty_open(int input, int output, int primary, void *d,
if (data->raw) { if (data->raw) {
err = raw(fd); err = raw(fd);
if (err) if (err) {
close(fd);
return err; return err;
} }
}
if (data->announce) if (data->announce)
(*data->announce)(dev, data->dev); (*data->announce)(dev, data->dev);

View File

@@ -1,16 +1,16 @@
/* /*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com) * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stdio.h>
#include <termios.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <fcntl.h>
#include <termios.h>
#include "chan_user.h" #include "chan_user.h"
#include "user.h" #include "kern_constants.h"
#include "os.h" #include "os.h"
#include "um_malloc.h" #include "um_malloc.h"
#include "user.h"
struct tty_chan { struct tty_chan {
char *dev; char *dev;
@@ -23,7 +23,7 @@ static void *tty_chan_init(char *str, int device, const struct chan_opts *opts)
struct tty_chan *data; struct tty_chan *data;
if (*str != ':') { if (*str != ':') {
printk("tty_init : channel type 'tty' must specify " printk(UM_KERN_ERR "tty_init : channel type 'tty' must specify "
"a device\n"); "a device\n");
return NULL; return NULL;
} }
@@ -42,11 +42,18 @@ static int tty_open(int input, int output, int primary, void *d,
char **dev_out) char **dev_out)
{ {
struct tty_chan *data = d; struct tty_chan *data = d;
int fd, err; int fd, err, mode = 0;
fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0); if (input && output)
mode = O_RDWR;
else if (input)
mode = O_RDONLY;
else if (output)
mode = O_WRONLY;
fd = open(data->dev, mode);
if (fd < 0) if (fd < 0)
return fd; return -errno;
if (data->raw) { if (data->raw) {
CATCH_EINTR(err = tcgetattr(fd, &data->tt)); CATCH_EINTR(err = tcgetattr(fd, &data->tt));

View File

@@ -3,18 +3,19 @@
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include <termios.h> #include <termios.h>
#include "chan_user.h" #include "chan_user.h"
#include "kern_constants.h"
#include "os.h" #include "os.h"
#include "init.h" #include "um_malloc.h"
#include "user.h" #include "user.h"
#include "xterm.h" #include "xterm.h"
#include "kern_constants.h"
struct xterm_chan { struct xterm_chan {
int pid; int pid;
@@ -29,7 +30,7 @@ static void *xterm_init(char *str, int device, const struct chan_opts *opts)
{ {
struct xterm_chan *data; struct xterm_chan *data;
data = malloc(sizeof(*data)); data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
if (data == NULL) if (data == NULL)
return NULL; return NULL;
*data = ((struct xterm_chan) { .pid = -1, *data = ((struct xterm_chan) { .pid = -1,
@@ -207,11 +208,6 @@ static void xterm_close(int fd, void *d)
os_close_file(fd); os_close_file(fd);
} }
static void xterm_free(void *d)
{
free(d);
}
const struct chan_ops xterm_ops = { const struct chan_ops xterm_ops = {
.type = "xterm", .type = "xterm",
.init = xterm_init, .init = xterm_init,
@@ -221,6 +217,6 @@ const struct chan_ops xterm_ops = {
.write = generic_write, .write = generic_write,
.console_write = generic_console_write, .console_write = generic_console_write,
.window_size = generic_window_size, .window_size = generic_window_size,
.free = xterm_free, .free = generic_free,
.winch = 1, .winch = 1,
}; };