Commit 75886f21 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

uml: pty channel tidying

Cleanup, mostly style violations.

Tidied the includes.

getmaster returns a real errno, which pty_open returns if there's a
problem.

The printks now have severity.

Changed os_* calls to call libc directly.
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 63920f47
/* /*
* 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
*/ */
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <termios.h> #include <termios.h>
#include <sys/stat.h>
#include "chan_user.h" #include "chan_user.h"
#include "user.h"
#include "kern_util.h"
#include "os.h" #include "os.h"
#include "user.h"
#include "kern_constants.h"
#include "um_malloc.h" #include "um_malloc.h"
struct pty_chan { struct pty_chan {
...@@ -28,11 +30,13 @@ static void *pty_chan_init(char *str, int device, const struct chan_opts *opts) ...@@ -28,11 +30,13 @@ static void *pty_chan_init(char *str, int device, const struct chan_opts *opts)
struct pty_chan *data; struct pty_chan *data;
data = um_kmalloc(sizeof(*data)); data = um_kmalloc(sizeof(*data));
if(data == NULL) return(NULL); if (data == NULL)
return NULL;
*data = ((struct pty_chan) { .announce = opts->announce, *data = ((struct pty_chan) { .announce = opts->announce,
.dev = device, .dev = device,
.raw = opts->raw }); .raw = opts->raw });
return(data); return data;
} }
static int pts_open(int input, int output, int primary, void *d, static int pts_open(int input, int output, int primary, void *d,
...@@ -43,31 +47,35 @@ static int pts_open(int input, int output, int primary, void *d, ...@@ -43,31 +47,35 @@ static int pts_open(int input, int output, int primary, void *d,
int fd, err; int fd, err;
fd = get_pty(); fd = get_pty();
if(fd < 0){ if (fd < 0) {
err = -errno; err = -errno;
printk("open_pts : Failed to open pts\n"); printk(UM_KERN_ERR "open_pts : Failed to open pts\n");
return err; return err;
} }
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); return err;
err = raw(fd); err = raw(fd);
if(err) if (err)
return(err); return err;
} }
dev = ptsname(fd); dev = ptsname(fd);
sprintf(data->dev_name, "%s", dev); sprintf(data->dev_name, "%s", dev);
*dev_out = data->dev_name; *dev_out = data->dev_name;
if (data->announce) if (data->announce)
(*data->announce)(dev, data->dev); (*data->announce)(dev, data->dev);
return(fd);
return fd;
} }
static int getmaster(char *line) static int getmaster(char *line)
{ {
struct stat buf;
char *pty, *bank, *cp; char *pty, *bank, *cp;
int master, err; int master, err;
...@@ -75,24 +83,29 @@ static int getmaster(char *line) ...@@ -75,24 +83,29 @@ static int getmaster(char *line)
for (bank = "pqrs"; *bank; bank++) { for (bank = "pqrs"; *bank; bank++) {
line[strlen("/dev/pty")] = *bank; line[strlen("/dev/pty")] = *bank;
*pty = '0'; *pty = '0';
if (os_stat_file(line, NULL) < 0) /* Did we hit the end ? */
if ((stat(line, &buf) < 0) && (errno == ENOENT))
break; break;
for (cp = "0123456789abcdef"; *cp; cp++) { for (cp = "0123456789abcdef"; *cp; cp++) {
*pty = *cp; *pty = *cp;
master = os_open_file(line, of_rdwr(OPENFLAGS()), 0); master = open(line, O_RDWR);
if (master >= 0) { if (master >= 0) {
char *tp = &line[strlen("/dev/")]; char *tp = &line[strlen("/dev/")];
/* verify slave side is usable */ /* verify slave side is usable */
*tp = 't'; *tp = 't';
err = os_access(line, OS_ACC_RW_OK); err = access(line, R_OK | W_OK);
*tp = 'p'; *tp = 'p';
if(err == 0) return(master); if(!err)
(void) os_close_file(master); return master;
close(master);
} }
} }
} }
return(-1);
printk(UM_KERN_ERR "getmaster - no usable host pty devices\n");
return -ENOENT;
} }
static int pty_open(int input, int output, int primary, void *d, static int pty_open(int input, int output, int primary, void *d,
...@@ -103,20 +116,22 @@ static int pty_open(int input, int output, int primary, void *d, ...@@ -103,20 +116,22 @@ static int pty_open(int input, int output, int primary, void *d,
char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx"; char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
fd = getmaster(dev); fd = getmaster(dev);
if(fd < 0) if (fd < 0)
return(-errno); return fd;
if(data->raw){ if(data->raw){
err = raw(fd); err = raw(fd);
if(err) if (err)
return(err); return err;
} }
if(data->announce) (*data->announce)(dev, data->dev); if (data->announce)
(*data->announce)(dev, data->dev);
sprintf(data->dev_name, "%s", dev); sprintf(data->dev_name, "%s", dev);
*dev_out = data->dev_name; *dev_out = data->dev_name;
return(fd);
return fd;
} }
const struct chan_ops pty_ops = { const struct chan_ops pty_ops = {
...@@ -144,14 +159,3 @@ const struct chan_ops pts_ops = { ...@@ -144,14 +159,3 @@ const struct chan_ops pts_ops = {
.free = generic_free, .free = generic_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:
*/
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