Commit e99525f9 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

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: default avatarJeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 79f66233
This diff is collapsed.
/*
* 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)
{
......@@ -53,7 +47,7 @@ int generic_window_size(int fd, void *unused, unsigned short *rows_out,
struct winsize size;
int ret;
if(ioctl(fd, TIOCGWINSZ, &size) < 0)
if (ioctl(fd, TIOCGWINSZ, &size) < 0)
return -errno;
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)
struct termios save, new;
int err;
if(isatty(fd)){
if (isatty(fd)) {
CATCH_EINTR(err = tcgetattr(fd, &save));
if (err)
goto error;
......@@ -90,11 +84,11 @@ int generic_console_write(int fd, const char *buf, int n)
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))
if (isatty(fd))
CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
return(err);
return err;
error:
return(-errno);
return -errno;
}
/*
......@@ -137,56 +131,62 @@ static int winch_thread(void *arg)
pty_fd = data->pty_fd;
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);
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
/*
* 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);
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("winch_thread : setsid failed, errno = %d\n", errno);
if (setsid() < 0) {
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);
if (err < 0) {
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);
if (count != sizeof(c))
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
while(1) {
/*
* 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);
if (count != sizeof(c))
printk(UM_KERN_ERR "winch_thread : write failed, "
"err = %d\n", -count);
}
}
......@@ -198,36 +198,41 @@ static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out,
char c;
err = os_pipe(fds, 1, 1);
if(err < 0){
printk("winch_tramp : os_pipe failed, err = %d\n", -err);
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
/*
* 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);
if (err < 0) {
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);
err = -EINVAL;
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", -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;
}
......@@ -246,7 +251,7 @@ void register_winch(int fd, struct tty_struct *tty)
int pid, thread, count, thread_fd = -1;
char c = 1;
if(!isatty(fd))
if (!isatty(fd))
return;
pid = tcgetpgrp(fd);
......@@ -259,8 +264,8 @@ void register_winch(int fd, struct tty_struct *tty)
register_winch_irq(thread_fd, fd, thread, tty, stack);
count = os_write_file(thread_fd, &c, sizeof(c));
if(count != sizeof(c))
printk("register_winch : failed to write "
if (count != sizeof(c))
printk(UM_KERN_ERR "register_winch : failed to write "
"synchronization byte, err = %d\n", -count);
}
}
/*
* 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;
......@@ -26,22 +28,26 @@ static void *fd_init(char *str, int device, const struct chan_opts *opts)
char *end;
int n;
if(*str != ':'){
printk("fd_init : channel type 'fd' must specify a file "
"descriptor\n");
return(NULL);
if (*str != ':') {
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);
if ((*end != '\0') || (end == str)) {
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)
......@@ -49,18 +55,18 @@ static int fd_open(int input, int output, int primary, void *d, char **dev_out)
struct fd_chan *data = d;
int err;
if(data->raw && isatty(data->fd)){
if (data->raw && isatty(data->fd)) {
CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
if(err)
return(err);
if (err)
return err;
err = raw(data->fd);
if(err)
return(err);
if (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,13 +74,14 @@ static void fd_close(int fd, void *d)
struct fd_chan *data = d;
int err;
if(data->raw && isatty(fd)){
CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
if(err)
printk("Failed to restore terminal state - "
"errno = %d\n", -err);
data->raw = 0;
}
if (!data->raw || !isatty(fd))
return;
CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
if (err)
printk(UM_KERN_ERR "Failed to restore terminal state - "
"errno = %d\n", -err);
data->raw = 0;
}
const struct chan_ops fd_ops = {
......@@ -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:
*/
/*
* 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:
*/
/*
* 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;
......@@ -53,8 +45,8 @@ static irqreturn_t pipe_interrupt(int irq, void *data)
int fd;
fd = os_rcv_fd(conn->socket[0], &conn->helper_pid);
if(fd < 0){
if(fd == -EAGAIN)
if (fd < 0) {
if (fd == -EAGAIN)
return IRQ_NONE;
printk(KERN_ERR "pipe_interrupt : os_rcv_fd returned %d\n",
......@@ -81,18 +73,18 @@ 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){
if(fd != -EAGAIN)
if (fd < 0) {
if (fd != -EAGAIN)
printk(KERN_ERR "port_accept : port_connection "
"returned %d\n", -fd);
goto out;
}
conn = kmalloc(sizeof(*conn), GFP_ATOMIC);
if(conn == NULL){
if (conn == NULL) {
printk(KERN_ERR "port_accept : failed to allocate "
"connection\n");
goto out_close;
......@@ -104,17 +96,17 @@ static int port_accept(struct port_list *port)
.telnetd_pid = pid,
.port = port });
if(um_request_irq(TELNETD_IRQ, socket[0], IRQ_READ, pipe_interrupt,
if (um_request_irq(TELNETD_IRQ, socket[0], IRQ_READ, pipe_interrupt,
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
"telnetd", conn)){
"telnetd", conn)) {
printk(KERN_ERR "port_accept : failed to get IRQ for "
"telnetd\n");
goto out_free;
}
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));
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,28 +115,29 @@ static int port_accept(struct port_list *port)
kfree(conn);
out_close:
os_close_file(fd);
if(pid != -1)
os_kill_process(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;
unsigned long flags;
local_irq_save(flags);
list_for_each(ele, &ports){
list_for_each(ele, &ports) {
port = list_entry(ele, struct port_list, list);
if(!port->has_connection)
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);
......@@ -169,25 +162,27 @@ void *port_data(int port_num)
int fd;
down(&ports_sem);
list_for_each(ele, &ports){
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){
if (port == NULL) {
printk(KERN_ERR "Allocation of port list failed\n");
goto out;
}
fd = port_listen_fd(port_num);
if(fd < 0){
if (fd < 0) {
printk(KERN_ERR "binding to port %d failed, errno = %d\n",
port_num, -fd);
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,
"port", port)){
"port", port)) {
printk(KERN_ERR "Failed to get IRQ for port %d\n", port_num);
goto out_close;
}
......@@ -206,7 +201,7 @@ void *port_data(int port_num)
found:
dev = kmalloc(sizeof(struct port_dev), GFP_KERNEL);
if(dev == NULL){
if (dev == NULL) {
printk(KERN_ERR "Allocation of port device entry failed\n");
goto out;
}
......@@ -233,9 +228,9 @@ int port_wait(void *data)
int fd;
atomic_inc(&port->wait_count);
while(1){
while (1) {
fd = -ERESTARTSYS;
if(wait_for_completion_interruptible(&port->done))
if (wait_for_completion_interruptible(&port->done))
goto out;
spin_lock(&port->lock);
......@@ -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);
}
......@@ -276,9 +272,9 @@ void port_remove_dev(void *d)
{
struct port_dev *dev = d;
if(dev->helper_pid != -1)
if (dev->helper_pid != -1)
os_kill_process(dev->helper_pid, 0);
if(dev->telnetd_pid != -1)
if (dev->telnetd_pid != -1)
os_kill_process(dev->telnetd_pid, 1);
dev->helper_pid = -1;
dev->telnetd_pid = -1;
......@@ -297,7 +293,7 @@ static void free_port(void)
struct list_head *ele;
struct port_list *port;
list_for_each(ele, &ports){
list_for_each(ele, &ports) {
port = list_entry(ele, struct port_list, list);
free_irq_by_fd(port->fd);
os_close_file(port->fd);
......
/*
* 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;
......@@ -34,24 +30,25 @@ static void *port_init(char *str, int device, const struct chan_opts *opts)
char *end;
int port;
if(*str != ':'){
printk("port_init : channel type 'port' must specify a "
"port number\n");
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("port_init : couldn't parse port '%s'\n", str);
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)
if (kern_data == NULL)
return NULL;
data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
if(data == NULL)
if (data == NULL)
goto err;
*data = ((struct port_chan) { .raw = opts->raw,
......@@ -79,13 +76,13 @@ static int port_open(int input, int output, int primary, void *d,
int fd, err;
fd = port_wait(data->kernel_data);
if((fd >= 0) && data->raw){
if ((fd >= 0) && data->raw) {
CATCH_EINTR(err = tcgetattr(fd, &data->tt));
if(err)
if (err)
return err;
err = raw(fd);
if(err)
if (err)
return err;
}
*dev_out = data->dev;
......@@ -119,11 +116,11 @@ int port_listen_fd(int port)
int fd, err, arg;
fd = socket(PF_INET, SOCK_STREAM, 0);
if(fd == -1)
if (fd == -1)
return -errno;
arg = 1;
if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof(arg)) < 0){
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof(arg)) < 0) {
err = -errno;
goto out;
}
......@@ -131,23 +128,23 @@ int port_listen_fd(int port)
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){
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
err = -errno;
goto out;
}
if(listen(fd, 1) < 0){
if (listen(fd, 1) < 0) {
err = -errno;
goto out;
}
err = os_set_fd_block(fd, 0);
if(err < 0)
if (err < 0)
goto out;
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,12 +173,12 @@ 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);
if(new < 0)
return new;
new = accept(fd, NULL, 0);
if (new < 0)
return -errno;
err = os_pipe(socket, 0, 0);
if(err < 0)
if (err < 0)
goto out_close;
data = ((struct port_pre_exec_data)
......@@ -189,18 +186,18 @@ int port_connection(int fd, int *socket, int *pid_out)
.pipe_fd = socket[1] });
err = run_helper(port_pre_exec, &data, argv);
if(err < 0)
if (err < 0)
goto out_shutdown;
*pid_out = err;
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;
}
......@@ -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)
......@@ -119,10 +123,12 @@ static int pty_open(int input, int output, int primary, void *d,
if (fd < 0)
return fd;
if(data->raw){
if (data->raw) {
err = raw(fd);
if (err)
if (err) {
close(fd);
return err;
}
}
if (data->announce)
......
/*
* 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;
......@@ -22,15 +22,15 @@ 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 "
if (*str != ':') {
printk(UM_KERN_ERR "tty_init : channel type 'tty' must specify "
"a device\n");
return NULL;
}
str++;
data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
if(data == NULL)
if (data == NULL)
return NULL;
*data = ((struct tty_chan) { .dev = str,
.raw = opts->raw });
......@@ -42,19 +42,26 @@ 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;
if (input && output)
mode = O_RDWR;
else if (input)
mode = O_RDONLY;
else if (output)
mode = O_WRONLY;
fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0);
if(fd < 0)
return fd;
fd = open(data->dev, mode);
if (fd < 0)
return -errno;
if(data->raw){
if (data->raw) {
CATCH_EINTR(err = tcgetattr(fd, &data->tt));
if(err)
if (err)
return err;
err = raw(fd);
if(err)
if (err)
return err;
}
......
......@@ -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,
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment