diff options
Diffstat (limited to 'arch/um/drivers/pty.c')
-rw-r--r-- | arch/um/drivers/pty.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/arch/um/drivers/pty.c b/arch/um/drivers/pty.c index 1e3fd619a837..49c79dda6046 100644 --- a/arch/um/drivers/pty.c +++ b/arch/um/drivers/pty.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ @@ -6,16 +6,16 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <string.h> -#include <fcntl.h> #include <errno.h> +#include <fcntl.h> +#include <string.h> #include <termios.h> #include <sys/stat.h> #include "chan_user.h" -#include "os.h" -#include "user.h" #include "kern_constants.h" +#include "os.h" #include "um_malloc.h" +#include "user.h" struct pty_chan { void (*announce)(char *dev_name, int dev); @@ -33,7 +33,7 @@ static void *pty_chan_init(char *str, int device, const struct chan_opts *opts) if (data == NULL) return NULL; - *data = ((struct pty_chan) { .announce = opts->announce, + *data = ((struct pty_chan) { .announce = opts->announce, .dev = device, .raw = opts->raw }); return data; @@ -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) @@ -97,7 +101,7 @@ static int getmaster(char *line) *tp = 't'; err = access(line, R_OK | W_OK); *tp = 'p'; - if(!err) + if (!err) return master; close(master); } @@ -119,12 +123,14 @@ 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) (*data->announce)(dev, data->dev); |