From 38a4db66e7e166f3b92f15e1c66d6707fcbab69d Mon Sep 17 00:00:00 2001 From: Ronny Chevalier Date: Wed, 15 Apr 2015 16:05:41 -0400 Subject: Ronny Chevalier shared: add terminal-util.[ch] Signed-off-by: Anthony G. Basile --- src/shared/util.c | 52 +--------------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) (limited to 'src/shared/util.c') diff --git a/src/shared/util.c b/src/shared/util.c index 0b04411f82..17ae61f90b 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -33,9 +33,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -71,6 +68,7 @@ #include "virt.h" #include "process-util.h" #include "random-util.h" +#include "terminal-util.h" /* Put this test here for a lack of better place */ assert_cc(EAGAIN == EWOULDBLOCK); @@ -78,9 +76,6 @@ assert_cc(EAGAIN == EWOULDBLOCK); int saved_argc = 0; char **saved_argv = NULL; -static volatile unsigned cached_columns = 0; -static volatile unsigned cached_lines = 0; - size_t page_size(void) { static thread_local size_t pgsz = 0; long r; @@ -600,51 +595,6 @@ bool hidden_file(const char *filename) { return hidden_file_allow_backup(filename); } -int open_terminal(const char *name, int mode) { - int fd, r; - unsigned c = 0; - - /* - * If a TTY is in the process of being closed opening it might - * cause EIO. This is horribly awful, but unlikely to be - * changed in the kernel. Hence we work around this problem by - * retrying a couple of times. - * - * https://bugs.launchpad.net/ubuntu/+source/linux/+bug/554172/comments/245 - */ - - assert(!(mode & O_CREAT)); - - for (;;) { - fd = open(name, mode, 0); - if (fd >= 0) - break; - - if (errno != EIO) - return -errno; - - /* Max 1s in total */ - if (c >= 20) - return -errno; - - usleep(50 * USEC_PER_MSEC); - c++; - } - - r = isatty(fd); - if (r < 0) { - safe_close(fd); - return -errno; - } - - if (!r) { - safe_close(fd); - return -ENOTTY; - } - - return fd; -} - int flush_fd(int fd) { struct pollfd pollfd = { .fd = fd, -- cgit v1.2.3-54-g00ecf