Permalink
Browse files

Add ability to set dlopen flags used to load .node modules

Cf. issue 436 in joyent/node repository
  • Loading branch information...
1 parent 4cc0a08 commit a77a3394713b03a2298192d4a40956a22555d6d1 Wayne Volkmuth committed Mar 23, 2011
Showing with 39 additions and 5 deletions.
  1. +4 −2 lib/module.js
  2. +6 −2 src/node.cc
  3. +29 −1 src/node_constants.cc
View
@@ -415,8 +415,10 @@ Module._extensions['.js'] = function(module, filename) {
// Native extension for .node
-Module._extensions['.node'] = function(module, filename) {
- process.dlopen(filename, module.exports);
+Module._extensions['.node'] = function(module, filename, flags) {
+ if (flags === undefined)
+ flags = process.dlOpenFlags || require('constants').RTLD_LAZY || 0;
+ process.dlopen(filename, module.exports, flags);
};
View
@@ -1593,12 +1593,15 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
String::Utf8Value filename(args[0]->ToString()); // Cast
Local<Object> target = args[1]->ToObject(); // Cast
+ int flags = RTLD_LAZY;
+ if (args.Length() >= 3)
+ flags = args[2]->IntegerValue();
// Actually call dlopen().
// FIXME: This is a blocking function and should be called asynchronously!
// This function should be moved to file.cc and use libeio to make this
// system call.
- void *handle = dlopen(*filename, RTLD_LAZY);
+ void *handle = dlopen(*filename, flags);
// Handle errors.
if (handle == NULL) {
@@ -1660,7 +1663,6 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
// coverity[leaked_storage]
return Undefined();
}
-
#endif // __POSIX__
@@ -2062,6 +2064,8 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
NODE_SET_METHOD(process, "umask", Umask);
NODE_SET_METHOD(process, "dlopen", DLOpen);
NODE_SET_METHOD(process, "_kill", Kill);
+
+ process->Set(String::NewSymbol("dlOpenFlags"), Integer::New(RTLD_LAZY));
#endif // __POSIX__
NODE_SET_METHOD(process, "uptime", Uptime);
View
@@ -26,6 +26,7 @@
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
+#include <dlfcn.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -838,6 +839,33 @@ void DefineConstants(Handle<Object> target) {
#ifdef SIGUNUSED
NODE_DEFINE_CONSTANT(target, SIGUNUSED);
#endif
-}
+#ifdef RTLD_LAZY
+ NODE_DEFINE_CONSTANT(target, RTLD_LAZY);
+#endif
+
+#ifdef RTLD_NOW
+ NODE_DEFINE_CONSTANT(target, RTLD_NOW);
+#endif
+
+#ifdef RTLD_GLOBAL
+ NODE_DEFINE_CONSTANT(target, RTLD_GLOBAL);
+#endif
+
+#ifdef RTLD_LOCAL
+ NODE_DEFINE_CONSTANT(target, RTLD_LOCAL);
+#endif
+
+#ifdef RTLD_NODELETE
+ NODE_DEFINE_CONSTANT(target, RTLD_NODELETE);
+#endif
+
+#ifdef RTLD_NOLOAD
+ NODE_DEFINE_CONSTANT(target, RTLD_NOLOAD);
+#endif
+
+#ifdef RTLD_DEEPBIND
+ NODE_DEFINE_CONSTANT(target, RTLD_DEEPBIND);
+#endif
+}
} // namespace node

0 comments on commit a77a339

Please sign in to comment.