Fix error.h non-static variables for liblttng-ctl
authorDavid Goulet <dgoulet@efficios.com>
Tue, 6 Mar 2012 16:16:26 +0000 (11:16 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 6 Mar 2012 16:22:01 +0000 (11:22 -0500)
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 <dgoulet@efficios.com>
13 files changed:
src/bin/lttng-consumerd/lttng-consumerd.c
src/bin/lttng-sessiond/main.c
src/bin/lttng/lttng.c
src/common/error.h
src/common/sessiond-comm/sessiond-comm.c
src/lib/lttng-ctl/lttng-ctl.c
tests/lttng/kernel_all_events_basic.c
tests/lttng/kernel_event_basic.c
tests/lttng/ust_global_all_events_basic.c
tests/lttng/ust_global_event_basic.c
tests/test_kernel_data_trace.c
tests/test_sessions.c
tests/test_ust_data_trace.c

index 7e3bf3cfbad8c99976cd5b1e8813ad2adfa882a5..52b910ac1385ee8bf92864eb158541b12e6c1f70 100644 (file)
@@ -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);
index b275874e7bc98dc3062b27c7529479326ef1b9bc..076aac54b1824659fc1ba88f195795084b334856 100644 (file)
@@ -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;
index 16582b0363b86fa1405d4afd6d1751f3c36b9499..10b5d191e84dc068a0ed713760990ac4e798ce27 100644 (file)
@@ -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 */
index e5255e4a42adaf9479c412679f812cd8064fa47b..f927078f17726f4e4bb4a755ce16c73e3ab93caa 100644 (file)
@@ -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.
  */
index 70cccf04122cc0174311fda13ecd7e5e55a8d367..61f4ed52ba2dfffe98591e7e65b3ae7deef70336 100644 (file)
@@ -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");
                }
        }
index c5887fe65ead21a41f637aafa3adc10d60e0eb45..da93da1cc35078ec232bd0997d023509dec56807 100644 (file)
@@ -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.
  */
index 3b9fd60e7fa25b0f0bb6b35152fee0ae60aab25d..6964a6f97035a81495a0591527e151ef27fc6a90 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "../utils.h"
 
-int opt_quiet = 0;
+int lttng_opt_quiet;
 
 int main(int argc, char **argv)
 {
index 1deeaad45e589506168ae302ee2f4b55828f19da..0af797c054fc0dadc9f6ad50fde5283e45a12c60 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "../utils.h"
 
-int opt_quiet = 0;
+int lttng_opt_quiet;
 
 int main(int argc, char **argv)
 {
index a2750c5572aba99a2c731cc134b06cf991e1f17e..03363a86b523dd21203ca35c1847625ba2cd0e98 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "../utils.h"
 
-int opt_quiet = 0;
+int lttng_opt_quiet;
 
 int main(int argc, char **argv)
 {
index 05c1a443e00cdf51002f9068cd82397c41df6111..24dcec53d9d473f9b34f6491dc39fc521aeccabf 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "../utils.h"
 
-int opt_quiet = 0;
+int lttng_opt_quiet;
 
 int main(int argc, char **argv)
 {
index 41728544f5c5f4aefffcb2a5b6999e98adc60345..6d7f291beefbf56217ce36bbed30fdc6ec195f54 100644 (file)
@@ -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"
index 5134f0b38cc4fda11bd854ea56691b496f456cc2..e55593561891d2827ba8cb8761e188e31c1d3e92 100644 (file)
@@ -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"
index 924cfe4b97f1fde75af52f075969280072eab932..459520db1e547e12fe988b5b5c5dc85d053b27f0 100644 (file)
@@ -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"
This page took 0.034428 seconds and 4 git commands to generate.