From db7be03cae038fe133e17c361e6ab43341361d9c Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 4 Dec 2010 12:33:41 -0500 Subject: fixed bad malloc added --help argument --- src/netnuke.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/netnuke.c b/src/netnuke.c index 973f8b7..27189e9 100644 --- a/src/netnuke.c +++ b/src/netnuke.c @@ -48,7 +48,7 @@ char** bus_flags = NULL; static struct option long_options[] = { - {"help", no_argument, 0, 0}, + {"help", no_argument, 0, 'h'}, {"verbose", no_argument, &verbose_flag, 1}, {"quiet", no_argument, &verbose_flag, 0}, {"list", no_argument, &list_flag, 1}, @@ -62,7 +62,8 @@ static struct option long_options[] = {NULL, 0, 0, 0} }; -static char* long_options_help[] = +/* The usage function will apply these strings */ +static const char* long_options_help[] = { "\tThis message", "More output", @@ -191,14 +192,14 @@ int main(int argc, char* argv[]) bus_flags = (char**)malloc(1024); while(tok !=NULL) { - bus_flags[i] = (char*)malloc(strlen(tok)); - strncpy(bus_flags[i], tok, strlen(tok)); + bus_flags[i] = (char*)malloc(strlen(tok)+1); + strncpy(bus_flags[i], tok, strlen(tok)+1); i++; tok = strtok(NULL, ","); } break; } - //case 'h': + case 'h': //case ':': case '?': usage(basename(argv[0])); @@ -234,8 +235,18 @@ int main(int argc, char* argv[]) int thread_count = 0; int i = 0; + /* Select the bus mask and scan for devices */ bus_mask = selectbus(bus_flags); scanbus(device, bus_mask); + + /* Run check to see if any devices were returned */ + if(device[0] == NULL) + { + COM(self, "No devices detected\n"); + exit(0); + } + + /* Tell the random generator to start */ nnrandinit(); COM(self, "Initializing mutex\n"); @@ -243,11 +254,13 @@ int main(int argc, char* argv[]) COM(self, "Generating threads\n"); + /* If the operator does wants to preserve the first device */ if(ignore_flag) { int first = 0; int last = 0; + /* Count how many devices we have */ while(device[i] != NULL) { i++; @@ -255,19 +268,22 @@ int main(int argc, char* argv[]) last = i - 1; COM(self, "IGNORING: %s\n", device[first]->path); + /* Replace the first device's array entry and then clear the original */ memmove(device[first], device[last], sizeof(nndevice_t)); memset(device[last], 0, sizeof(nndevice_t)); device[last] = NULL; } - + /* Start a single thread per device node*/ for( i = 0; device[i] != NULL ; i++ ) { thread[i] = (pthread_t)nnthread(device[i]); COM(self, "thread id: %ld\n", thread[i]); } + /* Catch up */ usleep(10000); + /* Using the original device count, set thread_count and join all threads */ thread_count = i; COM(self, "Joining %d thread%c\n", thread_count, (thread_count > 1 || thread_count < 1) ? 's' : '\b'); @@ -278,8 +294,10 @@ int main(int argc, char* argv[]) COM(self, "Destroying mutex\n"); pthread_mutex_destroy(&lock_global); - COM(self, "Total bytes written: %lu\n", total_written_bytes); + + /* Close urandom */ nnrandfree(); + return 0; } -- cgit From 06885ad9fe9224812f9bdbd6891f921b05a54dbc Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 4 Dec 2010 12:34:30 -0500 Subject: IDE now sets nndevice_t variables like scsi bus flags work again --- src/bus.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bus.c b/src/bus.c index 2515b0d..d136cb8 100644 --- a/src/bus.c +++ b/src/bus.c @@ -97,8 +97,13 @@ int scanbus(nndevice_t** device, int mask) if((ioctl(fd, BLKGETSIZE, &blocks)) == 0) { size = blocks * blocksize; - printf("%s ", entries.gl_pathv[j]); - printf("%lu %lu %.2f\n", blocks, size, (double)size / (1024 * 1024 * 1024)); + strncpy(device[j]->path, entries.gl_pathv[j], sizeof(device[j]->path)); + device[j]->blks = blocks; + device[j]->sz = size; + device[j]->blksz = 512; + + printf("%s ", device[j]->path); + printf("%llu %llu %.2f\n", device[j]->blks, device[j]->sz, (double)device[j]->sz / (1024 * 1024 * 1024)); } close(fd); } @@ -121,19 +126,18 @@ int selectbus(char** flags) return (mask = BUS_BOTH); } - mask = 0; while(flags[i] != NULL) { if(!strcmp(flags[i], "ide")) { mask |= BUS_IDE; - printf("IDE (0x%02X)\n", mask); + COM(self, "IDE (0x%02X)\n", mask); } if(!strcmp(flags[i], "scsi")) { mask |= BUS_SCSI; - printf("SCSI (0x%02X)\n", mask); + COM(self, "SCSI (0x%02X)\n", mask); } i++; -- cgit