Fix: define _LGPL_SOURCE in C files
[lttng-tools.git] / src / common / testpoint / testpoint.c
CommitLineData
6242251b
CB
1/*
2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#ifndef NTESTPOINT
19
20#define _GNU_SOURCE /* for RTLD_DEFAULT GNU extension */
6c1c0768 21#define _LGPL_SOURCE
6242251b
CB
22#include <dlfcn.h> /* for dlsym */
23#include <stdlib.h> /* for getenv */
24#include <string.h> /* for strncmp */
25
26#include "testpoint.h"
27
28/* Environment variable used to enable the testpoints facilities. */
29static const char *lttng_testpoint_env_var = "LTTNG_TESTPOINT_ENABLE";
30
31/* Testpoint toggle flag */
32int lttng_testpoint_activated;
33
34/*
35 * Toggle the support for testpoints on the application startup.
36 */
37static void __attribute__((constructor)) lttng_testpoint_check(void)
38{
39 char *testpoint_env_val = NULL;
40
41 testpoint_env_val = getenv(lttng_testpoint_env_var);
42 if (testpoint_env_val != NULL
43 && (strncmp(testpoint_env_val, "1", 1) == 0)) {
44 lttng_testpoint_activated = 1;
45 }
46}
47
48/*
49 * Lookup a symbol by name.
50 *
51 * Return the address where the symbol is loaded or NULL if the symbol was not
52 * found.
53 */
54void *lttng_testpoint_lookup(const char *name)
55{
56 if (!name) {
57 return NULL;
58 }
59
60 return dlsym(RTLD_DEFAULT, name);
61}
62
63#endif /* NTESTPOINT */
This page took 0.038051 seconds and 5 git commands to generate.