X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Ftlsproxy.c;h=ba8386b2125c9ddf56efae46848eb772ff484701;hb=f4eb585e927d86ece30067bdf8e96abe8058f5d2;hp=77c6d0293228735f370dc1fdb898ffd62a738aec;hpb=d0b5d139253e5c599c9e675fc0a5677bda5a5a29;p=tlsproxy%2Ftlsproxy.git diff --git a/src/tlsproxy.c b/src/tlsproxy.c index 77c6d02..ba8386b 100644 --- a/src/tlsproxy.c +++ b/src/tlsproxy.c @@ -76,7 +76,7 @@ static void print_usage(const char *argv); static void initialize_gnutls(void); static void deinitialize_gnutls(void); -static void worker_thread(void); +static void *worker_thread(void *unused); int main(int argc, char **argv) { @@ -97,8 +97,7 @@ int main(int argc, char **argv) { port = atoi(argv[argc - 1]); if (port <= 0 || port > 0xffff ) { - print_usage(argv[0]); - fprintf(stderr, "\ninvalid port: '%s'\n", argv[argc - 1]); + fprintf(stderr, "invalid port: '%s'\n", argv[argc - 1]); return EXIT_FAILURE; } @@ -136,19 +135,11 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } for (i = 0; i < thread_count; i++) { - int result; - pthread_t thread; - - result = pthread_create(&thread, NULL, - (void * (*)(void *))&worker_thread, - NULL); - if (result != 0) { - fprintf(stderr, "failed to create worker thread: %s\n", - strerror(result)); + errno = pthread_create(threads + i, NULL, &worker_thread, NULL); + if (errno != 0) { + perror("failed to create worker thread"); return EXIT_FAILURE; } - - threads[i] = thread; } #ifdef USE_IPV4_ONLY @@ -231,9 +222,9 @@ int main(int argc, char **argv) { } } - free(ringbuffer_full); - free(ringbuffer_free); - free(ringbuffer_lock); + sem_del(ringbuffer_full); + sem_del(ringbuffer_free); + sem_del(ringbuffer_lock); free(threads); @@ -268,13 +259,12 @@ static void parse_arguments(int argc, char **argv) { while ((option = getopt(argc, argv, "d:p:t:uh?")) != -1) { switch (option) { case 'd': { - if (atoi(optarg) < 0) { - print_usage(argv[0]); - fprintf(stderr, "\n-d positive number required: '%s'\n", + global_log_level = atoi(optarg); + if (global_log_level < 0) { + fprintf(stderr, "-d positive number required: '%s'\n", optarg); exit(EXIT_FAILURE); } - global_log_level = atoi(optarg); break; } case 'p': { @@ -286,9 +276,8 @@ static void parse_arguments(int argc, char **argv) { || strlen(position + 1) == 0 || atoi(position + 1) <= 0 || atoi(position + 1) > 0xffff) { - print_usage(argv[0]); - fprintf(stderr, "\ninvalid -p: '%s', format host:port\n", - optarg); + fprintf(stderr, "invalid -p: '%s', format host:port\n", + optarg); exit(EXIT_FAILURE); } @@ -311,8 +300,7 @@ static void parse_arguments(int argc, char **argv) { } case 't': { if (atoi(optarg) <= 0) { - print_usage(argv[0]); - fprintf(stderr, "\n-t positive number required: '%s'\n", + fprintf(stderr, "-t positive number required: '%s'\n", optarg); exit(EXIT_FAILURE); } @@ -331,8 +319,7 @@ static void parse_arguments(int argc, char **argv) { } if (optind >= argc) { - print_usage(argv[0]); - fprintf(stderr, "\nport missing\n"); + fprintf(stderr, "port missing\n"); exit(EXIT_FAILURE); } } @@ -352,18 +339,18 @@ static void print_usage(const char *argv) { static void initialize_gnutls(void) { int result; - gcry_error_t error = 0; + gcry_error_t error; /* Thread safe setup. Must be called before gnutls_global_init(). */ error = gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); - if (error) { + if (error != 0) { fprintf(stderr, "gcry_control(): %s/%s\n", gcry_strsource(error), gcry_strerror(error)); exit(EXIT_FAILURE); } /* Prevent usage of blocking /dev/random. */ error = gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0); - if (error) { + if (error != 0) { fprintf(stderr, "gcry_control(): %s/%s\n", gcry_strsource(error), gcry_strerror(error)); exit(EXIT_FAILURE); @@ -390,9 +377,11 @@ static void deinitialize_gnutls(void) { gnutls_global_deinit(); } -static void worker_thread(void) { +static void *worker_thread(void *unused) { int client_socket; + (void)unused; + for (;;) { /* Get next element from ring buffer. */ P(ringbuffer_full); @@ -409,4 +398,6 @@ static void worker_thread(void) { handle_connection(client_socket); } + + return NULL; }