From: Steven Whitehouse <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 2/6] libgfs2: Move gfs2_getch into utils
Date: Wed, 30 Nov 2011 15:04:38 +0000 [thread overview]
Message-ID: <1322665482-28435-3-git-send-email-swhiteho@redhat.com> (raw)
In-Reply-To: <1322665482-28435-1-git-send-email-swhiteho@redhat.com>
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\n");
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()\n", __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
next prev parent reply other threads:[~2011-11-30 15:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-30 15:04 [Cluster-devel] libgfs2 cleanups Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 1/6] libgfs2: Move generic_interrupt() into utils Steven Whitehouse
2011-11-30 15:04 ` Steven Whitehouse [this message]
2011-11-30 15:04 ` [Cluster-devel] [PATCH 3/6] libgfs2: Prepare to remove log_xxx() macros from library Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 4/6] libgfs2: Move some debug messages out into mkfs/fsck Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 5/6] libgfs2: Clean up sb read/check functions Steven Whitehouse
2011-11-30 15:04 ` [Cluster-devel] [PATCH 6/6] libgfs2: Remove some more log_xxx calls Steven Whitehouse
2011-11-30 15:55 ` [Cluster-devel] libgfs2 cleanups Bob Peterson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1322665482-28435-3-git-send-email-swhiteho@redhat.com \
--to=swhiteho@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).