From 97e190465f6a2a7d5bf72f445bb4d9d8544a0916 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 6 Mar 2012 11:16:26 -0500 Subject: [PATCH] Fix error.h non-static variables for liblttng-ctl Linking with liblttng-ctl made the variable opt_quiet and opt_verbose undefined if nonexistent in the linked application. Rename the variables adding the prefix lttng_* and declaring them in liblttng-ctl as global variable. The user can now control the verbosity of the library by simply setting them. Future work will mostly add an API call to control verbosity. (closes #151) Signed-off-by: David Goulet --- src/bin/lttng-consumerd/lttng-consumerd.c | 8 ++--- src/bin/lttng-sessiond/main.c | 10 ++---- src/bin/lttng/lttng.c | 11 +++---- src/common/error.h | 37 ++++++++++++----------- src/common/sessiond-comm/sessiond-comm.c | 6 ++-- src/lib/lttng-ctl/lttng-ctl.c | 12 ++++++++ tests/lttng/kernel_all_events_basic.c | 2 +- tests/lttng/kernel_event_basic.c | 2 +- tests/lttng/ust_global_all_events_basic.c | 2 +- tests/lttng/ust_global_event_basic.c | 2 +- tests/test_kernel_data_trace.c | 4 +-- tests/test_sessions.c | 4 +-- tests/test_ust_data_trace.c | 4 +-- 13 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/bin/lttng-consumerd/lttng-consumerd.c b/src/bin/lttng-consumerd/lttng-consumerd.c index 7e3bf3cfb..52b910ac1 100644 --- a/src/bin/lttng-consumerd/lttng-consumerd.c +++ b/src/bin/lttng-consumerd/lttng-consumerd.c @@ -58,8 +58,8 @@ static pthread_t threads[2]; static int sigintcount = 0; /* Argument variables */ -int opt_quiet; -int opt_verbose; +int lttng_opt_quiet; /* not static in error.h */ +int lttng_opt_verbose; /* not static in error.h */ static int opt_daemon; static const char *progname; static char command_sock_path[PATH_MAX]; /* Global command socket path */ @@ -199,10 +199,10 @@ static void parse_args(int argc, char **argv) usage(stdout); exit(EXIT_SUCCESS); case 'q': - opt_quiet = 1; + lttng_opt_quiet = 1; break; case 'v': - opt_verbose = 1; + lttng_opt_verbose = 1; break; case 'V': fprintf(stdout, "%s\n", VERSION); diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index b275874e7..076aac54b 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -81,14 +81,10 @@ const char default_tracing_group[] = DEFAULT_TRACING_GROUP; const char default_ust_sock_dir[] = DEFAULT_UST_SOCK_DIR; const char default_global_apps_pipe[] = DEFAULT_GLOBAL_APPS_PIPE; -/* Variables */ -int opt_verbose; /* Not static for lttngerr.h */ -int opt_verbose_consumer; /* Not static for lttngerr.h */ -int opt_quiet; /* Not static for lttngerr.h */ - const char *progname; const char *opt_tracing_group; static int opt_sig_parent; +static int opt_verbose_consumer; static int opt_daemon; static int opt_no_kernel; static int is_root; /* Set to 1 if the daemon is running as root */ @@ -3989,11 +3985,11 @@ static int parse_args(int argc, char **argv) opt_no_kernel = 1; break; case 'q': - opt_quiet = 1; + lttng_opt_quiet = 1; break; case 'v': /* Verbose level can increase using multiple -v */ - opt_verbose += 1; + lttng_opt_verbose += 1; break; case 'Z': opt_verbose_consumer += 1; diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 16582b036..10b5d191e 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -35,9 +35,6 @@ /* Variables */ static char *progname; - -int opt_quiet; -int opt_verbose; static int opt_no_sessiond; static char *opt_sessiond_path; static pid_t sessiond_pid; @@ -432,10 +429,10 @@ static int parse_args(int argc, char **argv) ret = 0; goto end; case 'v': - opt_verbose += 1; + lttng_opt_verbose += 1; break; case 'q': - opt_quiet = 1; + lttng_opt_quiet = 1; break; case 'g': lttng_set_tracing_group(optarg); @@ -462,8 +459,8 @@ static int parse_args(int argc, char **argv) } /* If both options are specified, quiet wins */ - if (opt_verbose && opt_quiet) { - opt_verbose = 0; + if (lttng_opt_verbose && lttng_opt_quiet) { + lttng_opt_verbose = 0; } /* Spawn session daemon if needed */ diff --git a/src/common/error.h b/src/common/error.h index e5255e4a4..f927078f1 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -30,8 +30,8 @@ #define XSTR(d) STR(d) #define STR(s) #s -extern int opt_quiet; -extern int opt_verbose; +extern int lttng_opt_quiet; +extern int lttng_opt_verbose; #define PRINT_ERR 0x1 #define PRINT_WARN 0x2 @@ -44,22 +44,22 @@ extern int opt_verbose; /* * Macro for printing message depending on command line option and verbosity. */ -#define __lttng_print(type, fmt, args...) \ - do { \ - if (opt_quiet == 0 && type == PRINT_MSG) { \ - fprintf(stdout, fmt, ## args); \ - } else if (opt_quiet == 0 && \ - (((type & PRINT_DBG) && opt_verbose == 1) || \ - ((type & (PRINT_DBG | PRINT_DBG2)) && \ - opt_verbose == 2) || \ - ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) && \ - opt_verbose == 3))) { \ - fprintf(stderr, fmt, ## args); \ - } else if (opt_quiet == 0 && (type & (PRINT_WARN))) { \ - fprintf(stderr, fmt, ## args); \ - } else if (type & (PRINT_ERR | PRINT_BUG)) { \ - fprintf(stderr, fmt, ## args); \ - } \ +#define __lttng_print(type, fmt, args...) \ + do { \ + if (lttng_opt_quiet == 0 && type == PRINT_MSG) { \ + fprintf(stdout, fmt, ## args); \ + } else if (lttng_opt_quiet == 0 && \ + (((type & PRINT_DBG) && lttng_opt_verbose == 1) || \ + ((type & (PRINT_DBG | PRINT_DBG2)) && \ + lttng_opt_verbose == 2) || \ + ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) && \ + lttng_opt_verbose == 3))) { \ + fprintf(stderr, fmt, ## args); \ + } else if (lttng_opt_quiet == 0 && (type & (PRINT_WARN))) { \ + fprintf(stderr, fmt, ## args); \ + } else if (type & (PRINT_ERR | PRINT_BUG)) { \ + fprintf(stderr, fmt, ## args); \ + } \ } while (0); #define MSG(fmt, args...) \ @@ -84,6 +84,7 @@ extern int opt_verbose; " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__) #if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) + /* * Version using XSI strerror_r. */ diff --git a/src/common/sessiond-comm/sessiond-comm.c b/src/common/sessiond-comm/sessiond-comm.c index 70cccf041..61f4ed52b 100644 --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@ -299,7 +299,7 @@ ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len) * Only warn about EPIPE when quiet mode is deactivated. * We consider EPIPE as expected. */ - if (errno != EPIPE || !opt_quiet) { + if (errno != EPIPE || !lttng_opt_quiet) { PERROR("sendmsg"); } } @@ -370,7 +370,7 @@ ssize_t lttcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd) * Only warn about EPIPE when quiet mode is deactivated. * We consider EPIPE as expected. */ - if (errno != EPIPE || !opt_quiet) { + if (errno != EPIPE || !lttng_opt_quiet) { PERROR("sendmsg"); } } @@ -489,7 +489,7 @@ ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len) * Only warn about EPIPE when quiet mode is deactivated. * We consider EPIPE as expected. */ - if (errno != EPIPE || !opt_quiet) { + if (errno != EPIPE || !lttng_opt_quiet) { PERROR("sendmsg"); } } diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index c5887fe65..da93da1cc 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -41,6 +41,18 @@ static char sessiond_sock_path[PATH_MAX]; static char *tracing_group; static int connected; +/* Global */ + +/* + * Those two variables are used by error.h to silent or control the verbosity of + * error message. They are global to the library so application linking with it + * are able to compile correctly and also control verbosity of the library. + * + * Note that it is *not* possible to silent ERR() and PERROR() macros. + */ +int lttng_opt_quiet; +int lttng_opt_verbose; + /* * Copy string from src to dst and enforce null terminated byte. */ diff --git a/tests/lttng/kernel_all_events_basic.c b/tests/lttng/kernel_all_events_basic.c index 3b9fd60e7..6964a6f97 100644 --- a/tests/lttng/kernel_all_events_basic.c +++ b/tests/lttng/kernel_all_events_basic.c @@ -29,7 +29,7 @@ #include "../utils.h" -int opt_quiet = 0; +int lttng_opt_quiet; int main(int argc, char **argv) { diff --git a/tests/lttng/kernel_event_basic.c b/tests/lttng/kernel_event_basic.c index 1deeaad45..0af797c05 100644 --- a/tests/lttng/kernel_event_basic.c +++ b/tests/lttng/kernel_event_basic.c @@ -29,7 +29,7 @@ #include "../utils.h" -int opt_quiet = 0; +int lttng_opt_quiet; int main(int argc, char **argv) { diff --git a/tests/lttng/ust_global_all_events_basic.c b/tests/lttng/ust_global_all_events_basic.c index a2750c557..03363a86b 100644 --- a/tests/lttng/ust_global_all_events_basic.c +++ b/tests/lttng/ust_global_all_events_basic.c @@ -29,7 +29,7 @@ #include "../utils.h" -int opt_quiet = 0; +int lttng_opt_quiet; int main(int argc, char **argv) { diff --git a/tests/lttng/ust_global_event_basic.c b/tests/lttng/ust_global_event_basic.c index 05c1a443e..24dcec53d 100644 --- a/tests/lttng/ust_global_event_basic.c +++ b/tests/lttng/ust_global_event_basic.c @@ -29,7 +29,7 @@ #include "../utils.h" -int opt_quiet = 0; +int lttng_opt_quiet; int main(int argc, char **argv) { diff --git a/tests/test_kernel_data_trace.c b/tests/test_kernel_data_trace.c index 41728544f..6d7f291be 100644 --- a/tests/test_kernel_data_trace.c +++ b/tests/test_kernel_data_trace.c @@ -36,8 +36,8 @@ #define RANDOM_STRING_LEN 11 /* For lttngerr.h */ -int opt_quiet = 1; -int opt_verbose = 0; +int lttng_opt_quiet = 1; +int lttng_opt_verbose; static const char alphanum[] = "0123456789" diff --git a/tests/test_sessions.c b/tests/test_sessions.c index 5134f0b38..e55593561 100644 --- a/tests/test_sessions.c +++ b/tests/test_sessions.c @@ -55,8 +55,8 @@ static struct ltt_session_list *session_list; /* For lttngerr.h */ -int opt_quiet = 1; -int opt_verbose = 0; +int lttng_opt_quiet = 1; +int lttng_opt_verbose = 0; static const char alphanum[] = "0123456789" diff --git a/tests/test_ust_data_trace.c b/tests/test_ust_data_trace.c index 924cfe4b9..459520db1 100644 --- a/tests/test_ust_data_trace.c +++ b/tests/test_ust_data_trace.c @@ -38,8 +38,8 @@ #define RANDOM_STRING_LEN 11 /* For lttngerr.h */ -int opt_quiet = 1; -int opt_verbose = 0; +int lttng_opt_quiet = 1; +int lttng_opt_verbose; static const char alphanum[] = "0123456789" -- 2.34.1