diff options
Diffstat (limited to 'arch/um/drivers/fd.c')
| -rw-r--r-- | arch/um/drivers/fd.c | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/arch/um/drivers/fd.c b/arch/um/drivers/fd.c index 39c01ffd45c9..0a2bb5b64b82 100644 --- a/arch/um/drivers/fd.c +++ b/arch/um/drivers/fd.c | |||
| @@ -1,17 +1,18 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) | 2 | * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) |
| 3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include <stdio.h> | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
| 8 | #include <unistd.h> | 8 | #include <unistd.h> |
| 9 | #include <termios.h> | ||
| 10 | #include <errno.h> | 9 | #include <errno.h> |
| 11 | #include "user.h" | 10 | #include <termios.h> |
| 12 | #include "chan_user.h" | 11 | #include "chan_user.h" |
| 12 | #include "kern_constants.h" | ||
| 13 | #include "os.h" | 13 | #include "os.h" |
| 14 | #include "um_malloc.h" | 14 | #include "um_malloc.h" |
| 15 | #include "user.h" | ||
| 15 | 16 | ||
| 16 | struct fd_chan { | 17 | struct fd_chan { |
| 17 | int fd; | 18 | int fd; |
| @@ -26,22 +27,26 @@ static void *fd_init(char *str, int device, const struct chan_opts *opts) | |||
| 26 | char *end; | 27 | char *end; |
| 27 | int n; | 28 | int n; |
| 28 | 29 | ||
| 29 | if(*str != ':'){ | 30 | if (*str != ':') { |
| 30 | printk("fd_init : channel type 'fd' must specify a file " | 31 | printk(UM_KERN_ERR "fd_init : channel type 'fd' must specify a " |
| 31 | "descriptor\n"); | 32 | "file descriptor\n"); |
| 32 | return(NULL); | 33 | return NULL; |
| 33 | } | 34 | } |
| 34 | str++; | 35 | str++; |
| 35 | n = strtoul(str, &end, 0); | 36 | n = strtoul(str, &end, 0); |
| 36 | if((*end != '\0') || (end == str)){ | 37 | if ((*end != '\0') || (end == str)) { |
| 37 | printk("fd_init : couldn't parse file descriptor '%s'\n", str); | 38 | printk(UM_KERN_ERR "fd_init : couldn't parse file descriptor " |
| 38 | return(NULL); | 39 | "'%s'\n", str); |
| 40 | return NULL; | ||
| 39 | } | 41 | } |
| 42 | |||
| 40 | data = kmalloc(sizeof(*data), UM_GFP_KERNEL); | 43 | data = kmalloc(sizeof(*data), UM_GFP_KERNEL); |
| 41 | if(data == NULL) return(NULL); | 44 | if (data == NULL) |
| 45 | return NULL; | ||
| 46 | |||
| 42 | *data = ((struct fd_chan) { .fd = n, | 47 | *data = ((struct fd_chan) { .fd = n, |
| 43 | .raw = opts->raw }); | 48 | .raw = opts->raw }); |
| 44 | return(data); | 49 | return data; |
| 45 | } | 50 | } |
| 46 | 51 | ||
| 47 | static int fd_open(int input, int output, int primary, void *d, char **dev_out) | 52 | static int fd_open(int input, int output, int primary, void *d, char **dev_out) |
| @@ -49,18 +54,18 @@ static int fd_open(int input, int output, int primary, void *d, char **dev_out) | |||
| 49 | struct fd_chan *data = d; | 54 | struct fd_chan *data = d; |
| 50 | int err; | 55 | int err; |
| 51 | 56 | ||
| 52 | if(data->raw && isatty(data->fd)){ | 57 | if (data->raw && isatty(data->fd)) { |
| 53 | CATCH_EINTR(err = tcgetattr(data->fd, &data->tt)); | 58 | CATCH_EINTR(err = tcgetattr(data->fd, &data->tt)); |
| 54 | if(err) | 59 | if (err) |
| 55 | return(err); | 60 | return err; |
| 56 | 61 | ||
| 57 | err = raw(data->fd); | 62 | err = raw(data->fd); |
| 58 | if(err) | 63 | if (err) |
| 59 | return(err); | 64 | return err; |
| 60 | } | 65 | } |
| 61 | sprintf(data->str, "%d", data->fd); | 66 | sprintf(data->str, "%d", data->fd); |
| 62 | *dev_out = data->str; | 67 | *dev_out = data->str; |
| 63 | return(data->fd); | 68 | return data->fd; |
| 64 | } | 69 | } |
| 65 | 70 | ||
| 66 | static void fd_close(int fd, void *d) | 71 | static void fd_close(int fd, void *d) |
| @@ -68,13 +73,14 @@ static void fd_close(int fd, void *d) | |||
| 68 | struct fd_chan *data = d; | 73 | struct fd_chan *data = d; |
| 69 | int err; | 74 | int err; |
| 70 | 75 | ||
| 71 | if(data->raw && isatty(fd)){ | 76 | if (!data->raw || !isatty(fd)) |
| 72 | CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt)); | 77 | return; |
| 73 | if(err) | 78 | |
| 74 | printk("Failed to restore terminal state - " | 79 | CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt)); |
| 75 | "errno = %d\n", -err); | 80 | if (err) |
| 76 | data->raw = 0; | 81 | printk(UM_KERN_ERR "Failed to restore terminal state - " |
| 77 | } | 82 | "errno = %d\n", -err); |
| 83 | data->raw = 0; | ||
| 78 | } | 84 | } |
| 79 | 85 | ||
| 80 | const struct chan_ops fd_ops = { | 86 | const struct chan_ops fd_ops = { |
| @@ -89,14 +95,3 @@ const struct chan_ops fd_ops = { | |||
| 89 | .free = generic_free, | 95 | .free = generic_free, |
| 90 | .winch = 1, | 96 | .winch = 1, |
| 91 | }; | 97 | }; |
| 92 | |||
| 93 | /* | ||
| 94 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
| 95 | * Emacs will notice this stuff at the end of the file and automatically | ||
| 96 | * adjust the settings for this buffer only. This must remain at the end | ||
| 97 | * of the file. | ||
| 98 | * --------------------------------------------------------------------------- | ||
| 99 | * Local variables: | ||
| 100 | * c-file-style: "linux" | ||
| 101 | * End: | ||
| 102 | */ | ||
