diff --git a/CHANGELOG.md b/CHANGELOG.md index 680db72..5ce6047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ RELEASE NOTES ============= +v0.29-pre-release (Pending release May/Jun 2020) +----------------------- +Features/fixes in 0.29 that have been committed to the master are tagged with [DONE], +other items in 0.29 are proposed and yet to be implemented. +- [DONE] Add auto power off option on completion of wipe ( --autopoweroff ) (Thanks PartialVolume) +- [DONE] Fix --nowait option the wasn't working. + + v0.28 ----------------------- - Fix premature exit when terminal resized on completion of wipes (Thanks PartialVolume) diff --git a/configure.ac b/configure.ac index 35be56f..6e52cb5 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.64]) -AC_INIT([nwipe], [0.28], [git@brumit.nl]) +AC_INIT([nwipe], [0.29], [git@brumit.nl]) AM_INIT_AUTOMAKE(foreign subdir-objects) AC_OUTPUT(Makefile src/Makefile man/Makefile) AC_CONFIG_SRCDIR([src/nwipe.c]) diff --git a/man/nwipe.1 b/man/nwipe.1 index ac4be97..52c29ac 100644 --- a/man/nwipe.1 +++ b/man/nwipe.1 @@ -1,4 +1,4 @@ -.TH NWIPE "1" "March 2020" "nwipe version 0.28" "User Commands" +.TH NWIPE "1" "March 2020" "nwipe version 0.29" "User Commands" .SH NAME nwipe \- securely erase disks .SH SYNOPSIS @@ -34,6 +34,10 @@ If no devices have been specified on the command line, starts wiping all devices immediately. If devices have been specified, starts wiping only those specified devices immediately. .TP +\fB\-\-autopoweroff\fR +Power off system on completion of wipe delayed for for one minute. During +this one minute delay you can abort the shutdown by typing sudo shutdown -c +.TP \fB\-\-sync\fR Open devices in sync mode .TP diff --git a/src/gui.c b/src/gui.c index 4d49fab..e5258ad 100644 --- a/src/gui.c +++ b/src/gui.c @@ -2317,7 +2317,7 @@ void* nwipe_gui_status( void* ptr ) case 0x0a: /* Check whether we have finished all wipes, if yes exit while loop if user pressed spacebar or - * return */ + * return. */ if( !nwipe_active || terminate_signal == 1 ) { loop_control = 0; @@ -2332,6 +2332,15 @@ void* nwipe_gui_status( void* ptr ) } } /* keystroke */ + + /* if wipe has completed and user has specified auto poweroff or nowait then we can skip waiting for the user to press return */ + if( !nwipe_active ) + { + if( nwipe_options.autopoweroff || nwipe_options.nowait ) + { + loop_control = 0; + } + } /* Update screen if not blanked. */ if( nwipe_gui_blank == 0 ) diff --git a/src/nwipe.c b/src/nwipe.c index bd28649..66583af 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -19,6 +19,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif + #ifndef _POSIX_SOURCE #define _POSIX_SOURCE #endif @@ -439,13 +443,9 @@ int main( int argc, char** argv ) sleep( 2 ); /* DO NOT REMOVE ! Stops the routine hogging CPU cycles */ } - if( terminate_signal == 1 ) + if( terminate_signal != 1 ) { - nwipe_log( NWIPE_LOG_INFO, "Program interrupted" ); - } - else - { - if( !nwipe_options.nowait ) + if( !nwipe_options.nowait && !nwipe_options.autopoweroff ) { do { @@ -453,6 +453,7 @@ int main( int argc, char** argv ) } while( terminate_signal != 1 ); } } + nwipe_log( NWIPE_LOG_INFO, "Exit in progress" ); /* Send a REQUEST for the wipe threads to be cancelled */ @@ -534,6 +535,8 @@ int main( int argc, char** argv ) } cleanup(); + + check_for_autopoweroff(); /* Exit. */ return return_status; @@ -688,3 +691,21 @@ int cleanup() return 0; } +void check_for_autopoweroff( void ) +{ + char cmd[]="shutdown -P +1 \"System going down in one minute\""; + FILE* fp; + int r; // A result buffer. + + /* User request auto power down ? */ + if( nwipe_options.autopoweroff == 1 ) + { + fp = popen( cmd, "r" ); + if( fp == NULL ) + { + nwipe_log( NWIPE_LOG_INFO, "Failed to autopoweroff to %s", cmd ); + return; + } + r = pclose( fp ); + } +} diff --git a/src/nwipe.h b/src/nwipe.h index 9722d2d..d99505b 100644 --- a/src/nwipe.h +++ b/src/nwipe.h @@ -25,6 +25,8 @@ /* Function prototypes */ int cleanup(); +void check_for_autopoweroff( void); +void* signal_hand( void* ); #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE @@ -111,6 +113,4 @@ typedef unsigned char u8; /* This is required for ioctl FDFLUSH. */ #include -void* signal_hand( void* ); - #endif /* NWIPE_H_ */ diff --git a/src/options.c b/src/options.c index 38f1732..698e463 100644 --- a/src/options.c +++ b/src/options.c @@ -59,6 +59,9 @@ int nwipe_options_parse( int argc, char** argv ) static struct option nwipe_options_long[] = { /* Set when the user wants to wipe without a confirmation prompt. */ {"autonuke", no_argument, 0, 0}, + + /* Set when the user wants to have the system powerdown on completion of wipe. */ + {"autopoweroff", no_argument, 0, 0}, /* A GNU standard option. Corresponds to the 'h' short option. */ {"help", no_argument, 0, 'h'}, @@ -104,6 +107,7 @@ int nwipe_options_parse( int argc, char** argv ) /* Set default options. */ nwipe_options.autonuke = 0; + nwipe_options.autopoweroff = 0; nwipe_options.method = &nwipe_dodshort; nwipe_options.prng = &nwipe_twister; nwipe_options.rounds = 1; @@ -142,6 +146,12 @@ int nwipe_options_parse( int argc, char** argv ) nwipe_options.autonuke = 1; break; } + + if( strcmp( nwipe_options_long[i].name, "autopoweroff" ) == 0 ) + { + nwipe_options.autopoweroff = 1; + break; + } if( strcmp( nwipe_options_long[i].name, "noblank" ) == 0 ) { @@ -378,6 +388,15 @@ void nwipe_options_log( void ) { nwipe_log( NWIPE_LOG_NOTICE, " autonuke = %i (off)", nwipe_options.autonuke ); } + + if( nwipe_options.autopoweroff ) + { + nwipe_log( NWIPE_LOG_NOTICE, " autopoweroff = %i (on)", nwipe_options.autopoweroff ); + } + else + { + nwipe_log( NWIPE_LOG_NOTICE, " autopoweroff = %i (off)", nwipe_options.autopoweroff ); + } if( nwipe_options.noblank ) { @@ -440,6 +459,9 @@ void display_help() puts( " starts wiping all devices immediately. If devices have" ); puts( " been specified, starts wiping only those specified" ); puts( " devices immediately.\n" ); + puts( " --autopoweroff Power off system on completion of wipe delayed for" ); + puts( " for one minute. During this one minute delay you can" ); + puts( " abort the shutdown by typing sudo shutdown -c\n" ); puts( " --sync=NUM Will perform a sync after NUM writes (default: 0)" ); puts( " 0 - fdatasync after the disk is completely written" ); puts( " 1 - fdatasync after every write" ); diff --git a/src/options.h b/src/options.h index 06629b3..90c2c82 100644 --- a/src/options.h +++ b/src/options.h @@ -48,6 +48,7 @@ void display_help(); typedef struct { int autonuke; // Do not prompt the user for confirmation when set. + int autopoweroff; // Power off on completion of wipe int noblank; // Do not perform a final blanking pass. int nowait; // Do not wait for a final key before exiting. int nosignals; // Do not allow signals to interrupt a wipe. diff --git a/src/version.c b/src/version.c index f4d5468..92fe05d 100644 --- a/src/version.c +++ b/src/version.c @@ -4,7 +4,7 @@ * used by configure to dynamically assign those values * to documentation files. */ -const char* version_string = "0.28"; +const char* version_string = "0.29"; const char* program_name = "nwipe"; const char* author_name = "Martijn van Brummelen"; const char* email_address = "git@brumit.nl"; @@ -14,4 +14,4 @@ Modifications to original dwipe Copyright Andy Beverley \n\ This is free software; see the source for copying conditions.\n\ There is NO warranty; not even for MERCHANTABILITY or FITNESS\n\ FOR A PARTICULAR PURPOSE.\n"; -const char* banner = "nwipe 0.28"; +const char* banner = "nwipe 0.29-release candidate";