Skip to content

Commit 170a1a3

Browse files
Update exploithawk.c
1 parent 8150d0d commit 170a1a3

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

exploithawk.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#define MAX_TITLE 512
1818
#define MAX_SOURCE 32
1919
#define TITLE_WRAP 50 // preferred width for title column
20+
#define MAX_THREADS 64
21+
#define MAX_THREADS (int)(sizeof(threads)/sizeof(threads[0]))
2022

2123
typedef struct {
2224
char source[MAX_SOURCE];
@@ -344,17 +346,35 @@ int main(int argc, char *argv[]) {
344346
int num_threads = 0;
345347
pthread_t threads[64];
346348

347-
// CSV threads
348-
for (int i = 0; i < (int)(sizeof(exploitDBPaths)/sizeof(exploitDBPaths[0])); i++)
349-
pthread_create(&threads[num_threads++], NULL, load_csv_thread, (void*)exploitDBPaths[i]);
350-
351-
// Directory threads
352-
for (int i = 0; i < (int)(sizeof(exploitDirs)/sizeof(exploitDirs[0])); i++)
353-
pthread_create(&threads[num_threads++], NULL, scan_dir_thread, (void*)exploitDirs[i]);
354-
355-
// Join all threads
356-
for (int i = 0; i < num_threads; i++)
357-
pthread_join(threads[i], NULL);
349+
// CSV threads
350+
for (int i = 0; i < (int)(sizeof(exploitDBPaths)/sizeof(exploitDBPaths[0])); i++) {
351+
if (num_threads >= MAX_THREADS) break;
352+
int rc = pthread_create(&threads[num_threads], NULL, load_csv_thread, (void*)exploitDBPaths[i]);
353+
if (rc != 0) {
354+
fprintf(stderr, "pthread_create failed for CSV path %s: %d\n", exploitDBPaths[i], rc);
355+
} else {
356+
num_threads++;
357+
}
358+
}
359+
360+
// Directory threads
361+
for (int i = 0; i < (int)(sizeof(exploitDirs)/sizeof(exploitDirs[0])); i++) {
362+
if (num_threads >= MAX_THREADS) break;
363+
int rc = pthread_create(&threads[num_threads], NULL, scan_dir_thread, (void*)exploitDirs[i]);
364+
if (rc != 0) {
365+
fprintf(stderr, "pthread_create failed for dir %s: %d\n", exploitDirs[i], rc);
366+
} else {
367+
num_threads++;
368+
}
369+
}
370+
371+
// Join exactly the created threads
372+
for (int i = 0; i < num_threads; i++) {
373+
int rc = pthread_join(threads[i], NULL);
374+
if (rc != 0) {
375+
fprintf(stderr, "pthread_join failed on thread %d: %d\n", i, rc);
376+
}
377+
}
358378

359379
display_results();
360380
pthread_mutex_destroy(&lock);

0 commit comments

Comments
 (0)