mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-20 13:42:14 +00:00
Enable SIGUSR1 stats to work without gui
This commit is contained in:
@@ -18,6 +18,8 @@ same as dwipe, with a few changes:
|
|||||||
- The parted library is used to detect drives
|
- The parted library is used to detect drives
|
||||||
.TP
|
.TP
|
||||||
- The code is designed to be compiled with gcc
|
- The code is designed to be compiled with gcc
|
||||||
|
.TP
|
||||||
|
- SIGUSR1 can be used to log the stats of the current wipe
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
@@ -41,6 +43,7 @@ Do not wait for a key before exiting (default is to wait).
|
|||||||
\fB\-\-nogui\fR
|
\fB\-\-nogui\fR
|
||||||
Do not show the GUI interface. Can only be used with the autonuke option.
|
Do not show the GUI interface. Can only be used with the autonuke option.
|
||||||
Nowait option is automatically invoked with the nogui option.
|
Nowait option is automatically invoked with the nogui option.
|
||||||
|
SIGUSR1 can be used to retrieve the current wiping statistics.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-verify\fR=\fITYPE\fR
|
\fB\-\-verify\fR=\fITYPE\fR
|
||||||
Whether to perform verification of erasure (default: last)
|
Whether to perform verification of erasure (default: last)
|
||||||
|
|||||||
@@ -123,9 +123,12 @@ typedef struct nwipe_context_t_
|
|||||||
/* Values cannot form part of the second array below, hence the need for this. */
|
/* Values cannot form part of the second array below, hence the need for this. */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int nwipe_enumerated; /* The number of devices available. */
|
int nwipe_enumerated; /* The number of devices available. */
|
||||||
int nwipe_selected; /* The number of devices being wiped. */
|
int nwipe_selected; /* The number of devices being wiped. */
|
||||||
pthread_t *gui_thread; /* The ID of GUI thread. */
|
time_t maxeta; /* The estimated runtime of the slowest device. */
|
||||||
|
u64 throughput; /* Total throughput */
|
||||||
|
u64 errors; /* The combined number of errors of all processes. */
|
||||||
|
pthread_t *gui_thread; /* The ID of GUI thread. */
|
||||||
} nwipe_misc_thread_data_t;
|
} nwipe_misc_thread_data_t;
|
||||||
|
|
||||||
/* The second points to the first structure, as well as the structure of all the devices */
|
/* The second points to the first structure, as well as the structure of all the devices */
|
||||||
|
|||||||
122
src/gui.c
122
src/gui.c
@@ -1659,13 +1659,13 @@ void *nwipe_gui_status( void *ptr )
|
|||||||
int keystroke;
|
int keystroke;
|
||||||
|
|
||||||
/* The combined througput of all processes. */
|
/* The combined througput of all processes. */
|
||||||
u64 nwipe_throughput = 0;
|
nwipe_misc_thread_data->throughput = 0;
|
||||||
|
|
||||||
/* The estimated runtime of the slowest device. */
|
/* The estimated runtime of the slowest device. */
|
||||||
time_t nwipe_maxeta = 0;
|
nwipe_misc_thread_data->maxeta = 0;
|
||||||
|
|
||||||
/* The combined number of errors of all processes. */
|
/* The combined number of errors of all processes. */
|
||||||
u64 nwipe_errors = 0;
|
nwipe_misc_thread_data->errors = 0;
|
||||||
|
|
||||||
/* Time values. */
|
/* Time values. */
|
||||||
int nwipe_hh;
|
int nwipe_hh;
|
||||||
@@ -1801,53 +1801,7 @@ void *nwipe_gui_status( void *ptr )
|
|||||||
if ( nwipe_gui_blank == 0 )
|
if ( nwipe_gui_blank == 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
nwipe_active = 0; // Number of active wipe threads
|
nwipe_active = compute_stats(ptr); // Returns number of active wipe threads
|
||||||
/* Enumerate all contexts to compute statistics. */
|
|
||||||
for( i = 0 ; i < count ; i++ )
|
|
||||||
{
|
|
||||||
/* Check whether the child process is still running the wipe. */
|
|
||||||
if( c[i]->thread > 0 )
|
|
||||||
{
|
|
||||||
/* Increment the child counter. */
|
|
||||||
nwipe_active += 1;
|
|
||||||
|
|
||||||
/* Maintain a rolling average of throughput. */
|
|
||||||
nwipe_update_speedring( &c[i]->speedring, c[i]->round_done, nwipe_time_now );
|
|
||||||
|
|
||||||
if( c[i]->speedring.timestotal > 0 )
|
|
||||||
{
|
|
||||||
/* Update the current average throughput in bytes-per-second. */
|
|
||||||
c[i]->throughput = c[i]->speedring.bytestotal / c[i]->speedring.timestotal;
|
|
||||||
|
|
||||||
/* Update the estimated remaining runtime. */
|
|
||||||
/* Check that throughput is not zero (sometimes caused during a sync) */
|
|
||||||
if (c[i]->throughput == 0)
|
|
||||||
{
|
|
||||||
c[i]->throughput = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
c[i]->eta = ( c[i]->round_size - c[i]->round_done ) / c[i]->throughput;
|
|
||||||
|
|
||||||
if( c[i]->eta > nwipe_maxeta )
|
|
||||||
{
|
|
||||||
nwipe_maxeta = c[i]->eta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the percentage value. */
|
|
||||||
c[i]->round_percent = (double) c[i]->round_done / (double) c[i]->round_size * 100;
|
|
||||||
|
|
||||||
/* Accumulate combined throughput. */
|
|
||||||
nwipe_throughput += c[i]->throughput;
|
|
||||||
|
|
||||||
} /* child running */
|
|
||||||
|
|
||||||
/* Accumulate the error count. */
|
|
||||||
nwipe_errors += c[i]->pass_errors;
|
|
||||||
nwipe_errors += c[i]->verify_errors;
|
|
||||||
|
|
||||||
} /* for statistics */
|
|
||||||
|
|
||||||
|
|
||||||
/* Print information for the user. */
|
/* Print information for the user. */
|
||||||
for( i = offset ; i < offset + slots && i < count ; i++ )
|
for( i = offset ; i < offset + slots && i < count ; i++ )
|
||||||
@@ -1949,6 +1903,7 @@ void *nwipe_gui_status( void *ptr )
|
|||||||
nwipe_gui_load();
|
nwipe_gui_load();
|
||||||
|
|
||||||
|
|
||||||
|
u64 nwipe_throughput = nwipe_misc_thread_data->throughput;
|
||||||
if( nwipe_throughput >= INT64_C( 1000000000000000 ) )
|
if( nwipe_throughput >= INT64_C( 1000000000000000 ) )
|
||||||
{ nwipe_throughput /= INT64_C( 1000000000000 ); nwipe_format = nwipe_tera; }
|
{ nwipe_throughput /= INT64_C( 1000000000000 ); nwipe_format = nwipe_tera; }
|
||||||
else if( nwipe_throughput >= INT64_C( 1000000000000 ) )
|
else if( nwipe_throughput >= INT64_C( 1000000000000 ) )
|
||||||
@@ -1984,6 +1939,7 @@ void *nwipe_gui_status( void *ptr )
|
|||||||
|
|
||||||
mvwprintw( stats_window, NWIPE_GUI_STATS_ETA_Y, 1, "Remaining:" );
|
mvwprintw( stats_window, NWIPE_GUI_STATS_ETA_Y, 1, "Remaining:" );
|
||||||
|
|
||||||
|
time_t nwipe_maxeta = nwipe_misc_thread_data->maxeta;
|
||||||
if( nwipe_maxeta > 0 )
|
if( nwipe_maxeta > 0 )
|
||||||
{
|
{
|
||||||
/* Do it again for the estimated runtime remaining. */
|
/* Do it again for the estimated runtime remaining. */
|
||||||
@@ -1999,7 +1955,7 @@ void *nwipe_gui_status( void *ptr )
|
|||||||
|
|
||||||
/* Print the error count. */
|
/* Print the error count. */
|
||||||
mvwprintw( stats_window, NWIPE_GUI_STATS_ERRORS_Y, NWIPE_GUI_STATS_ERRORS_X, "Errors:" );
|
mvwprintw( stats_window, NWIPE_GUI_STATS_ERRORS_Y, NWIPE_GUI_STATS_ERRORS_X, "Errors:" );
|
||||||
mvwprintw( stats_window, NWIPE_GUI_STATS_ERRORS_Y, NWIPE_GUI_STATS_TAB, "%llu", nwipe_errors );
|
mvwprintw( stats_window, NWIPE_GUI_STATS_ERRORS_Y, NWIPE_GUI_STATS_TAB, "%llu", nwipe_misc_thread_data->errors );
|
||||||
|
|
||||||
/* Add a border. */
|
/* Add a border. */
|
||||||
box( stats_window, 0, 0 );
|
box( stats_window, 0, 0 );
|
||||||
@@ -2059,6 +2015,70 @@ void *nwipe_gui_status( void *ptr )
|
|||||||
|
|
||||||
} /* nwipe_gui_status */
|
} /* nwipe_gui_status */
|
||||||
|
|
||||||
|
int compute_stats(void *ptr)
|
||||||
|
{
|
||||||
|
nwipe_thread_data_ptr_t *nwipe_thread_data_ptr;
|
||||||
|
nwipe_thread_data_ptr = (nwipe_thread_data_ptr_t *) ptr;
|
||||||
|
|
||||||
|
nwipe_context_t **c;
|
||||||
|
nwipe_misc_thread_data_t *nwipe_misc_thread_data;
|
||||||
|
|
||||||
|
c = nwipe_thread_data_ptr->c;
|
||||||
|
nwipe_misc_thread_data = nwipe_thread_data_ptr->nwipe_misc_thread_data;
|
||||||
|
int count = nwipe_misc_thread_data->nwipe_selected;
|
||||||
|
|
||||||
|
int nwipe_active = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
time_t nwipe_time_now = time( NULL );
|
||||||
|
|
||||||
|
/* Enumerate all contexts to compute statistics. */
|
||||||
|
for( i = 0 ; i < count ; i++ )
|
||||||
|
{
|
||||||
|
/* Check whether the child process is still running the wipe. */
|
||||||
|
if( c[i]->thread > 0 )
|
||||||
|
{
|
||||||
|
/* Increment the child counter. */
|
||||||
|
nwipe_active += 1;
|
||||||
|
|
||||||
|
/* Maintain a rolling average of throughput. */
|
||||||
|
nwipe_update_speedring( &c[i]->speedring, c[i]->round_done, nwipe_time_now );
|
||||||
|
|
||||||
|
if( c[i]->speedring.timestotal > 0 )
|
||||||
|
{
|
||||||
|
/* Update the current average throughput in bytes-per-second. */
|
||||||
|
c[i]->throughput = c[i]->speedring.bytestotal / c[i]->speedring.timestotal;
|
||||||
|
|
||||||
|
/* Update the estimated remaining runtime. */
|
||||||
|
/* Check that throughput is not zero (sometimes caused during a sync) */
|
||||||
|
if (c[i]->throughput == 0)
|
||||||
|
{
|
||||||
|
c[i]->throughput = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
c[i]->eta = ( c[i]->round_size - c[i]->round_done ) / c[i]->throughput;
|
||||||
|
|
||||||
|
if( c[i]->eta > nwipe_misc_thread_data->maxeta )
|
||||||
|
{
|
||||||
|
nwipe_misc_thread_data->maxeta = c[i]->eta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update the percentage value. */
|
||||||
|
c[i]->round_percent = (double) c[i]->round_done / (double) c[i]->round_size * 100;
|
||||||
|
|
||||||
|
/* Accumulate combined throughput. */
|
||||||
|
nwipe_misc_thread_data->throughput += c[i]->throughput;
|
||||||
|
} /* child running */
|
||||||
|
|
||||||
|
/* Accumulate the error count. */
|
||||||
|
nwipe_misc_thread_data->errors += c[i]->pass_errors;
|
||||||
|
nwipe_misc_thread_data->errors += c[i]->verify_errors;
|
||||||
|
|
||||||
|
} /* for statistics */
|
||||||
|
|
||||||
|
return nwipe_active;
|
||||||
|
}
|
||||||
|
|
||||||
void nwipe_update_speedring( nwipe_speedring_t* speedring, u64 speedring_bytes, time_t speedring_now )
|
void nwipe_update_speedring( nwipe_speedring_t* speedring, u64 speedring_bytes, time_t speedring_now )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ void nwipe_gui_rounds( void ); /* Change the rounds op
|
|||||||
void nwipe_gui_verify( void ); /* Change the verify option. */
|
void nwipe_gui_verify( void ); /* Change the verify option. */
|
||||||
void nwipe_gui_noblank( void ); /* Change the noblank option. */
|
void nwipe_gui_noblank( void ); /* Change the noblank option. */
|
||||||
|
|
||||||
|
int compute_stats(void *ptr);
|
||||||
void nwipe_update_speedring( nwipe_speedring_t* speedring, u64 speedring_done, time_t speedring_now );
|
void nwipe_update_speedring( nwipe_speedring_t* speedring, u64 speedring_done, time_t speedring_now );
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -520,6 +520,8 @@ void *signal_hand(void *ptr)
|
|||||||
// Log current status. All values are automatically updated by the GUI
|
// Log current status. All values are automatically updated by the GUI
|
||||||
case SIGUSR1 :
|
case SIGUSR1 :
|
||||||
{
|
{
|
||||||
|
compute_stats(ptr);
|
||||||
|
|
||||||
for( i = 0; i < nwipe_misc_thread_data->nwipe_selected; i++ )
|
for( i = 0; i < nwipe_misc_thread_data->nwipe_selected; i++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -568,7 +570,7 @@ void *signal_hand(void *ptr)
|
|||||||
case SIGTERM :
|
case SIGTERM :
|
||||||
{
|
{
|
||||||
|
|
||||||
for( i = 0; i < nwipe_misc_thread_data->nwipe_enumerated; i++ )
|
for( i = 0; i < nwipe_misc_thread_data->nwipe_selected; i++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( c[i]->thread )
|
if ( c[i]->thread )
|
||||||
@@ -596,7 +598,6 @@ void *signal_hand(void *ptr)
|
|||||||
printf("%s\n", log_lines[i]);
|
printf("%s\n", log_lines[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("Program interrupted (caught signal %d)\n", sig);
|
printf("Program interrupted (caught signal %d)\n", sig);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ display_help()
|
|||||||
puts(" --noblank Do not blank disk after wipe (default is to complete a final blank pass)" );
|
puts(" --noblank Do not blank disk after wipe (default is to complete a final blank pass)" );
|
||||||
puts(" --nowait Do not wait for a key before exiting (default is to wait)" );
|
puts(" --nowait Do not wait for a key before exiting (default is to wait)" );
|
||||||
puts(" --nogui Do not show the GUI interface. Automatically invokes the nowait option" );
|
puts(" --nogui Do not show the GUI interface. Automatically invokes the nowait option" );
|
||||||
puts(" Must be used with --autonuke option");
|
puts(" Must be used with --autonuke option. Send SIGUSR1 to log current stats");
|
||||||
puts("");
|
puts("");
|
||||||
exit( EXIT_SUCCESS );
|
exit( EXIT_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user