Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dynamic-util.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "util/dynamic-util.h"
16 
17 #include <dlfcn.h>
18 #include <sstream>
19 #include "runtime/exec-env.h"
20 #include "util/test-info.h"
21 
22 #include "common/names.h"
23 
24 namespace impala {
25 
26 Status DynamicLookup(void* handle, const char* symbol, void** fn_ptr, bool quiet) {
27  *(void **) (fn_ptr) = dlsym(handle, symbol);
28  char* error = dlerror();
29  if (error != NULL) {
30  stringstream ss;
31  ss << "Unable to find " << symbol << "\ndlerror: " << error;
32  return quiet ? Status::Expected(ss.str()) : Status(ss.str());
33  }
34  return Status::OK;
35 }
36 
37 Status DynamicOpen(const char* library, void** handle) {
38  int flags = RTLD_NOW;
39  // If we are loading shared libraries from the FE tests, where the Java
40  // side loads the initial impala binary (libfesupport.so), we are unable
41  // to load other libraries and have the symbols resolve. We'll load the
42  // secondary libraries with RTLD_LAZY, which means the symbols don't need
43  // to resolve at load time but will fail at dlsym(). This is generally
44  // undesirable (we want to fail early) and also not the best solution. This
45  // will prevent the FE tests from running the functions that cannot resolve
46  // the symbols (e.g. planner tests with some UDFs).
47  // TODO: this is to work around some build breaks. We need to fix this better.
48  if (TestInfo::is_fe_test()) flags = RTLD_LAZY;
49  *handle = dlopen(library, flags);
50  if (*handle == NULL) {
51  stringstream ss;
52  ss << "Unable to load " << library << "\ndlerror: " << dlerror();
53  return Status(ss.str());
54  }
55  return Status::OK;
56 }
57 
58 void DynamicClose(void* handle) {
59  dlclose(handle);
60 }
61 
62 }
Status DynamicOpen(const char *library, void **handle)
Definition: dynamic-util.cc:37
Status DynamicLookup(void *handle, const char *symbol, void **fn_ptr, bool quiet)
Definition: dynamic-util.cc:26
static bool is_fe_test()
Definition: test-info.h:33
static Status Expected(const std::string &error_msg)
Create a status instance that represents an expected error and will not be logged.
Definition: status.cc:162
void DynamicClose(void *handle)
Closes the handle.
Definition: dynamic-util.cc:58
static const Status OK
Definition: status.h:87