Skip to content

Commit

Permalink
uml: console subsystem tidying
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff Dike authored and Linus Torvalds committed Oct 16, 2007
1 parent 79f6623 commit e99525f
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 299 deletions.
160 changes: 80 additions & 80 deletions arch/um/drivers/chan_kern.c

Large diffs are not rendered by default.

111 changes: 58 additions & 53 deletions arch/um/drivers/chan_user.c
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand All @@ -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;
}

/*
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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);
}
}
74 changes: 35 additions & 39 deletions arch/um/drivers/fd.c
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,55 +28,60 @@ 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)
{
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)
{
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 = {
Expand All @@ -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:
*/
Loading

0 comments on commit e99525f

Please sign in to comment.