]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/commitdiff
Minor code cleanup.
authorSimon Ruderich <simon@ruderich.org>
Sun, 28 Jul 2013 10:11:23 +0000 (12:11 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sun, 28 Jul 2013 10:11:23 +0000 (12:11 +0200)
src/connection.c
src/tlsproxy.c
tests/client.c

index e053df2ee23e187a9399acc39c4cc403149c01a8..365eaab2e6de30c361f92d07c5130eaf9c4ff3cc 100644 (file)
@@ -625,9 +625,8 @@ static int read_from_write_to(int from, int to) {
     if (size_read < 0) {
         LOG_PERROR(LOG_WARNING, "read_from_write_to(): read()");
         return -1;
-    }
     /* EOF */
-    if (size_read == 0) {
+    } else if (size_read == 0) {
         return -1;
     }
 
@@ -722,9 +721,8 @@ static int read_from_write_to_tls(gnutls_session_t from,
         LOG(LOG_WARNING, "read_from_write_to_tls(): gnutls_record_recv(): %s",
                          gnutls_strerror((int)size_read));
         return -1;
-    }
     /* EOF */
-    if (size_read == 0) {
+    } else if (size_read == 0) {
         return -1;
     }
 
index 77c6d0293228735f370dc1fdb898ffd62a738aec..0f3481efab96694813d781b9eba91c7b08f5042a 100644 (file)
@@ -136,19 +136,13 @@ 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,
+        errno = pthread_create(threads + i, NULL,
                                 (void * (*)(void *))&worker_thread,
                                 NULL);
-        if (result != 0) {
-            fprintf(stderr, "failed to create worker thread: %s\n",
-                            strerror(result));
+        if (errno != 0) {
+            perror("failed to create worker thread");
             return EXIT_FAILURE;
         }
-
-        threads[i] = thread;
     }
 
 #ifdef USE_IPV4_ONLY
@@ -268,13 +262,13 @@ 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) {
+                global_log_level = atoi(optarg);
+                if (global_log_level < 0) {
                     print_usage(argv[0]);
                     fprintf(stderr, "\n-d positive number required: '%s'\n",
                                     optarg);
                     exit(EXIT_FAILURE);
                 }
-                global_log_level = atoi(optarg);
                 break;
             }
             case 'p': {
@@ -352,18 +346,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);
index 9bb23f392ab2831a896dc859d5fc76b9d05c6acc..c11684d2e19bd57d7a60f422601b8aefe7386a8e 100644 (file)
@@ -235,7 +235,7 @@ static int read_http_request(FILE *client_fd, char *request, size_t length) {
         return -2;
     }
 
-    while (fgets(buffer, MAX_REQUEST_LINE, client_fd) != NULL) {
+    while (fgets(buffer, sizeof(buffer), client_fd) != NULL) {
         /* End of header. */
         if (!strcmp(buffer, "\n") || !strcmp(buffer, "\r\n")) {
             break;