Merge pull request #297 from PartialVolume/add_nwipe_version_and_OS_info_to_log

This commit adds nwipes banner version number and OS info derived from /proc/version to the nwipe log. This information may be useful when a user has an issue and submits a log file.
This commit is contained in:
PartialVolume
2020-12-05 00:43:17 +00:00
committed by GitHub
3 changed files with 95 additions and 1 deletions

View File

@@ -404,6 +404,88 @@ void nwipe_perror( int nwipe_errno, const char* f, const char* s )
} /* nwipe_perror */
void nwipe_log_OSinfo()
{
/* Read /proc/version, format and write to the log */
FILE* fp = NULL;
char OS_info_temp[MAX_SIZE_OS_STRING + 1];
char OS_info[MAX_SIZE_OS_STRING + 1];
int idx;
int idx2;
int idx3;
int idx4;
/* initialise OS_info & OS_info_temp strings */
idx = 0;
while( idx < MAX_SIZE_OS_STRING + 1 )
{
OS_info_temp[idx] = 0;
OS_info[idx] = 0;
idx++;
}
/* Open a pipe to /proc/version for reading */
fp = popen( "cat /proc/version", "r" );
if( fp == NULL )
{
nwipe_log( NWIPE_LOG_WARNING, "Unable to create a pipe to /proc/version" );
return;
}
/* Read the OS info */
if( fgets( OS_info_temp, MAX_SIZE_OS_STRING, fp ) == NULL )
{
nwipe_log( NWIPE_LOG_WARNING, "fget failed to read /proc/version" );
fclose( fp );
return;
}
/* Format the string for the log, place on multiple lines as necessary,
* column aligned, left offset with n (OS_info_Line_offset) spaces */
idx = 0;
idx2 = 0;
idx3 = OS_info_Line_Length;
while( OS_info_temp[idx] != 0 )
{
while( idx2 < idx3 && idx2 < MAX_SIZE_OS_STRING )
{
/* remove newlines from the source */
if( OS_info_temp[idx] == 0x0a )
{
idx++;
}
/* copy the character */
OS_info[idx2++] = OS_info_temp[idx++];
}
if( OS_info_temp[idx] != 0 )
{
OS_info[idx2++] = 0x0a;
idx4 = 0;
/* left indent with spaces */
while( idx4 < OS_info_Line_offset && idx2 < MAX_SIZE_OS_STRING )
{
OS_info[idx2++] = ' ';
idx4++;
}
/* calculate idx3 ready for next line */
idx3 += OS_info_Line_offset + OS_info_Line_Length;
}
else
{
continue;
}
}
nwipe_log( NWIPE_LOG_INFO, "%s", OS_info );
fclose( fp );
return;
}
int nwipe_log_sysinfo()
{
FILE* fp;

View File

@@ -24,6 +24,10 @@
/* Maximum size of a log message */
#define MAX_LOG_LINE_CHARS 512
#define MAX_SIZE_OS_STRING 512 /* Maximum size of acceptable OS string */
#define OS_info_Line_offset 31 /* OS_info line offset in log */
#define OS_info_Line_Length 48 /* OS_info line length */
typedef enum nwipe_log_t_ {
NWIPE_LOG_NONE = 0,
NWIPE_LOG_DEBUG, // TODO: Very verbose logging.
@@ -38,6 +42,7 @@ typedef enum nwipe_log_t_ {
void nwipe_log( nwipe_log_t level, const char* format, ... );
void nwipe_perror( int nwipe_errno, const char* f, const char* s );
void nwipe_log_OSinfo();
int nwipe_log_sysinfo();
void nwipe_log_summary( nwipe_context_t**, int ); // This produces the wipe status table on exit
void Determine_C_B_nomenclature( u64, char*, int );

View File

@@ -49,6 +49,7 @@
#include <parted/parted.h>
#include <parted/debug.h>
#include "version.h"
int terminate_signal;
int user_abort;
@@ -72,6 +73,12 @@ int main( int argc, char** argv )
/* The generic result buffer. */
int r;
/* Log nwipes version */
nwipe_log( NWIPE_LOG_INFO, "%s", banner );
/* Log OS info */
nwipe_log_OSinfo();
/* Initialise the termintaion signal, 1=terminate nwipe */
terminate_signal = 0;
@@ -119,7 +126,7 @@ int main( int argc, char** argv )
if( nwipe_enumerated == 0 )
{
nwipe_log( NWIPE_LOG_ERROR, "Devices not found. Check you're not excluding drives unnecessarily." );
printf( "No drives found" );
printf( "No drives found\n" );
cleanup();
exit( 1 );
}