aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2010-12-04 21:02:03 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2010-12-04 21:02:03 -0500
commit8a8f1c9fc84a77a73c622b84b74d721d6cc6bebf (patch)
tree0f82649efabbff646dfbdc7b56e2cf428f7a4b32
parent2ccade436d8fe51eea6cb09e6324a921c243f332 (diff)
parent06885ad9fe9224812f9bdbd6891f921b05a54dbc (diff)
downloadNetNuke2-8a8f1c9fc84a77a73c622b84b74d721d6cc6bebf.tar.gz
Merge branch 'master' of git://github.com/jhunkeler/NetNuke
-rw-r--r--src/bus.c14
-rw-r--r--src/netnuke.c32
2 files changed, 34 insertions, 12 deletions
diff --git a/src/bus.c b/src/bus.c
index 1b96b25..eb1a862 100644
--- a/src/bus.c
+++ b/src/bus.c
@@ -149,8 +149,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);
}
@@ -173,19 +178,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++;
diff --git a/src/netnuke.c b/src/netnuke.c
index 682d727..2c521bb 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]));
@@ -235,8 +236,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");
@@ -244,11 +255,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++;
@@ -256,19 +269,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');
@@ -279,8 +295,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;
}