aboutsummaryrefslogtreecommitdiff
path: root/src/netnuke.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2010-12-02 17:06:23 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2010-12-02 17:06:23 -0500
commitd8394383b8ab15653ed02b82996081c8fe07cbd8 (patch)
tree1dd3c8d8f2712b1c9658de3b4c3ff3cc61b76c65 /src/netnuke.c
parent44a70fa1ee939fd17e46b4ad13cc90414ae7f678 (diff)
downloadNetNuke2-d8394383b8ab15653ed02b82996081c8fe07cbd8.tar.gz
Added --list argument to display devices then exit.
Implemented --ignore-first (probably a little buggy). For now, write messages only appear with --verbose set. Removed a few debug messages.
Diffstat (limited to 'src/netnuke.c')
-rw-r--r--src/netnuke.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/netnuke.c b/src/netnuke.c
index 3920d7e..973f8b7 100644
--- a/src/netnuke.c
+++ b/src/netnuke.c
@@ -37,6 +37,8 @@ pthread_mutex_t lock_global = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t lock_write = PTHREAD_MUTEX_INITIALIZER;
extern unsigned long total_written_bytes;
unsigned int blksz_override = 0;
+int list_flag = 0;
+int ignore_flag = 0;
int safety_flag = 0;
int logging_flag = 0;
int verbose_flag = 0;
@@ -49,8 +51,9 @@ static struct option long_options[] =
{"help", no_argument, 0, 0},
{"verbose", no_argument, &verbose_flag, 1},
{"quiet", no_argument, &verbose_flag, 0},
+ {"list", no_argument, &list_flag, 1},
{"safety-off", no_argument, &safety_flag, 0},
- {"ignore-first", no_argument, 0, 'i'},
+ {"ignore-first", no_argument, &ignore_flag, 1},
{"logging", no_argument, &logging_flag, 1},
{"timeout", required_argument, 0, 't'},
{"scheme", required_argument, 0, 's'},
@@ -64,6 +67,7 @@ static char* long_options_help[] =
"\tThis message",
"More output",
"Suppress output",
+ "Print device list, then exit",
"Enable destructive write mode",
"Ignore first device",
"Log all output to netnuke.log",
@@ -147,7 +151,7 @@ int main(int argc, char* argv[])
int c;
int option_index = 0;
- while((c = getopt_long (argc, argv, "ib:s:d:t:", long_options, &option_index)) > 0)
+ while((c = getopt_long (argc, argv, "ib:s:d:t:", long_options, &option_index)) != -1)
{
switch (c)
{
@@ -194,11 +198,10 @@ int main(int argc, char* argv[])
}
break;
}
- case 'h':
- case ':':
+ //case 'h':
+ //case ':':
case '?':
usage(basename(argv[0]));
- break;
}
}
@@ -210,7 +213,7 @@ int main(int argc, char* argv[])
putchar ('\n');
}
- COM(self, "Safety is %s\n", safety_flag ? "ON" : "OFF");
+ COM(self, "Safety is %s\n", safety_flag ? "OFF" : "ON");
nndevice_t** device;
device = (nndevice_t**)malloc(MAXTHREAD * sizeof(nndevice_t));
@@ -219,9 +222,17 @@ int main(int argc, char* argv[])
perror("device list");
exit(1);
}
+
+ if(list_flag)
+ {
+ bus_mask = selectbus(bus_flags);
+ scanbus(device, bus_mask);
+ exit(0);
+ }
+
pthread_t thread[MAXTHREAD];
int thread_count = 0;
- int i;
+ int i = 0;
bus_mask = selectbus(bus_flags);
scanbus(device, bus_mask);
@@ -231,15 +242,36 @@ int main(int argc, char* argv[])
pthread_mutex_init(&lock_global, NULL);
COM(self, "Generating threads\n");
- for( i = 0 ; device[i] != NULL ; i++ )
+
+ if(ignore_flag)
+ {
+ int first = 0;
+ int last = 0;
+
+ while(device[i] != NULL)
+ {
+ i++;
+ }
+ last = i - 1;
+
+ COM(self, "IGNORING: %s\n", device[first]->path);
+ memmove(device[first], device[last], sizeof(nndevice_t));
+ memset(device[last], 0, sizeof(nndevice_t));
+ device[last] = NULL;
+ }
+
+
+ for( i = 0; device[i] != NULL ; i++ )
{
thread[i] = (pthread_t)nnthread(device[i]);
COM(self, "thread id: %ld\n", thread[i]);
}
+ usleep(10000);
thread_count = i;
COM(self, "Joining %d thread%c\n", thread_count, (thread_count > 1 || thread_count < 1) ? 's' : '\b');
- for( i = 0 ; i < thread_count ; i++ )
+
+ for( i = 0 ; i < thread_count ; i++)
{
pthread_join(thread[i], NULL);
}