From b4a88b54f2c6a448c7a03d86a8c86fc707d958e3 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 30 Apr 2022 16:13:21 -0700 Subject: [PATCH] ... --- inc/net.h | 2 +- src/log.c | 13 ++----------- src/net/start.c | 2 -- src/session.c | 6 ------ src/sighandler.c | 2 +- src/watch.c | 2 -- test/integration/Makefile.am | 8 ++++---- test/integration/basic.tests.c | 3 +-- test/integration/test_utils.c | 14 ++++---------- test/integration/test_utils.h | 2 +- 10 files changed, 14 insertions(+), 40 deletions(-) diff --git a/inc/net.h b/inc/net.h index 96a85e3..1bee9dd 100644 --- 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)); \ diff --git a/src/log.c b/src/log.c index 5261d8e..7c75457 100644 --- 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); diff --git a/src/net/start.c b/src/net/start.c index 0fc4140..b6aec30 100644 --- a/src/net/start.c +++ b/src/net/start.c @@ -52,7 +52,6 @@ int net_start() { } static void net_stop() { - log_info("net thread stopping\n"); for(size_t i=0;isize;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; } diff --git a/src/sighandler.c b/src/sighandler.c index 793fa11..a46f902 100644 --- a/src/sighandler.c +++ b/src/sighandler.c @@ -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() { diff --git a/src/watch.c b/src/watch.c index 34e37c7..d7fef26 100644 --- a/src/watch.c +++ b/src/watch.c @@ -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"); } diff --git a/test/integration/Makefile.am b/test/integration/Makefile.am index a9f941d..5cccaf1 100644 --- a/test/integration/Makefile.am +++ b/test/integration/Makefile.am @@ -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 diff --git a/test/integration/basic.tests.c b/test/integration/basic.tests.c index 34c416a..55c2c28 100644 --- a/test/integration/basic.tests.c +++ b/test/integration/basic.tests.c @@ -22,8 +22,7 @@ void basic_test() { NULL }; - run_and_exit_successfully(opts); + run_and_gracefully_exit_successfully(opts,2); - assert(0); reset_env(); } diff --git a/test/integration/test_utils.c b/test/integration/test_utils.c index 373304d..aed2456 100644 --- a/test/integration/test_utils.c +++ b/test/integration/test_utils.c @@ -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() { diff --git a/test/integration/test_utils.h b/test/integration/test_utils.h index 0640a7c..5df4ace 100644 --- a/test/integration/test_utils.h +++ b/test/integration/test_utils.h @@ -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 -- 2.30.2