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)); \
 
 }
 
 static void log_entries_clean(void *p) {
-       printf("log_entries_clean\n");
        free(helper.p);
 }
 
 }
 
 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() {
        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);
        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);
 
 }
 
 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]);
        }
                        log_err(NET_MESSAGE_SHUTDOWN_FAILED);
                }
        }
-       log_info("net thread stopped\n");
 }
 
 
 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); }
 
        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) {
                return -1;
        }
 
-       printf("session setup\n");
-
        return 1;
 }
 
 
         * call exit explicitly will call functions registered
         * with atexit and do appropriate cleanup.
         */
-       exit(EXIT_FAILURE);
+       exit(EXIT_SUCCESS);
 }
 
 static void shutdown_success() {
 
 }
 
 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");
 }
 
 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
 
                NULL
        };
        
-       run_and_exit_successfully(opts);
+       run_and_gracefully_exit_successfully(opts,2);
 
-       assert(0);
        reset_env();
 }
 
        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() {
 
 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