diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2010-12-09 23:01:29 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2010-12-09 23:01:29 -0500 |
commit | 4d123d9e3253a08166d0d1924b86d6b63336f0e9 (patch) | |
tree | 3fc68e484f9dd4c6ee781915b0fbf7c85c95a895 | |
parent | 8b5923e40557970824d2c7cdf7f181a87c9c424d (diff) | |
download | NetNuke2-4d123d9e3253a08166d0d1924b86d6b63336f0e9.tar.gz |
- curses.c spawns an ncurses enabled worker thread
- The meat of netnuke.c has been moved to curses.c
- COM prints via wprintw instead of fprintf
- Other craziness
-rw-r--r-- | include/netnuke.h | 6 | ||||
-rw-r--r-- | src/netnuke.c | 101 | ||||
-rw-r--r-- | src/output_redirect.c | 5 |
3 files changed, 18 insertions, 94 deletions
diff --git a/include/netnuke.h b/include/netnuke.h index d8b4547..dc78ef2 100644 --- a/include/netnuke.h +++ b/include/netnuke.h @@ -22,6 +22,7 @@ #define NETNUKE_H #include "config.h" +#include <ncurses.h> #define AUTHOR "Joseph Hunkeler" #define LICENSE "GPLv3" @@ -64,6 +65,11 @@ int scanbus(nndevice_t** device,int mask); void showbus(int mask); int selectbus(char** flags); void usage(const char* progname); +WINDOW *create_window(int height, int width, int starty, int startx); +void free_window(WINDOW* window); +void* main_window_worker(void* args); +void main_init(void); +void main_deinit(void); #endif //NETNUKE_H diff --git a/src/netnuke.c b/src/netnuke.c index 11f63b6..8c53e14 100644 --- a/src/netnuke.c +++ b/src/netnuke.c @@ -47,6 +47,7 @@ int bus_mask = 0; int device_timeout = 0; char** bus_flags = NULL; char** ignore_list = NULL; +nndevice_t** device; static struct option long_options[] = { @@ -150,7 +151,6 @@ int main(int argc, char* argv[]) { fprintf(stderr, "Failed to cleanup %s: %s\n", NNLOGFILE, strerror(errno)); } - COM(self, "Program start\n"); if(argc < 2) usage(basename(argv[0])); int c; @@ -173,10 +173,10 @@ int main(int argc, char* argv[]) blksz_override = atoi(optarg); if(blksz_override < 512) { - COM(self, "Block size must be a multiple of 512\n"); + fprintf(stderr, "Block size must be a multiple of 512\n"); exit(1); } - COM(self, "Forcing %d block size\n", blksz_override); + break; } case 's': @@ -186,7 +186,6 @@ int main(int argc, char* argv[]) case 't': { device_timeout = atoi(optarg); - COM(self, "%ds timeout set\n", device_timeout); break; } case 'i': @@ -232,96 +231,12 @@ int main(int argc, char* argv[]) putchar ('\n'); } - COM(self, "Safety is %s\n", safety_flag ? "OFF" : "ON"); - - nndevice_t** device; - device = (nndevice_t**)malloc(MAXTHREAD * sizeof(nndevice_t)); - if(device == NULL) - { - perror("device list"); - exit(1); - } - - if(list_flag) - { - bus_mask = selectbus(bus_flags); - scanbus_sysfs(device); - exit(0); - } - - pthread_t thread[MAXTHREAD]; - int thread_count = 0; - int i = 0; - - /* Select the bus mask and scan for devices */ - bus_mask = selectbus(bus_flags); - scanbus_sysfs(device); - - /* 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"); - pthread_mutex_init(&lock_global, NULL); - pthread_mutex_init(&lock_write, NULL); - COM(self, "Generating threads\n"); - - /* If the operator wants to preserve the first device */ - if(ignore_first_flag) - { - int first = 0; - int last = 0; - - /* Count how many devices we have */ - while(device[i] != NULL) - { - i++; - } - 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; - } - - if(ignore_flag) - { - ignore_device(ignore_list, device); - } - - /* 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: %8X %8X\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'); - - for( i = 0 ; i < thread_count ; i++) - { - pthread_join(thread[i], NULL); - } - - COM(self, "Destroying mutex\n"); - pthread_mutex_destroy(&lock_global); - pthread_mutex_destroy(&lock_write); - COM(self, "Total bytes written: %lu\n", total_written_bytes); + /* Initialize ncurses */ + initscr(); - /* Close urandom */ - nnrandfree(); + /* Initialize secondary main thread */ + main_init(); + endwin(); return 0; } diff --git a/src/output_redirect.c b/src/output_redirect.c index e296b33..8384270 100644 --- a/src/output_redirect.c +++ b/src/output_redirect.c @@ -42,6 +42,7 @@ int nnlogcleanup() int COM(const char* func, char *format, ...) { + extern WINDOW* main_window; struct tm *logtm; time_t logtime = time(NULL); char timestr[64]; @@ -75,7 +76,9 @@ int COM(const char* func, char *format, ...) else { snprintf(tmpstr, sizeof(tmpstr), "_%s_: %s", func, str); - fprintf(stdout, "%s", tmpstr); + //fprintf(stdout, "%s", tmpstr); + wprintw(main_window, "%s", tmpstr); + wrefresh(main_window); } free(str); |