First patch moving user interface code out of the library

Signed-off-by: Steven Whitehouse <[email protected]>
---
 gfs2/convert/gfs2_convert.c |   48 +++++++++++++++++++++++++++++++++++++++++++
 gfs2/fsck/util.c            |   48 +++++++++++++++++++++++++++++++++++++++++++
 gfs2/fsck/util.h            |    4 +++
 gfs2/libgfs2/gfs2_log.c     |   48 -------------------------------------------
 gfs2/libgfs2/libgfs2.h      |    3 --
 5 files changed, 100 insertions(+), 51 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 396e899..f79b4a4 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2057,6 +2057,54 @@ static void copy_quotas(struct gfs2_sbd *sdp)
        inode_put(&oq_ip);
 }
 
+
+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;
+       char response;
+       int err, i;
+
+       FD_ZERO(&rfds);
+       FD_SET(STDIN_FILENO, &rfds);
+
+       tv.tv_sec = 0;
+       tv.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))) {
+               if(err < 0) {
+                       log_debug("Error in select() on stdin\n");
+                       break;
+               }
+               if(read(STDIN_FILENO, &response, sizeof(char)) < 0) {
+                       log_debug("Error in read() on stdin\n");
+                       break;
+               }
+       }
+       while (TRUE) {
+               printf("\n%s interrupted during %s:  ", caller, where);
+               if (progress)
+                       printf("%s.\n", progress);
+               printf("%s", question);
+
+               /* Make sure query is printed out */
+               fflush(NULL);
+               response = gfs2_getch();
+               printf("\n");
+               fflush(NULL);
+               if (strchr(answers, response))
+                       break;
+               printf("Bad response, please type ");
+               for (i = 0; i < strlen(answers) - 1; i++)
+                       printf("'%c', ", answers[i]);
+               printf(" or '%c'.\n", answers[i]);
+       }
+       return response;
+}
+
 static int __attribute__((format(printf, 3, 4))) gfs2_query(int *setonabort,
                            struct gfs2_options *opts, const char *format, ...)
 {
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index 0d243e0..ddbc757 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -87,6 +87,54 @@ void warm_fuzzy_stuff(uint64_t block)
        }
 }
 
+
+char generic_interrupt(const char *caller, const char *where,
+                      const char *progress, const char *question,
+                      const char *answers)
+{
+       fd_set rfds;
+       struct timeval tv;
+       char response;
+       int err, i;
+
+       FD_ZERO(&rfds);
+       FD_SET(STDIN_FILENO, &rfds);
+
+       tv.tv_sec = 0;
+       tv.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))) {
+               if(err < 0) {
+                       log_debug("Error in select() on stdin\n");
+                       break;
+               }
+               if(read(STDIN_FILENO, &response, sizeof(char)) < 0) {
+                       log_debug("Error in read() on stdin\n");
+                       break;
+               }
+       }
+       while (TRUE) {
+               printf("\n%s interrupted during %s:  ", caller, where);
+               if (progress)
+                       printf("%s.\n", progress);
+               printf("%s", question);
+
+               /* Make sure query is printed out */
+               fflush(NULL);
+               response = gfs2_getch();
+               printf("\n");
+               fflush(NULL);
+               if (strchr(answers, response))
+                       break;
+               printf("Bad response, please type ");
+               for (i = 0; i < strlen(answers) - 1; i++)
+                       printf("'%c', ", answers[i]);
+               printf(" or '%c'.\n", answers[i]);
+       }
+       return response;
+}
+
 /* fsck_query: Same as gfs2_query except it adjusts errors_found and
    errors_corrected. */
 int fsck_query(const char *format, ...)
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index b56fe69..7c32404 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -180,4 +180,8 @@ extern void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct 
gfs2_bmap *il);
 extern int gfs2_blockmap_set(struct gfs2_bmap *il, uint64_t block,
                             enum gfs2_mark_block mark);
 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);
+
 #endif /* __UTIL_H__ */
diff --git a/gfs2/libgfs2/gfs2_log.c b/gfs2/libgfs2/gfs2_log.c
index aa5ca73..39b09c7 100644
--- a/gfs2/libgfs2/gfs2_log.c
+++ b/gfs2/libgfs2/gfs2_log.c
@@ -84,51 +84,3 @@ char gfs2_getch(void)
        tcsetattr (STDIN_FILENO, TCSANOW, &savetermattr);
        return ch;
 }
-
-char generic_interrupt(const char *caller, const char *where,
-                      const char *progress, const char *question,
-                      const char *answers)
-{
-       fd_set rfds;
-       struct timeval tv;
-       char response;
-       int err, i;
-
-       FD_ZERO(&rfds);
-       FD_SET(STDIN_FILENO, &rfds);
-
-       tv.tv_sec = 0;
-       tv.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))) {
-               if(err < 0) {
-                       log_debug("Error in select() on stdin\n");
-                       break;
-               }
-               if(read(STDIN_FILENO, &response, sizeof(char)) < 0) {
-                       log_debug("Error in read() on stdin\n");
-                       break;
-               }
-       }
-       while (TRUE) {
-               printf("\n%s interrupted during %s:  ", caller, where);
-               if (progress)
-                       printf("%s.\n", progress);
-               printf("%s", question);
-
-               /* Make sure query is printed out */
-               fflush(NULL);
-               response = gfs2_getch();
-               printf("\n");
-               fflush(NULL);
-               if (strchr(answers, response))
-                       break;
-               printf("Bad response, please type ");
-               for (i = 0; i < strlen(answers) - 1; i++)
-                       printf("'%c', ", answers[i]);
-               printf(" or '%c'.\n", answers[i]);
-       }
-       return response;
-}
-
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 95fd2b4..80c84fa 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -662,9 +662,6 @@ extern void decrease_verbosity(void);
 extern void print_fsck_log(int priority, const char *file, int line,
                           const char *format, ...)
        __attribute__((format(printf,4,5)));
-extern char generic_interrupt(const char *caller, const char *where,
-                             const char *progress, const char *question,
-                             const char *answers);
 /* misc.c */
 
 extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
-- 
1.7.4.4

Reply via email to