diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dd2adf9..15cb7f84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,8 @@ option(CODE_COVERAGE "Enable code coverage" OFF) if(CODE_COVERAGE) # GCC/Clang if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage -lgcov -DEXIT_USING_FILE") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage -fprofile-arcs -ftest-coverage -lgcov ") endif() endif() @@ -100,6 +100,9 @@ if((${DISTRO_ID} MATCHES "amzn") OR (${DISTRO_ID} MATCHES "ubuntu")) "[Unit]\n" "Description=credentials-fetcher systemd service unit file.\n\n" "[Service]\n" + "StandardError=journal\n" + "StandardOutput=journal\n" + "StandardInput=null\n" "ExecStartPre=mkdir -p ${CF_KRB_DIR} ${CF_UNIX_DOMAIN_SOCKET_DIR} ${CF_LOGGING_DIR}\n" "ExecStartPre=chgrp ec2-user /var/credentials-fetcher ${CF_KRB_DIR} ${CF_UNIX_DOMAIN_SOCKET_DIR} ${CF_LOGGING_DIR}\n" "ExecStartPre=chmod 755 /var/credentials-fetcher ${CF_KRB_DIR} ${CF_UNIX_DOMAIN_SOCKET_DIR} ${CF_LOGGING_DIR}\n" @@ -119,6 +122,9 @@ else() "[Unit]\n" "Description=credentials-fetcher systemd service unit file.\n\n" "[Service]\n" + "StandardError=journal\n" + "StandardOutput=journal\n" + "StandardInput=null\n" "ExecStartPre=mkdir -p ${CF_KRB_DIR} ${CF_UNIX_DOMAIN_SOCKET_DIR} ${CF_LOGGING_DIR}\n" "ExecStart=/usr/sbin/credentials-fetcherd\n" "Environment=\"CREDENTIALS_FETCHERD_STARTED_BY_SYSTEMD=1\"\n" diff --git a/code_coverage_using_gcov.sh b/code_coverage_using_gcov.sh new file mode 100755 index 00000000..5b68a915 --- /dev/null +++ b/code_coverage_using_gcov.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# +mkdir -p build && cd build +if [ $? -ne 0 ]; then + echo "ERROR: Failed at creating build dir" + exit 1 +fi +cmake3 .. -DCODE_COVERAGE=ON && make +if [ $? -ne 0 ]; then + echo "ERROR: Failed at build" + exit 1 +fi + +echo "Start running the credentials-fetcher daemon" +echo "After running gRPC clients, you must exit the credentials-fetcher daemon using 'touch /tmp/credentials_fetcher_exit.txt'" +echo "Note: If you use ctrl-c or sigkill, the gcda files will not get created" + +echo "Run the following in the build directory:" + +echo "\tpip install gcovr" +echo "\tgcovr --html-details coverage.html -r .." +echo "\ttar cvfz coverage.tar.gz *.html" +echo "To view code coverage, extract coverage.tar.gz and start browsing at coverage.html" +exit 0 diff --git a/daemon/src/daemon.cpp b/daemon/src/daemon.cpp index 7df40577..543c328c 100644 --- a/daemon/src/daemon.cpp +++ b/daemon/src/daemon.cpp @@ -19,6 +19,7 @@ static const char* grpc_thread_name = "grpc_thread"; static void systemd_shutdown_signal_catcher( int signo ) { + printf("Credentials-fetcher shutdown: Caught signo %d\n", signo); cf_daemon.got_systemd_shutdown_signal = 1; } @@ -232,7 +233,9 @@ int main( int argc, const char* argv[] ) cf_daemon.got_systemd_shutdown_signal = 0; memset( &sa, 0, sizeof( struct sigaction ) ); sa.sa_handler = &systemd_shutdown_signal_catcher; - if ( sigaction( SIGTERM, &sa, NULL ) == -1 ) + if ( ( sigaction( SIGTERM, &sa, NULL ) == -1 ) || + ( sigaction( SIGINT, &sa, NULL ) == -1 ) || + ( sigaction( SIGHUP, &sa, NULL ) == -1 ) ) { perror( "sigaction" ); return EXIT_FAILURE; @@ -322,6 +325,16 @@ int main( int argc, const char* argv[] ) sd_notifyf( 0, "STATUS=Watchdog notify count = %d", i ); // TBD: Remove later, visible in systemctl status ++i; +#ifdef EXIT_USING_FILE + struct stat st; + if ( lstat( "/tmp/credentials_fetcher_exit.txt", &st ) != -1 ) + { + if (S_ISREG(st.st_mode)) + { + cf_daemon.got_systemd_shutdown_signal = 1; + } + } +#endif } return EXIT_SUCCESS;