Commit 63920f47 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

uml: xterm driver tidying

Major tidying of the xterm console driver:
	got rid of the tt-mode gdb support
	tidied up the includes
	fixed lots of style violations
	replaced os_* calls with glibc calls in xterm.c
	all printk calls now have a severity indicator
	the error paths of xterm_open are closer to being right
Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 89df6bfc
...@@ -42,8 +42,6 @@ static struct chan_opts opts = { ...@@ -42,8 +42,6 @@ static struct chan_opts opts = {
.announce = ssl_announce, .announce = ssl_announce,
.xterm_title = "Serial Line #%d", .xterm_title = "Serial Line #%d",
.raw = 1, .raw = 1,
.tramp_stack = 0,
.in_kernel = 1,
}; };
static int ssl_config(char *str, char **error_out); static int ssl_config(char *str, char **error_out);
......
...@@ -46,8 +46,6 @@ static struct chan_opts opts = { ...@@ -46,8 +46,6 @@ static struct chan_opts opts = {
.announce = stdio_announce, .announce = stdio_announce,
.xterm_title = "Virtual Console #%d", .xterm_title = "Virtual Console #%d",
.raw = 1, .raw = 1,
.tramp_stack = 0,
.in_kernel = 1,
}; };
static int con_config(char *str, char **error_out); static int con_config(char *str, char **error_out);
......
/* /*
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <termios.h> #include <termios.h>
#include <signal.h>
#include <sched.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 "init.h"
#include "user.h"
#include "xterm.h" #include "xterm.h"
#include "kern_constants.h"
struct xterm_chan { struct xterm_chan {
int pid; int pid;
...@@ -25,25 +23,21 @@ struct xterm_chan { ...@@ -25,25 +23,21 @@ struct xterm_chan {
int device; int device;
int raw; int raw;
struct termios tt; struct termios tt;
unsigned long stack;
int direct_rcv;
}; };
/* Not static because it's called directly by the tt mode gdb code */ static void *xterm_init(char *str, int device, const struct chan_opts *opts)
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 = malloc(sizeof(*data));
if(data == NULL) return(NULL); if (data == NULL)
return NULL;
*data = ((struct xterm_chan) { .pid = -1, *data = ((struct xterm_chan) { .pid = -1,
.helper_pid = -1, .helper_pid = -1,
.device = device, .device = device,
.title = opts->xterm_title, .title = opts->xterm_title,
.raw = opts->raw, .raw = opts->raw } );
.stack = opts->tramp_stack, return data;
.direct_rcv = !opts->in_kernel } );
return(data);
} }
/* Only changed by xterm_setup, which is a setup */ /* Only changed by xterm_setup, which is a setup */
...@@ -57,16 +51,22 @@ static int __init xterm_setup(char *line, int *add) ...@@ -57,16 +51,22 @@ static int __init xterm_setup(char *line, int *add)
terminal_emulator = line; terminal_emulator = line;
line = strchr(line, ','); line = strchr(line, ',');
if(line == NULL) return(0); if (line == NULL)
return 0;
*line++ = '\0'; *line++ = '\0';
if(*line) title_switch = line; if (*line)
title_switch = line;
line = strchr(line, ','); line = strchr(line, ',');
if(line == NULL) return(0); if (line == NULL)
return 0;
*line++ = '\0'; *line++ = '\0';
if(*line) exec_switch = line; if (*line)
exec_switch = line;
return(0); return 0;
} }
__uml_setup("xterm=", xterm_setup, __uml_setup("xterm=", xterm_setup,
...@@ -82,114 +82,128 @@ __uml_setup("xterm=", xterm_setup, ...@@ -82,114 +82,128 @@ __uml_setup("xterm=", xterm_setup,
" are 'xterm=gnome-terminal,-t,-x'.\n\n" " are 'xterm=gnome-terminal,-t,-x'.\n\n"
); );
/* XXX This badly needs some cleaning up in the error paths static int xterm_open(int input, int output, int primary, void *d,
* Not static because it's called directly by the tt mode gdb code
*/
int xterm_open(int input, int output, int primary, void *d,
char **dev_out) char **dev_out)
{ {
struct xterm_chan *data = d; struct xterm_chan *data = d;
unsigned long stack;
int pid, fd, new, err; int pid, fd, new, err;
char title[256], file[] = "/tmp/xterm-pipeXXXXXX"; char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
char *argv[] = { terminal_emulator, title_switch, title, exec_switch, char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
"/usr/lib/uml/port-helper", "-uml-socket", "/usr/lib/uml/port-helper", "-uml-socket",
file, NULL }; file, NULL };
if(os_access(argv[4], OS_ACC_X_OK) < 0) if (access(argv[4], X_OK) < 0)
argv[4] = "port-helper"; argv[4] = "port-helper";
/* Check that DISPLAY is set, this doesn't guarantee the xterm /* Check that DISPLAY is set, this doesn't guarantee the xterm
* will work but w/o it we can be pretty sure it won't. */ * will work but w/o it we can be pretty sure it won't. */
if (!getenv("DISPLAY")) { if (getenv("DISPLAY") == NULL) {
printk("xterm_open: $DISPLAY not set.\n"); printk(UM_KERN_ERR "xterm_open: $DISPLAY not set.\n");
return -ENODEV; return -ENODEV;
} }
/*
* This business of getting a descriptor to a temp file,
* deleting the file and closing the descriptor is just to get
* a known-unused name for the Unix socket that we really
* want.
*/
fd = mkstemp(file); fd = mkstemp(file);
if(fd < 0){ if (fd < 0) {
err = -errno; err = -errno;
printk("xterm_open : mkstemp failed, errno = %d\n", errno); printk(UM_KERN_ERR "xterm_open : mkstemp failed, errno = %d\n",
errno);
return err; return err;
} }
if(unlink(file)){ if (unlink(file)) {
err = -errno; err = -errno;
printk("xterm_open : unlink failed, errno = %d\n", errno); printk(UM_KERN_ERR "xterm_open : unlink failed, errno = %d\n",
errno);
return err; return err;
} }
os_close_file(fd); close(fd);
fd = os_create_unix_socket(file, sizeof(file), 1); fd = os_create_unix_socket(file, sizeof(file), 1);
if(fd < 0){ if (fd < 0) {
printk("xterm_open : create_unix_socket failed, errno = %d\n", printk(UM_KERN_ERR "xterm_open : create_unix_socket failed, "
-fd); "errno = %d\n", -fd);
return(fd); return fd;
} }
sprintf(title, data->title, data->device); sprintf(title, data->title, data->device);
stack = data->stack; pid = run_helper(NULL, NULL, argv, NULL);
pid = run_helper(NULL, NULL, argv, &stack); if (pid < 0) {
if(pid < 0){ err = pid;
printk("xterm_open : run_helper failed, errno = %d\n", -pid); printk(UM_KERN_ERR "xterm_open : run_helper failed, "
return(pid); "errno = %d\n", -err);
goto out_close1;
} }
if (data->direct_rcv) {
new = os_rcv_fd(fd, &data->helper_pid);
} else {
err = os_set_fd_block(fd, 0); err = os_set_fd_block(fd, 0);
if(err < 0){ if (err < 0) {
printk("xterm_open : failed to set descriptor " printk(UM_KERN_ERR "xterm_open : failed to set descriptor "
"non-blocking, err = %d\n", -err); "non-blocking, err = %d\n", -err);
return(err); goto out_kill;
} }
new = xterm_fd(fd, &data->helper_pid); new = xterm_fd(fd, &data->helper_pid);
} if (new < 0) {
if(new < 0){ err = new;
printk("xterm_open : os_rcv_fd failed, err = %d\n", -new); printk(UM_KERN_ERR "xterm_open : os_rcv_fd failed, err = %d\n",
goto out; -err);
goto out_kill;
} }
err = os_set_fd_block(new, 0); err = os_set_fd_block(new, 0);
if (err) { if (err) {
printk("xterm_open : failed to set xterm descriptor " printk(UM_KERN_ERR "xterm_open : failed to set xterm "
"non-blocking, err = %d\n", -err); "descriptor non-blocking, err = %d\n", -err);
goto out; goto out_close2;
} }
CATCH_EINTR(err = tcgetattr(new, &data->tt)); CATCH_EINTR(err = tcgetattr(new, &data->tt));
if(err){ if (err) {
new = err; new = err;
goto out; goto out_close2;
} }
if(data->raw){ if (data->raw) {
err = raw(new); err = raw(new);
if(err){ if (err) {
new = err; new = err;
goto out; goto out_close2;
} }
} }
unlink(file);
data->pid = pid; data->pid = pid;
*dev_out = NULL; *dev_out = NULL;
out:
unlink(file); return new;
return(new);
out_close2:
close(new);
out_kill:
os_kill_process(pid, 1);
out_close1:
close(fd);
return err;
} }
/* Not static because it's called directly by the tt mode gdb code */ static void xterm_close(int fd, void *d)
void xterm_close(int fd, void *d)
{ {
struct xterm_chan *data = d; struct xterm_chan *data = d;
if(data->pid != -1) if (data->pid != -1)
os_kill_process(data->pid, 1); os_kill_process(data->pid, 1);
data->pid = -1; data->pid = -1;
if(data->helper_pid != -1)
if (data->helper_pid != -1)
os_kill_process(data->helper_pid, 0); os_kill_process(data->helper_pid, 0);
data->helper_pid = -1; data->helper_pid = -1;
os_close_file(fd); os_close_file(fd);
} }
...@@ -210,14 +224,3 @@ const struct chan_ops xterm_ops = { ...@@ -210,14 +224,3 @@ const struct chan_ops xterm_ops = {
.free = xterm_free, .free = xterm_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:
*/
/* /*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com) * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include "linux/errno.h" #include <linux/slab.h>
#include "linux/slab.h" #include <linux/completion.h>
#include "linux/signal.h" #include <linux/irqreturn.h>
#include "linux/interrupt.h" #include <asm/irq.h>
#include "asm/irq.h"
#include "irq_user.h"
#include "irq_kern.h" #include "irq_kern.h"
#include "kern_util.h"
#include "os.h" #include "os.h"
#include "xterm.h"
struct xterm_wait { struct xterm_wait {
struct completion ready; struct completion ready;
...@@ -27,12 +23,13 @@ static irqreturn_t xterm_interrupt(int irq, void *data) ...@@ -27,12 +23,13 @@ static irqreturn_t xterm_interrupt(int irq, void *data)
int fd; int fd;
fd = os_rcv_fd(xterm->fd, &xterm->pid); fd = os_rcv_fd(xterm->fd, &xterm->pid);
if(fd == -EAGAIN) if (fd == -EAGAIN)
return(IRQ_NONE); return IRQ_NONE;
xterm->new_fd = fd; xterm->new_fd = fd;
complete(&xterm->ready); complete(&xterm->ready);
return(IRQ_HANDLED);
return IRQ_HANDLED;
} }
int xterm_fd(int socket, int *pid_out) int xterm_fd(int socket, int *pid_out)
...@@ -41,14 +38,13 @@ int xterm_fd(int socket, int *pid_out) ...@@ -41,14 +38,13 @@ int xterm_fd(int socket, int *pid_out)
int err, ret; int err, ret;
data = kmalloc(sizeof(*data), GFP_KERNEL); data = kmalloc(sizeof(*data), GFP_KERNEL);
if(data == NULL){ if (data == NULL) {
printk(KERN_ERR "xterm_fd : failed to allocate xterm_wait\n"); printk(KERN_ERR "xterm_fd : failed to allocate xterm_wait\n");
return(-ENOMEM); return -ENOMEM;
} }
/* This is a locked semaphore... */ /* This is a locked semaphore... */
*data = ((struct xterm_wait) *data = ((struct xterm_wait) { .fd = socket,
{ .fd = socket,
.pid = -1, .pid = -1,
.new_fd = -1 }); .new_fd = -1 });
init_completion(&data->ready); init_completion(&data->ready);
...@@ -56,7 +52,7 @@ int xterm_fd(int socket, int *pid_out) ...@@ -56,7 +52,7 @@ int xterm_fd(int socket, int *pid_out)
err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt, err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt,
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM, IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
"xterm", data); "xterm", data);
if (err){ if (err) {
printk(KERN_ERR "xterm_fd : failed to get IRQ for xterm, " printk(KERN_ERR "xterm_fd : failed to get IRQ for xterm, "
"err = %d\n", err); "err = %d\n", err);
ret = err; ret = err;
...@@ -76,16 +72,5 @@ int xterm_fd(int socket, int *pid_out) ...@@ -76,16 +72,5 @@ int xterm_fd(int socket, int *pid_out)
out: out:
kfree(data); kfree(data);
return(ret); return ret;
} }
/*
* 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:
*/
...@@ -12,8 +12,6 @@ struct chan_opts { ...@@ -12,8 +12,6 @@ struct chan_opts {
void (*const announce)(char *dev_name, int dev); void (*const announce)(char *dev_name, int dev);
char *xterm_title; char *xterm_title;
const int raw; const int raw;
const unsigned long tramp_stack;
const int in_kernel;
}; };
enum chan_init_pri { INIT_STATIC, INIT_ALL, INIT_ONE }; enum chan_init_pri { INIT_STATIC, INIT_ALL, INIT_ONE };
......
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