]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
mke2fs: add an option in mke2fs.conf to proceed after a delay
authorTheodore Ts'o <tytso@mit.edu>
Sat, 26 Apr 2014 21:34:52 +0000 (17:34 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 5 May 2014 02:20:35 +0000 (22:20 -0400)
If mke2fs needs to ask the user for permission, and the user doesn't
type anything the specified delay in the /etc/mke2fs.conf file,
proceed as if the user had said yes.  The default is to do what we
currently do, which is to wait until the user answers the question one
way or the other.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
misc/mke2fs.c
misc/mke2fs.conf.5.in
misc/tune2fs.c
misc/util.c
misc/util.h

index a2b1f6578fe09cf1976665447cf224f126cf808b..6b099e10ab2ce7740c92db49bf638262fe367397 100644 (file)
@@ -102,6 +102,7 @@ static __u32        fs_stride;
 static int     quotatype = -1;  /* Initialize both user and group quotas by default */
 static __u64   offset;
 static blk64_t journal_location = ~0LL;
+static int     proceed_delay = -1;
 
 static struct ext2_super_block fs_param;
 static char *fs_uuid = NULL;
@@ -1749,9 +1750,12 @@ profile_error:
        if (optind < argc)
                usage();
 
+       profile_get_integer(profile, "options", "proceed_delay", 0, 0,
+                           &proceed_delay);
+
        if (!check_plausibility(device_name, CREATE_FILE,
                                &is_device) && !force)
-               proceed_question();
+               proceed_question(proceed_delay);
 
        check_mount(device_name, force, _("filesystem"));
 
@@ -1797,7 +1801,7 @@ profile_error:
        } else if (!force && is_device && (fs_blocks_count > dev_size)) {
                com_err(program_name, 0, "%s",
                        _("Filesystem larger than apparent device size."));
-               proceed_question();
+               proceed_question(proceed_delay);
        }
 
        if (!fs_type)
@@ -2071,7 +2075,7 @@ profile_error:
                        com_err(program_name, 0,
                                _("%d-byte blocks too big for system (max %d)"),
                                blocksize, sys_page_size);
-                       proceed_question();
+                       proceed_question(proceed_delay);
                }
                fprintf(stderr, _("Warning: %d-byte blocks too big for system "
                                  "(max %d), forced to continue\n"),
@@ -2785,7 +2789,7 @@ int main (int argc, char *argv[])
 
                if (!check_plausibility(journal_device, CHECK_BLOCK_DEV,
                                        NULL) && !force)
-                       proceed_question();
+                       proceed_question(proceed_delay);
                check_mount(journal_device, force, _("journal"));
 
                retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
index 02efdce4bdbd822428d5d2c0b2d3ed0290100a1c..8e25892e0d87c9e3f692a68378e884fc99237d9c 100644 (file)
@@ -68,7 +68,10 @@ The following stanzas are used in the
 .I mke2fs.conf
 file.  They will be described in more detail in future sections of this
 document.
-.TP 
+.TP
+.I [options]
+Contains relations which influence how mke2fs behaves.
+.TP
 .I [defaults]
 Contains relations which define the default parameters
 used by
@@ -84,6 +87,18 @@ the
 .B -T
 option to
 .BR mke2fs (8).
+.SH THE [options] STANZA
+The following relations are defined in the
+.I [options]
+stanza.
+.TP
+.I proceed_delay
+If this relation is set to a positive integer, then if mke2fs will
+proceed after waiting
+.I proceed_delay
+seconds, after asking the user for permission to proceed, even if the
+user has not answered the question.  Defaults to 0, which means to wait
+until the user answers the question one way or another.
 .SH THE [defaults] STANZA
 The following relations are defined in the 
 .I [defaults]
index fbf5f524f2963bf4c10996dd3ad93524fe609419..7b3723b1e78983c35cf8d97a0fc5345cb939b80d 100644 (file)
@@ -675,7 +675,7 @@ static int add_journal(ext2_filsys fs)
        if (journal_device) {
                if (!check_plausibility(journal_device, CHECK_BLOCK_DEV,
                                        NULL))
-                       proceed_question();
+                       proceed_question(-1);
                check_mount(journal_device, 0, _("journal"));
 #ifdef CONFIG_TESTIO_DEBUG
                if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
index f85942e3ae9407d4f4a7e28e6e87bcbaab5ed854..afb0058c29fd0f132a934002da139735bbf2fd4d 100644 (file)
@@ -14,6 +14,8 @@
 
 #include "config.h"
 #include <fcntl.h>
+#include <setjmp.h>
+#include <signal.h>
 #include <stdio.h>
 #include <string.h>
 #ifdef HAVE_ERRNO_H
@@ -68,18 +70,39 @@ char *get_progname(char *argv_zero)
                return cp+1;
 }
 
-void proceed_question(void)
+static jmp_buf alarm_env;
+
+static void alarm_signal(int signal)
+{
+       longjmp(alarm_env, 1);
+}
+
+void proceed_question(int delay)
 {
        char buf[256];
        const char *short_yes = _("yY");
 
        fflush(stdout);
        fflush(stderr);
-       fputs(_("Proceed anyway? (y,n) "), stdout);
+       if (delay > 0) {
+               if (setjmp(alarm_env)) {
+                       signal(SIGALRM, SIG_IGN);
+                       printf(_("<proceeding>\n"));
+                       return;
+               }
+               signal(SIGALRM, alarm_signal);
+               printf(_("Proceed anyway (or wait %d seconds) ? (y,n) "),
+                      delay);
+               alarm(delay);
+       } else
+               fputs(_("Proceed anyway? (y,n) "), stdout);
        buf[0] = 0;
        if (!fgets(buf, sizeof(buf), stdin) ||
-           strchr(short_yes, buf[0]) == 0)
+           strchr(short_yes, buf[0]) == 0) {
+               putc('\n', stdout);
                exit(1);
+       }
+       signal(SIGALRM, SIG_IGN);
 }
 
 /*
index b80d4895b38ddb84d17dc841c67d9e58efa0127c..9de3fbf6166d7ce75d671ef945a8be92dcfbbed4 100644 (file)
@@ -25,7 +25,7 @@ extern char   *journal_location_string;
 extern int strcasecmp (char *s1, char *s2);
 #endif
 extern char *get_progname(char *argv_zero);
-extern void proceed_question(void);
+extern void proceed_question(int delay);
 extern int check_plausibility(const char *device, int flags,
                              int *ret_is_dev);
 extern void parse_journal_opts(const char *opts);