Whamcloud - gitweb
badblocks: Print the currently tested block number when interrupted with ^C
authorTheodore Ts'o <tytso@mit.edu>
Mon, 29 Jun 2009 04:52:27 +0000 (00:52 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 29 Jun 2009 04:52:27 +0000 (00:52 -0400)
This can be useful for the user who wishes to restart the badblocks
program after interrupting it.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
misc/badblocks.c

index 6e9c939..3e7b336 100644 (file)
@@ -223,6 +223,9 @@ static void *terminate_addr = NULL;
 
 static void terminate_intr(int signo EXT2FS_ATTR((unused)))
 {
+       fprintf(stderr, "\n\nInterrupted at block %llu\n", 
+               (unsigned long long) currently_testing);
+       fflush(stderr);
        if (terminate_addr)
                longjmp(terminate_addr,1);
        exit(1);
@@ -434,6 +437,9 @@ static unsigned int test_ro (int dev, blk_t last_block,
        unsigned int bb_count = 0;
        errcode_t errcode;
 
+       /* set up abend handler */
+       capture_terminate(NULL);
+
        errcode = ext2fs_badblocks_list_iterate_begin(bb_list,&bb_iter);
        if (errcode) {
                com_err (program_name, errcode,
@@ -531,6 +537,8 @@ static unsigned int test_ro (int dev, blk_t last_block,
 
        ext2fs_badblocks_list_iterate_end(bb_iter);
 
+       uncapture_terminate();
+
        return bb_count;
 }
 
@@ -544,6 +552,9 @@ static unsigned int test_rw (int dev, blk_t last_block,
        int i, try, got, nr_pattern, pat_idx;
        unsigned int bb_count = 0;
 
+       /* set up abend handler */
+       capture_terminate(NULL);
+
        buffer = allocate_buffer(2 * blocks_at_once * block_size);
        read_buffer = buffer + blocks_at_once * block_size;