new package: nwipe

This commit is contained in:
Tee KOBAYASHI 2022-12-01 07:03:22 +09:00 committed by xtkoba
parent 2fd5ef382e
commit a7d1b21733
5 changed files with 226 additions and 0 deletions

12
packages/nwipe/build.sh Normal file
View File

@ -0,0 +1,12 @@
TERMUX_PKG_HOMEPAGE=https://github.com/martijnvanbrummelen/nwipe
TERMUX_PKG_DESCRIPTION="A program that will securely erase the entire contents of disks"
TERMUX_PKG_LICENSE="GPL-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=0.34
TERMUX_PKG_SRCURL=https://github.com/martijnvanbrummelen/nwipe/archive/refs/tags/v${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=be3122fcd8a6c8099ee1ae37dd640848774fdb84a7045a7b33dcf54c1ec69c29
TERMUX_PKG_DEPENDS="ncurses, ncurses-ui-libs, parted"
termux_step_pre_configure() {
autoreconf -fi
}

View File

@ -0,0 +1,10 @@
--- a/configure.ac
+++ b/configure.ac
@@ -52,7 +52,6 @@
AC_CHECK_LIB([intl], [libintl_dgettext]) # needed to statically link libparted, but not given in its pkgconfig file
AC_CHECK_LIB([uuid], [uuid_generate]) # needed to statically link libparted, but not given in its pkgconfig file
PKG_CHECK_MODULES([PARTED], [libparted])
-AC_CHECK_LIB([pthread], [main], ,[AC_MSG_ERROR([pthread development library not found])])
# Checks for header files.
AC_CHECK_HEADERS([fcntl.h inttypes.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/file.h sys/ioctl.h unistd.h])

View File

@ -0,0 +1,104 @@
--- a/src/device.c
+++ b/src/device.c
@@ -448,11 +448,11 @@
int idx2;
char readlink_command[] = "readlink /sys/block/%s";
- char readlink_command2[] = "/usr/bin/readlink /sys/block/%s";
- char readlink_command3[] = "/sbin/readlink /sys/block/%s";
+ char readlink_command2[] = "@TERMUX_PREFIX@/bin/readlink /sys/block/%s";
+ char readlink_command3[] = "@TERMUX_PREFIX@/local/bin/readlink /sys/block/%s";
char smartctl_command[] = "smartctl -i %s";
- char smartctl_command2[] = "/sbin/smartctl -i %s";
- char smartctl_command3[] = "/usr/bin/smartctl -i %s";
+ char smartctl_command2[] = "@TERMUX_PREFIX@/local/bin/smartctl -i %s";
+ char smartctl_command3[] = "@TERMUX_PREFIX@/bin/smartctl -i %s";
char device_shortform[50];
char result[512];
char final_cmd_readlink[sizeof( readlink_command ) + sizeof( device_shortform )];
@@ -499,11 +499,11 @@
/* Determine whether we can access readlink, required if the PATH environment is not setup ! (Debian sid 'su' as
* opposed to 'su -' */
- if( system( "which readlink > /dev/null 2>&1" ) )
+ if( system( "command -v readlink > /dev/null 2>&1" ) )
{
- if( system( "which /sbin/readlink > /dev/null 2>&1" ) )
+ if( system( "command -v @TERMUX_PREFIX@/local/bin/readlink > /dev/null 2>&1" ) )
{
- if( system( "which /usr/bin/readlink > /dev/null 2>&1" ) )
+ if( system( "command -v @TERMUX_PREFIX@/bin/readlink > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install readlink !" );
set_return_value = 2;
@@ -620,11 +620,11 @@
/* Determine whether we can access smartctl, required if the PATH environment is not setup ! (Debian sid 'su' as
* opposed to 'su -' */
- if( system( "which smartctl > /dev/null 2>&1" ) )
+ if( system( "command -v smartctl > /dev/null 2>&1" ) )
{
- if( system( "which /sbin/smartctl > /dev/null 2>&1" ) )
+ if( system( "command -v @TERMUX_PREFIX@/local/bin/smartctl > /dev/null 2>&1" ) )
{
- if( system( "which /usr/bin/smartctl > /dev/null 2>&1" ) )
+ if( system( "command -v @TERMUX_PREFIX@/bin/smartctl > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
}
--- a/src/logging.c
+++ b/src/logging.c
@@ -541,8 +541,8 @@
};
char dmidecode_command[] = "dmidecode -s %s";
- char dmidecode_command2[] = "/sbin/dmidecode -s %s";
- char dmidecode_command3[] = "/usr/bin/dmidecode -s %s";
+ char dmidecode_command2[] = "@TERMUX_PREFIX@/local/bin/dmidecode -s %s";
+ char dmidecode_command3[] = "@TERMUX_PREFIX@/bin/dmidecode -s %s";
char* p_dmidecode_command;
char cmd[sizeof( dmidecode_keywords ) + sizeof( dmidecode_command2 )];
@@ -553,11 +553,11 @@
p_dmidecode_command = 0;
- if( system( "which dmidecode > /dev/null 2>&1" ) )
+ if( system( "command -v dmidecode > /dev/null 2>&1" ) )
{
- if( system( "which /sbin/dmidecode > /dev/null 2>&1" ) )
+ if( system( "command -v @TERMUX_PREFIX@/local/bin/dmidecode > /dev/null 2>&1" ) )
{
- if( system( "which /usr/bin/dmidecode > /dev/null 2>&1" ) )
+ if( system( "command -v @TERMUX_PREFIX@/bin/dmidecode > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install dmidecode !" );
}
--- a/src/nwipe.c
+++ b/src/nwipe.c
@@ -67,8 +67,8 @@
pthread_t nwipe_sigint_thread; // The thread ID of the sigint handler.
char modprobe_command[] = "modprobe %s";
- char modprobe_command2[] = "/sbin/modprobe %s";
- char modprobe_command3[] = "/usr/sbin/modprobe %s";
+ char modprobe_command2[] = "@TERMUX_PREFIX@/local/bin/modprobe %s";
+ char modprobe_command3[] = "@TERMUX_PREFIX@/bin/modprobe %s";
char module_shortform[50];
char final_cmd_modprobe[sizeof( modprobe_command ) + sizeof( module_shortform )];
@@ -227,11 +227,11 @@
/* Determine whether we can access modprobe, required if the PATH environment is not setup ! (Debian sid 'su' as
* opposed to 'su -' */
- if( system( "which modprobe > /dev/null 2>&1" ) )
+ if( system( "command -v modprobe > /dev/null 2>&1" ) )
{
- if( system( "which /sbin/modprobe > /dev/null 2>&1" ) )
+ if( system( "command -v @TERMUX_PREFIX@/local/bin/modprobe > /dev/null 2>&1" ) )
{
- if( system( "which /usr/sbin/modprobe > /dev/null 2>&1" ) )
+ if( system( "command -v @TERMUX_PREFIX@/bin/modprobe > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "modprobe command not found. Install kmod package (modprobe)) !" );
nwipe_log( NWIPE_LOG_WARNING, "Most temperature monitoring may be unavailable as module drivetemp" );

View File

@ -0,0 +1,89 @@
--- a/src/context.h
+++ b/src/context.h
@@ -127,6 +127,7 @@
nwipe_speedring_t speedring; // Ring buffer for computing the rolling throughput average.
short sync_status; // A flag to indicate when the method is syncing.
pthread_t thread; // The ID of the thread.
+ atomic_flag thread_cancel; // The cancelation flag of the thread.
u64 throughput; // Average throughput in bytes per second.
u64 verify_errors; // The number of verification errors across all passes.
char temp1_path[MAX_HWMON_PATH_LENGTH]; // path to temperature variables /sys/class/hwmon/hwmonX/ etc.
--- a/src/nwipe.c
+++ b/src/nwipe.c
@@ -516,6 +516,7 @@
}
/* Fork a child process. */
+ atomic_flag_test_and_set( &c2[i]->thread_cancel );
errno = pthread_create( &c2[i]->thread, NULL, nwipe_options.method, (void*) c2[i] );
if( errno )
{
@@ -597,7 +598,7 @@
{
nwipe_log( NWIPE_LOG_INFO, "Requesting wipe thread cancellation for %s", c2[i]->device_name );
}
- pthread_cancel( c2[i]->thread );
+ atomic_flag_clear( &c2[i]->thread_cancel );
}
}
--- a/src/nwipe.h
+++ b/src/nwipe.h
@@ -111,4 +111,7 @@
/* This is required for ioctl FDFLUSH. */
#include <linux/fd.h>
+/* This is required for pthread_cancel() substitution. */
+#include <stdatomic.h>
+
#endif /* NWIPE_H_ */
--- a/src/pass.c
+++ b/src/pass.c
@@ -208,7 +208,10 @@
c->pass_done += r;
c->round_done += r;
- pthread_testcancel();
+ if ( !atomic_flag_test_and_set( &c->thread_cancel ) )
+ {
+ pthread_exit( NULL );
+ }
} /* while bytes remaining */
@@ -416,7 +419,10 @@
}
}
- pthread_testcancel();
+ if ( !atomic_flag_test_and_set( &c->thread_cancel ) )
+ {
+ pthread_exit( NULL );
+ }
} /* remaining bytes */
@@ -637,7 +643,10 @@
c->pass_done += r;
c->round_done += r;
- pthread_testcancel();
+ if ( !atomic_flag_test_and_set( &c->thread_cancel ) )
+ {
+ pthread_exit( NULL );
+ }
} /* while bytes remaining */
@@ -836,7 +845,10 @@
}
}
- pthread_testcancel();
+ if ( !atomic_flag_test_and_set( &c->thread_cancel ) )
+ {
+ pthread_exit( NULL );
+ }
} /* remaining bytes */

View File

@ -0,0 +1,11 @@
--- a/src/nwipe.c
+++ b/src/nwipe.c
@@ -44,7 +44,7 @@
#include "temperature.h"
#include <sys/ioctl.h> /* FIXME: Twice Included */
-#include <sys/shm.h>
+#include <linux/shm.h>
#include <wait.h>
#include <parted/parted.h>