Add --autopoweroff option

Fix non working --nowait option.
Update version info to 0.29-release candidate
This commit is contained in:
PartialVolume
2020-03-11 23:44:11 +00:00
parent 50079a15f9
commit e33c1bb06d
9 changed files with 78 additions and 13 deletions

View File

@@ -1,6 +1,14 @@
RELEASE NOTES 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 v0.28
----------------------- -----------------------
- Fix premature exit when terminal resized on completion of wipes (Thanks PartialVolume) - Fix premature exit when terminal resized on completion of wipes (Thanks PartialVolume)

View File

@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
AC_PREREQ([2.64]) 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) AM_INIT_AUTOMAKE(foreign subdir-objects)
AC_OUTPUT(Makefile src/Makefile man/Makefile) AC_OUTPUT(Makefile src/Makefile man/Makefile)
AC_CONFIG_SRCDIR([src/nwipe.c]) AC_CONFIG_SRCDIR([src/nwipe.c])

View File

@@ -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 .SH NAME
nwipe \- securely erase disks nwipe \- securely erase disks
.SH SYNOPSIS .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 devices immediately. If devices have been specified, starts wiping only
those specified devices immediately. those specified devices immediately.
.TP .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 \fB\-\-sync\fR
Open devices in sync mode Open devices in sync mode
.TP .TP

View File

@@ -2317,7 +2317,7 @@ void* nwipe_gui_status( void* ptr )
case 0x0a: case 0x0a:
/* Check whether we have finished all wipes, if yes exit while loop if user pressed spacebar or /* 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 ) if( !nwipe_active || terminate_signal == 1 )
{ {
loop_control = 0; loop_control = 0;
@@ -2332,6 +2332,15 @@ void* nwipe_gui_status( void* ptr )
} }
} /* keystroke */ } /* 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. */ /* Update screen if not blanked. */
if( nwipe_gui_blank == 0 ) if( nwipe_gui_blank == 0 )

View File

@@ -19,6 +19,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
*/ */
#ifndef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#endif
#ifndef _POSIX_SOURCE #ifndef _POSIX_SOURCE
#define _POSIX_SOURCE #define _POSIX_SOURCE
#endif #endif
@@ -439,13 +443,9 @@ int main( int argc, char** argv )
sleep( 2 ); /* DO NOT REMOVE ! Stops the routine hogging CPU cycles */ 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" ); if( !nwipe_options.nowait && !nwipe_options.autopoweroff )
}
else
{
if( !nwipe_options.nowait )
{ {
do do
{ {
@@ -453,6 +453,7 @@ int main( int argc, char** argv )
} while( terminate_signal != 1 ); } while( terminate_signal != 1 );
} }
} }
nwipe_log( NWIPE_LOG_INFO, "Exit in progress" ); nwipe_log( NWIPE_LOG_INFO, "Exit in progress" );
/* Send a REQUEST for the wipe threads to be cancelled */ /* Send a REQUEST for the wipe threads to be cancelled */
@@ -534,6 +535,8 @@ int main( int argc, char** argv )
} }
cleanup(); cleanup();
check_for_autopoweroff();
/* Exit. */ /* Exit. */
return return_status; return return_status;
@@ -688,3 +691,21 @@ int cleanup()
return 0; 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 );
}
}

View File

@@ -25,6 +25,8 @@
/* Function prototypes */ /* Function prototypes */
int cleanup(); int cleanup();
void check_for_autopoweroff( void);
void* signal_hand( void* );
#ifndef _LARGEFILE64_SOURCE #ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE
@@ -111,6 +113,4 @@ typedef unsigned char u8;
/* This is required for ioctl FDFLUSH. */ /* This is required for ioctl FDFLUSH. */
#include <linux/fd.h> #include <linux/fd.h>
void* signal_hand( void* );
#endif /* NWIPE_H_ */ #endif /* NWIPE_H_ */

View File

@@ -59,6 +59,9 @@ int nwipe_options_parse( int argc, char** argv )
static struct option nwipe_options_long[] = { static struct option nwipe_options_long[] = {
/* Set when the user wants to wipe without a confirmation prompt. */ /* Set when the user wants to wipe without a confirmation prompt. */
{"autonuke", no_argument, 0, 0}, {"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. */ /* A GNU standard option. Corresponds to the 'h' short option. */
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
@@ -104,6 +107,7 @@ int nwipe_options_parse( int argc, char** argv )
/* Set default options. */ /* Set default options. */
nwipe_options.autonuke = 0; nwipe_options.autonuke = 0;
nwipe_options.autopoweroff = 0;
nwipe_options.method = &nwipe_dodshort; nwipe_options.method = &nwipe_dodshort;
nwipe_options.prng = &nwipe_twister; nwipe_options.prng = &nwipe_twister;
nwipe_options.rounds = 1; nwipe_options.rounds = 1;
@@ -142,6 +146,12 @@ int nwipe_options_parse( int argc, char** argv )
nwipe_options.autonuke = 1; nwipe_options.autonuke = 1;
break; break;
} }
if( strcmp( nwipe_options_long[i].name, "autopoweroff" ) == 0 )
{
nwipe_options.autopoweroff = 1;
break;
}
if( strcmp( nwipe_options_long[i].name, "noblank" ) == 0 ) 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 ); 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 ) if( nwipe_options.noblank )
{ {
@@ -440,6 +459,9 @@ void display_help()
puts( " starts wiping all devices immediately. If devices have" ); puts( " starts wiping all devices immediately. If devices have" );
puts( " been specified, starts wiping only those specified" ); puts( " been specified, starts wiping only those specified" );
puts( " devices immediately.\n" ); 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( " --sync=NUM Will perform a sync after NUM writes (default: 0)" );
puts( " 0 - fdatasync after the disk is completely written" ); puts( " 0 - fdatasync after the disk is completely written" );
puts( " 1 - fdatasync after every write" ); puts( " 1 - fdatasync after every write" );

View File

@@ -48,6 +48,7 @@ void display_help();
typedef struct typedef struct
{ {
int autonuke; // Do not prompt the user for confirmation when set. 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 noblank; // Do not perform a final blanking pass.
int nowait; // Do not wait for a final key before exiting. int nowait; // Do not wait for a final key before exiting.
int nosignals; // Do not allow signals to interrupt a wipe. int nosignals; // Do not allow signals to interrupt a wipe.

View File

@@ -4,7 +4,7 @@
* used by configure to dynamically assign those values * used by configure to dynamically assign those values
* to documentation files. * to documentation files.
*/ */
const char* version_string = "0.28"; const char* version_string = "0.29";
const char* program_name = "nwipe"; const char* program_name = "nwipe";
const char* author_name = "Martijn van Brummelen"; const char* author_name = "Martijn van Brummelen";
const char* email_address = "git@brumit.nl"; const char* email_address = "git@brumit.nl";
@@ -14,4 +14,4 @@ Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\
There is NO warranty; not even for MERCHANTABILITY or FITNESS\n\ There is NO warranty; not even for MERCHANTABILITY or FITNESS\n\
FOR A PARTICULAR PURPOSE.\n"; FOR A PARTICULAR PURPOSE.\n";
const char* banner = "nwipe 0.28"; const char* banner = "nwipe 0.29-release candidate";