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
*/
#include <linux/stddef.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/string.h>
#include <linux/tty_flip.h>
#include <asm/irq.h>
#include "chan_kern.h"
#include "kern.h"
#include "irq_user.h"
#include "sigio.h"
#include "line.h"
#include "os.h"
#ifdef CONFIG_NOCONFIG_CHAN
static void *not_configged_init(char *str, int device,
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");
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,
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");
return -ENODEV;
}
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");
}
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");
return -EIO;
}
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");
return -EIO;
}
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");
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,
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");
return -ENODEV;
}
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");
}
@@ -91,7 +82,8 @@ static const struct chan_ops not_configged_ops = {
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 (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);
if (!chan->output || (chan->ops->write == NULL))
continue;
n = chan->ops->write(chan->fd, buf, len, chan->data);
if (chan->primary) {
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);
if (!chan->output || (chan->ops->console_write == NULL))
continue;
n = chan->ops->console_write(chan->fd, buf, len);
if(chan->primary) ret = n;
if (chan->primary)
ret = n;
}
return ret;
}
@@ -337,7 +332,8 @@ int console_open_chan(struct line *line, struct console *co)
if (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;
}
@@ -368,7 +364,8 @@ static void free_one_chan(struct chan *chan, int delay_free_irq)
if (chan->ops->free != NULL)
(*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);
}
@@ -606,7 +603,8 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task,
list_for_each_safe(ele, next, chans) {
chan = list_entry(ele, struct chan, list);
if(!chan->input || (chan->ops->read == NULL)) continue;
if (!chan->input || (chan->ops->read == NULL))
continue;
do {
if (tty && !tty_buffer_request_room(tty, 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);
} while (err > 0);
if(err == 0) reactivate_fd(chan->fd, irq);
if (err == 0)
reactivate_fd(chan->fd, irq);
if (err == -EIO) {
if (chan->primary) {
if (tty != NULL)
@@ -629,5 +628,6 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task,
}
}
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
*/
#include <unistd.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <termios.h>
#include <string.h>
#include <signal.h>
#include <sched.h>
#include <sys/stat.h>
#include <signal.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include "kern_util.h"
#include "chan_user.h"
#include "user.h"
#include "os.h"
#include "choose-mode.h"
#include "mode.h"
#include "um_malloc.h"
#include "user.h"
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.*/
if (isatty(fd))
CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
return(err);
return err;
error:
return(-errno);
return -errno;
}
/*
@@ -138,55 +132,61 @@ static int winch_thread(void *arg)
pipe_fd = data->pipe_fd;
count = os_write_file(pipe_fd, &c, sizeof(c));
if (count != sizeof(c))
printk("winch_thread : failed to write synchronization "
"byte, err = %d\n", -count);
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
/*
* 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. */
* SIGWINCH.
*/
signal(SIGWINCH, winch_handler);
sigfillset(&sigs);
/* Block all signals possible. */
if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) {
printk("winch_thread : sigprocmask failed, errno = %d\n",
errno);
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("winch_thread : setsid failed, errno = %d\n", errno);
printk(UM_KERN_ERR "winch_thread : setsid failed, errno = %d\n",
errno);
exit(1);
}
err = os_new_tty_pgrp(pty_fd, os_getpid());
if (err < 0) {
printk("winch_thread : new_tty_pgrp failed on fd %d, "
"err = %d\n", pty_fd, -err);
printk(UM_KERN_ERR "winch_thread : new_tty_pgrp failed on "
"fd %d err = %d\n", pty_fd, -err);
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
* kernel semaphores. We don't use SysV semaphores because they are
* persistent. */
* persistent.
*/
count = os_read_file(pipe_fd, &c, sizeof(c));
if (count != sizeof(c))
printk("winch_thread : failed to read synchronization byte, "
"err = %d\n", -count);
printk(UM_KERN_ERR "winch_thread : failed to read "
"synchronization byte, err = %d\n", -count);
while(1) {
/* This will be interrupted by SIGWINCH only, since
/*
* This will be interrupted by SIGWINCH only, since
* other signals are blocked.
*/
sigsuspend(&sigs);
count = os_write_file(pipe_fd, &c, sizeof(c));
if (count != sizeof(c))
printk("winch_thread : write failed, err = %d\n",
-count);
printk(UM_KERN_ERR "winch_thread : write failed, "
"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);
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;
}
data = ((struct winch_data) { .pty_fd = fd,
.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
* 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("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;
}
*fd_out = fds[0];
n = os_read_file(fds[0], &c, sizeof(c));
if (n != sizeof(c)) {
printk("winch_tramp : failed to read synchronization byte\n");
printk("read failed, err = %d\n", -n);
printk("fd %d will not support SIGWINCH\n", fd);
printk(UM_KERN_ERR "winch_tramp : failed to read "
"synchronization byte\n");
printk(UM_KERN_ERR "read failed, err = %d\n", -n);
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("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;
}
@@ -260,7 +265,7 @@ void register_winch(int fd, struct tty_struct *tty)
count = os_write_file(thread_fd, &c, 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);
}
}

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
*/
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <stdio.h>
#include <errno.h>
#include "user.h"
#include <termios.h>
#include <unistd.h>
#include "chan_user.h"
#include "os.h"
#include "um_malloc.h"
#include "user.h"
#include "os.h"
#include "kern_constants.h"
struct fd_chan {
int fd;
@@ -27,21 +29,25 @@ static void *fd_init(char *str, int device, const struct chan_opts *opts)
int n;
if (*str != ':') {
printk("fd_init : channel type 'fd' must specify a file "
"descriptor\n");
return(NULL);
printk(UM_KERN_ERR "fd_init : channel type 'fd' must specify a "
"file descriptor\n");
return NULL;
}
str++;
n = strtoul(str, &end, 0);
if ((*end != '\0') || (end == str)) {
printk("fd_init : couldn't parse file descriptor '%s'\n", str);
return(NULL);
printk(UM_KERN_ERR "fd_init : couldn't parse file descriptor "
"'%s'\n", str);
return NULL;
}
data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
if(data == NULL) return(NULL);
if(data == NULL)
return NULL;
*data = ((struct fd_chan) { .fd = n,
.raw = opts->raw });
return(data);
return data;
}
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)) {
CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
if (err)
return(err);
return err;
err = raw(data->fd);
if (err)
return(err);
return err;
}
sprintf(data->str, "%d", data->fd);
*dev_out = data->str;
return(data->fd);
return data->fd;
}
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;
int err;
if(data->raw && isatty(fd)){
if (!data->raw || !isatty(fd))
return;
CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
if (err)
printk("Failed to restore terminal state - "
printk(UM_KERN_ERR "Failed to restore terminal state - "
"errno = %d\n", -err);
data->raw = 0;
}
}
const struct chan_ops fd_ops = {
.type = "fd",
@@ -89,14 +96,3 @@ const struct chan_ops fd_ops = {
.free = generic_free,
.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
*/
#include <stdlib.h>
#include <stddef.h>
#include <errno.h>
#include "chan_user.h"
#include <fcntl.h>
#include "os.h"
#include "chan_user.h"
/* This address is used only as a unique identifer */
static int null_chan;
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,
char **dev_out)
{
int fd;
*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)
{
return(-ENODEV);
return -ENODEV;
}
static void null_free(void *data)
@@ -44,14 +49,3 @@ const struct chan_ops null_ops = {
.free = null_free,
.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
*/
#include "linux/list.h"
#include "linux/sched.h"
#include "linux/slab.h"
#include "linux/completion.h"
#include "linux/interrupt.h"
#include "linux/spinlock.h"
#include "linux/errno.h"
#include "linux/list.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 "irq_kern.h"
#include "os.h"
#include "port.h"
struct port_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)
{
struct connection *conn;
int fd, socket[2], pid, ret = 0;
int fd, socket[2], pid;
fd = port_connection(port->fd, socket, &pid);
if (fd < 0) {
@@ -114,7 +106,7 @@ static int port_accept(struct port_list *port)
if (atomic_read(&port->wait_count) == 0) {
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);
return 1;
@@ -123,16 +115,15 @@ static int port_accept(struct port_list *port)
kfree(conn);
out_close:
os_close_file(fd);
if(pid != -1)
os_kill_process(pid, 1);
out:
return ret;
return 0;
}
static DECLARE_MUTEX(ports_sem);
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 list_head *ele;
@@ -143,8 +134,10 @@ void port_work_proc(struct work_struct *unused)
port = list_entry(ele, struct port_list, list);
if (!port->has_connection)
continue;
reactivate_fd(port->fd, ACCEPT_IRQ);
while(port_accept(port)) ;
while (port_accept(port))
;
port->has_connection = 0;
}
local_irq_restore(flags);
@@ -171,7 +164,8 @@ void *port_data(int port_num)
down(&ports_sem);
list_for_each(ele, &ports) {
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);
if (port == NULL) {
@@ -185,6 +179,7 @@ void *port_data(int port_num)
port_num, -fd);
goto out_free;
}
if (um_request_irq(ACCEPT_IRQ, fd, IRQ_READ, port_interrupt,
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
"port", port)) {
@@ -258,7 +253,8 @@ int port_wait(void *data)
*/
free_irq(TELNETD_IRQ, conn);
if(conn->fd >= 0) break;
if (conn->fd >= 0)
break;
os_close_file(conn->fd);
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
*/
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <termios.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <netinet/in.h>
#include "kern_util.h"
#include "user.h"
#include "chan_user.h"
#include "port.h"
#include "kern_constants.h"
#include "os.h"
#include "port.h"
#include "um_malloc.h"
#include "user.h"
struct port_chan {
int raw;
@@ -35,14 +31,15 @@ static void *port_init(char *str, int device, const struct chan_opts *opts)
int port;
if (*str != ':') {
printk("port_init : channel type 'port' must specify a "
"port number\n");
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("port_init : couldn't parse port '%s'\n", str);
printk(UM_KERN_ERR "port_init : couldn't parse port '%s'\n",
str);
return NULL;
}
@@ -147,7 +144,7 @@ int port_listen_fd(int port)
return fd;
out:
os_close_file(fd);
close(fd);
return err;
}
@@ -163,10 +160,10 @@ void port_pre_exec(void *arg)
dup2(data->sock_fd, 0);
dup2(data->sock_fd, 1);
dup2(data->sock_fd, 2);
os_close_file(data->sock_fd);
close(data->sock_fd);
dup2(data->pipe_fd, 3);
os_shutdown_socket(3, 1, 0);
os_close_file(data->pipe_fd);
shutdown(3, SHUT_RD);
close(data->pipe_fd);
}
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 };
struct port_pre_exec_data data;
new = os_accept_connection(fd);
new = accept(fd, NULL, 0);
if (new < 0)
return new;
return -errno;
err = os_pipe(socket, 0, 0);
if (err < 0)
@@ -196,11 +193,11 @@ int port_connection(int fd, int *socket, int *pid_out)
return new;
out_shutdown:
os_shutdown_socket(socket[0], 1, 1);
os_close_file(socket[0]);
os_shutdown_socket(socket[1], 1, 1);
os_close_file(socket[1]);
shutdown(socket[0], SHUT_RDWR);
close(socket[0]);
shutdown(socket[1], SHUT_RDWR);
close(socket[1]);
out_close:
os_close_file(new);
close(new);
return err;
}

View File

@@ -56,11 +56,11 @@ static int pts_open(int input, int output, int primary, void *d,
if (data->raw) {
CATCH_EINTR(err = tcgetattr(fd, &data->tt));
if (err)
return err;
goto out_close;
err = raw(fd);
if (err)
return err;
goto out_close;
}
dev = ptsname(fd);
@@ -71,6 +71,10 @@ static int pts_open(int input, int output, int primary, void *d,
(*data->announce)(dev, data->dev);
return fd;
out_close:
close(fd);
return err;
}
static int getmaster(char *line)
@@ -121,9 +125,11 @@ static int pty_open(int input, int output, int primary, void *d,
if (data->raw) {
err = raw(fd);
if (err)
if (err) {
close(fd);
return err;
}
}
if (data->announce)
(*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
*/
#include <stdio.h>
#include <termios.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include "chan_user.h"
#include "user.h"
#include "kern_constants.h"
#include "os.h"
#include "um_malloc.h"
#include "user.h"
struct tty_chan {
char *dev;
@@ -23,7 +23,7 @@ static void *tty_chan_init(char *str, int device, const struct chan_opts *opts)
struct tty_chan *data;
if (*str != ':') {
printk("tty_init : channel type 'tty' must specify "
printk(UM_KERN_ERR "tty_init : channel type 'tty' must specify "
"a device\n");
return NULL;
}
@@ -42,11 +42,18 @@ static int tty_open(int input, int output, int primary, void *d,
char **dev_out)
{
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)
return fd;
return -errno;
if (data->raw) {
CATCH_EINTR(err = tcgetattr(fd, &data->tt));

View File

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