Commit | Line | Data |
---|---|---|
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 | ||
6c1c0768 | 20 | #define _LGPL_SOURCE |
6242251b CB |
21 | #include <dlfcn.h> /* for dlsym */ |
22 | #include <stdlib.h> /* for getenv */ | |
23 | #include <string.h> /* for strncmp */ | |
24 | ||
25 | #include "testpoint.h" | |
26 | ||
27 | /* Environment variable used to enable the testpoints facilities. */ | |
28 | static const char *lttng_testpoint_env_var = "LTTNG_TESTPOINT_ENABLE"; | |
29 | ||
30 | /* Testpoint toggle flag */ | |
31 | int lttng_testpoint_activated; | |
32 | ||
33 | /* | |
34 | * Toggle the support for testpoints on the application startup. | |
35 | */ | |
36 | static void __attribute__((constructor)) lttng_testpoint_check(void) | |
37 | { | |
38 | char *testpoint_env_val = NULL; | |
39 | ||
40 | testpoint_env_val = getenv(lttng_testpoint_env_var); | |
41 | if (testpoint_env_val != NULL | |
42 | && (strncmp(testpoint_env_val, "1", 1) == 0)) { | |
43 | lttng_testpoint_activated = 1; | |
44 | } | |
45 | } | |
46 | ||
47 | /* | |
48 | * Lookup a symbol by name. | |
49 | * | |
50 | * Return the address where the symbol is loaded or NULL if the symbol was not | |
51 | * found. | |
52 | */ | |
53 | void *lttng_testpoint_lookup(const char *name) | |
54 | { | |
55 | if (!name) { | |
56 | return NULL; | |
57 | } | |
58 | ||
59 | return dlsym(RTLD_DEFAULT, name); | |
60 | } | |
61 | ||
62 | #endif /* NTESTPOINT */ |