Fix: race between lttng-ust getenv() and application setenv()
[lttng-ust.git] / liblttng-ust / lttng-getcpu.c
CommitLineData
5e1b7b8b
MD
1/*
2 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; version 2.1 of
7 * the License.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#define _GNU_SOURCE
3fbec7dc 20#define _LGPL_SOURCE
5e1b7b8b
MD
21#include <error.h>
22#include <dlfcn.h>
23#include <stdlib.h>
24#include <usterr-signal-safe.h>
25#include <lttng/ust-getcpu.h>
26#include <urcu/system.h>
27#include <urcu/arch.h>
28
730bf2af 29#include "getenv.h"
5e1b7b8b
MD
30#include "../libringbuffer/getcpu.h"
31
32int (*lttng_get_cpu)(void);
33
4bc1ccd7
MD
34static
35void *getcpu_handle;
36
5e1b7b8b
MD
37int lttng_ust_getcpu_override(int (*getcpu)(void))
38{
39 CMM_STORE_SHARED(lttng_get_cpu, getcpu);
40 return 0;
41}
42
43void lttng_ust_getcpu_init(void)
44{
45 const char *libname;
5e1b7b8b
MD
46 void (*libinit)(void);
47
4bc1ccd7
MD
48 if (getcpu_handle)
49 return;
6f626d28 50 libname = lttng_getenv("LTTNG_UST_GETCPU_PLUGIN");
5e1b7b8b
MD
51 if (!libname)
52 return;
4bc1ccd7
MD
53 getcpu_handle = dlopen(libname, RTLD_NOW);
54 if (!getcpu_handle) {
5e1b7b8b
MD
55 PERROR("Cannot load LTTng UST getcpu override library %s",
56 libname);
57 return;
58 }
59 dlerror();
4bc1ccd7 60 libinit = (void (*)(void)) dlsym(getcpu_handle,
5e1b7b8b
MD
61 "lttng_ust_getcpu_plugin_init");
62 if (!libinit) {
63 PERROR("Cannot find LTTng UST getcpu override library %s initialization function lttng_ust_getcpu_plugin_init()",
64 libname);
65 return;
66 }
67 libinit();
68}
This page took 0.025952 seconds and 4 git commands to generate.