Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Cluster Development (http://www.linux-archive.org/cluster-development/)
-   -   libgfs2: Move gfs2_getch into utils (http://www.linux-archive.org/cluster-development/604728-libgfs2-move-gfs2_getch-into-utils.html)

Steven Whitehouse 11-30-2011 02:04 PM

libgfs2: Move gfs2_getch into utils
 
More UI code being moved out of the library.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
gfs2/convert/gfs2_convert.c | 36 ++++++++++++++++++++++++++++++++----
gfs2/fsck/util.c | 28 ++++++++++++++++++++++++++++
gfs2/fsck/util.h | 1 +
gfs2/libgfs2/gfs2_log.c | 28 ----------------------------
gfs2/libgfs2/libgfs2.h | 1 -
5 files changed, 61 insertions(+), 33 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index f79b4a4..9f24137 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -23,6 +23,7 @@
#include <sys/time.h>
#include <errno.h>
#include <ctype.h>
+#include <termios.h>
#include <libintl.h>
#include <locale.h>
#define _(String) gettext(String)
@@ -2057,24 +2058,51 @@ static void copy_quotas(struct gfs2_sbd *sdp)
inode_put(&oq_ip);
}

+static char gfs2_getch(void)
+{
+ struct termios termattr, savetermattr;
+ char ch;
+ ssize_t size;
+
+ tcgetattr (STDIN_FILENO, &termattr);
+ savetermattr = termattr;
+ termattr.c_lflag &= ~(ICANON | IEXTEN | ISIG);
+ termattr.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ termattr.c_cflag &= ~(CSIZE | PARENB);
+ termattr.c_cflag |= CS8;
+ termattr.c_oflag &= ~(OPOST);
+ termattr.c_cc[VMIN] = 0;
+ termattr.c_cc[VTIME] = 0;
+
+ tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
+ do {
+ size = read(STDIN_FILENO, &ch, 1);
+ if (size)
+ break;
+ usleep(50000);
+ } while (!size);
+
+ tcsetattr (STDIN_FILENO, TCSANOW, &savetermattr);
+ return ch;
+}

static char generic_interrupt(const char *caller, const char *where,
const char *progress, const char *question,
const char *answers)
{
fd_set rfds;
- struct timeval tv;
+ struct timeval stv;
char response;
int err, i;

FD_ZERO(&rfds);
FD_SET(STDIN_FILENO, &rfds);

- tv.tv_sec = 0;
- tv.tv_usec = 0;
+ stv.tv_sec = 0;
+ stv.tv_usec = 0;
/* Make sure there isn't extraneous input before asking the
* user the question */
- while((err = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv))) {
+ while((err = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &stv))) {
if(err < 0) {
log_debug("Error in select() on stdin
");
break;
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index ddbc757..d912920 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <sys/time.h>
#include <stdio.h>
+#include <termios.h>
#include <libintl.h>
#include <ctype.h>
#define _(String) gettext(String)
@@ -87,6 +88,33 @@ void warm_fuzzy_stuff(uint64_t block)
}
}

+char gfs2_getch(void)
+{
+ struct termios termattr, savetermattr;
+ char ch;
+ ssize_t size;
+
+ tcgetattr (STDIN_FILENO, &termattr);
+ savetermattr = termattr;
+ termattr.c_lflag &= ~(ICANON | IEXTEN | ISIG);
+ termattr.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ termattr.c_cflag &= ~(CSIZE | PARENB);
+ termattr.c_cflag |= CS8;
+ termattr.c_oflag &= ~(OPOST);
+ termattr.c_cc[VMIN] = 0;
+ termattr.c_cc[VTIME] = 0;
+
+ tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
+ do {
+ size = read(STDIN_FILENO, &ch, 1);
+ if (size)
+ break;
+ usleep(50000);
+ } while (!size);
+
+ tcsetattr (STDIN_FILENO, TCSANOW, &savetermattr);
+ return ch;
+}

char generic_interrupt(const char *caller, const char *where,
const char *progress, const char *question,
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index 7c32404..6de61e2 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -183,5 +183,6 @@ extern int set_ip_blockmap(struct gfs2_inode *ip, int instree);
extern char generic_interrupt(const char *caller, const char *where,
const char *progress, const char *question,
const char *answers);
+extern char gfs2_getch(void);

#endif /* __UTIL_H__ */
diff --git a/gfs2/libgfs2/gfs2_log.c b/gfs2/libgfs2/gfs2_log.c
index 39b09c7..a1ceaeb 100644
--- a/gfs2/libgfs2/gfs2_log.c
+++ b/gfs2/libgfs2/gfs2_log.c
@@ -56,31 +56,3 @@ void print_fsck_log(int priority, const char *file, int line,
print_msg(priority, file, line, format, args);
va_end(args);
}
-
-char gfs2_getch(void)
-{
- struct termios termattr, savetermattr;
- char ch;
- ssize_t size;
-
- tcgetattr (STDIN_FILENO, &termattr);
- savetermattr = termattr;
- termattr.c_lflag &= ~(ICANON | IEXTEN | ISIG);
- termattr.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
- termattr.c_cflag &= ~(CSIZE | PARENB);
- termattr.c_cflag |= CS8;
- termattr.c_oflag &= ~(OPOST);
- termattr.c_cc[VMIN] = 0;
- termattr.c_cc[VTIME] = 0;
-
- tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
- do {
- size = read(STDIN_FILENO, &ch, 1);
- if (size)
- break;
- usleep(50000);
- } while (!size);
-
- tcsetattr (STDIN_FILENO, TCSANOW, &savetermattr);
- return ch;
-}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 80c84fa..d02d63e 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -656,7 +656,6 @@ extern int print_level;

#define stack log_debug("<backtrace> - %s()
", __func__)

-extern char gfs2_getch(void);
extern void increase_verbosity(void);
extern void decrease_verbosity(void);
extern void print_fsck_log(int priority, const char *file, int line,
--
1.7.4.4


All times are GMT. The time now is 03:47 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.