...
authoralex <[email protected]>
Sat, 30 Apr 2022 23:13:21 +0000 (16:13 -0700)
committeralex <[email protected]>
Sat, 30 Apr 2022 23:13:21 +0000 (16:13 -0700)
inc/net.h
src/log.c
src/net/start.c
src/session.c
src/sighandler.c
src/watch.c
test/integration/Makefile.am
test/integration/basic.tests.c
test/integration/test_utils.c
test/integration/test_utils.h

index 96a85e35c77f2a357a2e41be3ebd0d978f83b7ff..1bee9dd7f78d4d77d4696751b6be50fa55282e2f 100644 (file)
--- a/inc/net.h
+++ b/inc/net.h
@@ -22,7 +22,7 @@ struct net_info {
        int epoll_fd;
 };
 
-#define NET_MESSAGE_SHUTDOWN_FAILED "net thread shutdown failed\n"
+#define NET_MESSAGE_SHUTDOWN_FAILED "net threads shutdown failed\n"
 
 #define HINTS_INIT(hints,socktype) { \
        memset(&hints,0,sizeof(struct addrinfo)); \
index 5261d8e9f194b3457baf6484dcbdd06528c4e277..7c754570ca35edf016049611fd5ea4b0cb56576f 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -43,7 +43,6 @@ static void log_enqueue(struct log_entry *p) {
 }
 
 static void log_entries_clean(void *p) {
-       printf("log_entries_clean\n");
        free(helper.p);
 }
 
@@ -62,26 +61,21 @@ static int log_entries_init() {
 }
 
 static void log_flush(void *p) {
-       printf("log_flush\n");
        pthread_mutex_lock(&logging_mutex);
 
-       printf("log_flush2\n");
        if(helper.start!=NULL) {        
                fputs(LOG_MESSAGE_FLUSH,stderr);
        }
 
-       printf("log_flush3\n");
        while(helper.start!=NULL) {
                log_print(helper.start);
        }
        
-       printf("log_flush4\n");
        helper.start = NULL;
        helper.end = NULL;
        helper.next = 0;
 
        pthread_mutex_unlock(&logging_mutex);
-       printf("log_flush5\n");
 }
 
 void log_print() {
@@ -158,11 +152,11 @@ void *log_poll(void *p) {
        while(1) {
                pthread_testcancel();
                
+               pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL);
                pthread_mutex_lock(&logging_mutex);
-               printf("logging mutex lock\n");
                log_print();
                pthread_mutex_unlock(&logging_mutex);
-               printf("logging mutex unlock\n");
+               pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
        }
 
        pthread_cleanup_pop(1);
@@ -175,13 +169,10 @@ static void log_shutdown() {
        int ret_cancel, ret_join;
        void *res;
 
-       printf("shutting down logging thread\n");
-               
        ret_cancel = pthread_cancel(logging_thread);
        ret_join = pthread_join(logging_thread,&res);
        
        logging_thread = pthread_self();
-       printf("shutting down logging thread 2\n");
 
        if((ret_cancel!=0)||(ret_join!=0)||(res!=PTHREAD_CANCELED)) {
                log_err(LOG_MESSAGE_SHUTDOWN_FAILED);
index 0fc4140bb720dae459e1e1edfb6705752d3120d1..b6aec30b565543d8d00cdcf1c03d8f74d9b15804 100644 (file)
@@ -52,7 +52,6 @@ int net_start() {
 }
 
 static void net_stop() {
-       log_info("net thread stopping\n");
        for(size_t i=0;i<global_options.worker_threads;i++) {
                pthread_cancel(net_threads[i]);
        }
@@ -62,6 +61,5 @@ static void net_stop() {
                        log_err(NET_MESSAGE_SHUTDOWN_FAILED);
                }
        }
-       log_info("net thread stopped\n");
 }
 
index 0aeabe8d57a1077854daf33347ff61d108f927d9..a9659b6f1d9f760fde7f4ac14ce730b5d15c44b6 100644 (file)
@@ -10,8 +10,6 @@ static int session_torrent_resize(struct hash_map**,size_t);
 static void session_clean() {
        struct torrent *p;
 
-       printf("clearing session\n");
-
        for(size_t i=0;i<session.torrents.paths->size;i++) {
                p = session.torrents.paths->map[i];
                if(p!=NULL) { torrent_free(p); }
@@ -22,8 +20,6 @@ static void session_clean() {
 
        hashmap_clear(session.torrents.paths);
        hashmap_free(session.torrents.paths);
-       
-       printf("session cleared\n");
 }
 
 struct torrent *session_find_torrent(uint8_t *infohash, size_t size) {
@@ -47,8 +43,6 @@ int session_setup() {
                return -1;
        }
 
-       printf("session setup\n");
-
        return 1;
 }
 
index 793fa11a9843ee24e1f4e6705998e55bc3cedb18..a46f90291f75ce0ab3d3b8b2a401cbdf7d30c9bc 100644 (file)
@@ -9,7 +9,7 @@ static void handle_interrupt() {
         * call exit explicitly will call functions registered
         * with atexit and do appropriate cleanup.
         */
-       exit(EXIT_FAILURE);
+       exit(EXIT_SUCCESS);
 }
 
 static void shutdown_success() {
index 34e37c791ae8d3814dd83b1271871188ebb94f3b..d7fef2642dbd378f77851fa5f4621cf7ebac43ba 100644 (file)
@@ -101,10 +101,8 @@ static void watch_poll() {
 }
 
 static void watch_shutdown() {
-       printf("watch thread stopping\n");
        if(0!=pthread_cancel(watching_thread)) {
                log_err(WATCH_MESSAGE_SHUTDOWN_FAILED);
        }
        close(watch_fd);
-       printf("watch thread stopped\n");
 }
index a9f941dc172a4696fd185b9269ed677bb0eef0ce..5cccaf1e2b0b10c913b58a1cf3be357b6cfe5f82 100644 (file)
@@ -19,10 +19,10 @@ endif
 check_PROGRAMS = basic.tests
 TESTS = $(check_PROGRAMS)
 
-if ENABLE_MEMCHECK
-LOG_COMPILER = $(VALGRIND)
-AM_LOG_FLAGS = --leak-check=full -v --trace-children=yes --track-origins=yes --error-exitcode=1
-endif
+#if ENABLE_MEMCHECK
+#LOG_COMPILER = $(VALGRIND)
+#AM_LOG_FLAGS = -v --leak-check=full --trace-children=yes --trace-children-skip=*.tests,/bin/sh,/bin/rm --track-origins=yes --track-fds=yes --error-exitcode=1
+#endif
 
 common_SOURCES = \
        test_utils.c
index 34c416ab9f0825e5f1e4f53445578af8cd77776c..55c2c282ef2b819ed646d343955eeb249bb1ed2a 100644 (file)
@@ -22,8 +22,7 @@ void basic_test() {
                NULL
        };
        
-       run_and_exit_successfully(opts);
+       run_and_gracefully_exit_successfully(opts,2);
 
-       assert(0);
        reset_env();
 }
index 373304db1462a403bd025327629a45060084ca46..aed2456ebabef94820010b72a1f75c1dcac5facf 100644 (file)
@@ -27,30 +27,24 @@ pid_t run(char *const opts[]) {
        return pid;
 }
 
-void run_and_exit_successfully(char *const opts[]) {
+void run_and_gracefully_exit_successfully(char *const opts[], unsigned int secs) {
        int status;
 
-       printf("running\n");
        pid_t child_pid = run(opts);
 
-       // wait 5 seconds for startup   
-       printf("sleeping\n");
-       sleep(5);
+       // wait secs seconds for startup        
+       sleep(secs);
        
        // verify still running
-       printf("verify process running\n");
        assert(0==waitpid(child_pid,&status,WNOHANG));
 
        // SIGINT to shutdown
-       printf("send SIGINT\n");
        assert(0==kill(child_pid,SIGINT));
 
        // verify child process exited successfully
-       printf("waiting for child process to exit\n");
        assert(child_pid==waitpid(child_pid,&status,0));
-       printf("checking exit status\n");
        assert(WIFEXITED(status));
-       printf("success!\n");
+       assert(EXIT_SUCCESS==WEXITSTATUS(status));
 }
 
 void setup_env() {
index 0640a7c07eba81043e4acdfc23b86519cd5a08e4..5df4acea014269d511b5f8413a9c129144baf417 100644 (file)
@@ -16,7 +16,7 @@
 void clean_env();
 void reset_env();
 pid_t run(char*const[]);
-void run_and_exit_successfully(char*const[]);
+void run_and_gracefully_exit_successfully(char*const[],unsigned int);
 void setup_env();
 
 #endif