Don't initialize defaults in library constructor
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 20 Oct 2015 15:08:54 +0000 (11:08 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 20 Oct 2015 15:10:02 +0000 (11:10 -0400)
This is done so lttng-tools has no dependency on constructors
being run, such as in the case of a static build.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/defaults.c
src/common/defaults.h

index e670eeb0ffbb1b74819916dd7e58ad8cb3001e61..d131971ecf05e62b89d1cb1bd3db064c980b1d6c 100644 (file)
 
 #include "defaults.h"
 #include "macros.h"
+#include "align.h"
 
-size_t default_channel_subbuf_size;
-size_t default_metadata_subbuf_size;
-size_t default_kernel_channel_subbuf_size;
-size_t default_ust_pid_channel_subbuf_size;
-size_t default_ust_uid_channel_subbuf_size;
+static size_t default_channel_subbuf_size;
+static size_t default_metadata_subbuf_size;
+static size_t default_kernel_channel_subbuf_size;
+static size_t default_ust_pid_channel_subbuf_size;
+static size_t default_ust_uid_channel_subbuf_size;
 
-static void __attribute__((constructor)) init_defaults(void)
+LTTNG_HIDDEN
+size_t default_get_channel_subbuf_size(void)
 {
-       /*
-        * The libringbuffer won't accept subbuf sizes smaller than the page size.
-        * If the default subbuf size is smaller, replace it by the page size.
-        */
-       long page_size = sysconf(_SC_PAGESIZE);
-
-       if (page_size < 0) {
-               page_size = 0;
-       }
-
-       default_channel_subbuf_size =
-               max(_DEFAULT_CHANNEL_SUBBUF_SIZE, page_size);
-       default_metadata_subbuf_size =
-               max(DEFAULT_METADATA_SUBBUF_SIZE, page_size);
-       default_kernel_channel_subbuf_size =
-               max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE, page_size);
-       default_ust_pid_channel_subbuf_size =
-               max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE, page_size);
-       default_ust_uid_channel_subbuf_size =
-               max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE, page_size);
+       return max(_DEFAULT_CHANNEL_SUBBUF_SIZE, PAGE_SIZE);
+}
+
+LTTNG_HIDDEN
+size_t default_get_metadata_subbuf_size(void)
+{
+       return max(DEFAULT_METADATA_SUBBUF_SIZE, PAGE_SIZE);
+}
+
+LTTNG_HIDDEN
+size_t default_get_kernel_channel_subbuf_size(void)
+{
+       return max(DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE, PAGE_SIZE);
+}
+
+LTTNG_HIDDEN
+size_t default_get_ust_pid_channel_subbuf_size(void)
+{
+       return max(DEFAULT_UST_PID_CHANNEL_SUBBUF_SIZE, PAGE_SIZE);
+}
+
+LTTNG_HIDDEN
+size_t default_get_ust_uid_channel_subbuf_size(void)
+{
+       return max(DEFAULT_UST_UID_CHANNEL_SUBBUF_SIZE, PAGE_SIZE);
 }
index cba94c9168eff2111f4879c9e63cf51fbe36b3d9..6bf06becdde069ff04e26900c99013d8f62c4da1 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
  *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *               2015 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2 only,
@@ -19,6 +20,8 @@
 #ifndef _DEFAULTS_H
 #define _DEFAULTS_H
 
+#include <src/common/macros.h>
+
 /* Default unix group name for tracing. */
 #define DEFAULT_TRACING_GROUP                   "tracing"
 
 /* Default runas worker name */
 #define DEFAULT_RUN_AS_WORKER_NAME                     "lttng-runas"
 
-extern size_t default_channel_subbuf_size;
-extern size_t default_metadata_subbuf_size;
-extern size_t default_ust_pid_channel_subbuf_size;
-extern size_t default_ust_uid_channel_subbuf_size;
-extern size_t default_kernel_channel_subbuf_size;
-
 /*
  * Returns the default subbuf size.
  *
  * This function depends on a value that is set at constructor time, so it is
  * unsafe to call it from another constructor.
  */
-static inline
-size_t default_get_channel_subbuf_size(void)
-{
-       return default_channel_subbuf_size;
-}
+LTTNG_HIDDEN
+size_t default_get_channel_subbuf_size(void);
 
 /*
  * Returns the default metadata subbuf size.
@@ -327,11 +321,8 @@ size_t default_get_channel_subbuf_size(void)
  * This function depends on a value that is set at constructor time, so it is
  * unsafe to call it from another constructor.
  */
-static inline
-size_t default_get_metadata_subbuf_size(void)
-{
-       return default_metadata_subbuf_size;
-}
+LTTNG_HIDDEN
+size_t default_get_metadata_subbuf_size(void);
 
 /*
  * Returns the default subbuf size for the kernel domain.
@@ -339,11 +330,8 @@ size_t default_get_metadata_subbuf_size(void)
  * This function depends on a value that is set at constructor time, so it is
  * unsafe to call it from another constructor.
  */
-static inline
-size_t default_get_kernel_channel_subbuf_size(void)
-{
-       return default_kernel_channel_subbuf_size;
-}
+LTTNG_HIDDEN
+size_t default_get_kernel_channel_subbuf_size(void);
 
 /*
  * Returns the default subbuf size for the UST domain per PID.
@@ -351,11 +339,8 @@ size_t default_get_kernel_channel_subbuf_size(void)
  * This function depends on a value that is set at constructor time, so it is
  * unsafe to call it from another constructor.
  */
-static inline
-size_t default_get_ust_pid_channel_subbuf_size(void)
-{
-       return default_ust_pid_channel_subbuf_size;
-}
+LTTNG_HIDDEN
+size_t default_get_ust_pid_channel_subbuf_size(void);
 
 /*
  * Returns the default subbuf size for the UST domain per UID.
@@ -363,10 +348,7 @@ size_t default_get_ust_pid_channel_subbuf_size(void)
  * This function depends on a value that is set at constructor time, so it is
  * unsafe to call it from another constructor.
  */
-static inline
-size_t default_get_ust_uid_channel_subbuf_size(void)
-{
-       return default_ust_uid_channel_subbuf_size;
-}
+LTTNG_HIDDEN
+size_t default_get_ust_uid_channel_subbuf_size(void);
 
 #endif /* _DEFAULTS_H */
This page took 0.028781 seconds and 4 git commands to generate.