Browse Source

Can be build without dlopen()

Serj Kalichev 10 years ago
parent
commit
203b12d99d
6 changed files with 41 additions and 7 deletions
  1. 1 0
      .gitignore
  2. 2 1
      bin/module.am
  3. 1 1
      clish/plugin.h
  4. 16 3
      clish/plugin/plugin.c
  5. 4 1
      clish/plugin_builtin.c.in
  6. 17 1
      configure.ac

+ 1 - 0
.gitignore

@@ -24,6 +24,7 @@
 /aclocal.m4
 /Makefile.in
 /clish/plugin_builtin.c
+/*.patch
 
 # Debian files
 /build-stamp

+ 2 - 1
bin/module.am

@@ -10,7 +10,8 @@ bin_clish_LDADD = \
 	libclish.la \
 	libkonf.la \
 	libtinyrl.la \
-	liblub.la
+	liblub.la \
+	@CLISH_PLUGIN_BUILTIN_LIBS@
 
 bin_konfd_SOURCES = bin/konfd.c
 bin_konfd_LDADD = \

+ 1 - 1
clish/plugin.h

@@ -56,7 +56,7 @@ struct clish_plugin_builtin_list_s {
 	clish_plugin_init_t *init; /* Plugin init function */
 };
 typedef struct clish_plugin_builtin_list_s clish_plugin_builtin_list_t;
-extern clish_plugin_builtin_list_t * clish_plugin_builtin_list[];
+extern clish_plugin_builtin_list_t clish_plugin_builtin_list[];
 
 /* Symbol */
 

+ 16 - 3
clish/plugin/plugin.c

@@ -285,7 +285,7 @@ static int clish_plugin_load_shared(clish_plugin_t *this)
 	this->dlhan = dlopen(file, RTLD_NOW | RTLD_LOCAL);
 	lub_string_free(file);
 	if (!this->dlhan) {
-		fprintf(stderr, "Error: Can't open plugin %s: %s\n",
+		fprintf(stderr, "Error: Can't open plugin \"%s\": %s\n",
 			this->name, dlerror());
 		return -1;
 	}
@@ -297,7 +297,7 @@ static int clish_plugin_load_shared(clish_plugin_t *this)
 	this->init = (clish_plugin_init_t *)dlsym(this->dlhan, init_name);
 	lub_string_free(init_name);
 	if (!this->init) {
-		fprintf(stderr, "Error: Can't get plugin %s init function: %s\n",
+		fprintf(stderr, "Error: Can't get plugin \"%s\" init function: %s\n",
 			this->name, dlerror());
 		return -1;
 	}
@@ -305,7 +305,8 @@ static int clish_plugin_load_shared(clish_plugin_t *this)
 	return 0;
 #else /* HAVE_DLFCN_H */
 	/* We have no any dl functions. */
-
+	fprintf(stderr, "Error: Can't get plugin \"%s\" init function.\n",
+		this->name);
 	return -1;
 #endif /* HAVE_DLFCN_H */
 }
@@ -313,6 +314,18 @@ static int clish_plugin_load_shared(clish_plugin_t *this)
 /*--------------------------------------------------------- */
 static int clish_plugin_load_builtin(clish_plugin_t *this)
 {
+	int i = 0;
+
+	/* Search plugin in the list of builtin plugins */
+	while (clish_plugin_builtin_list[i].name) {
+		if (strcmp(clish_plugin_builtin_list[i].name, this->name))
+			continue;
+		this->init = clish_plugin_builtin_list[i].init;
+		break;
+	}
+	if (this->init)
+		return 0;
+
 	return -1;
 }
 

+ 4 - 1
clish/plugin_builtin.c.in

@@ -9,6 +9,9 @@
 #include <stdlib.h>
 #include "clish/plugin.h"
 
+/* Declare builtin plugin's init functions */
+@CLISH_PLUGIN_BUILTIN_DEFS@
+
 /* The array of builtin plugin's filled by configure script. */
-clish_plugin_builtin_list_t *clish_plugin_builtin_list[] = {@CLISH_PLUGIN_BUILTIN_LIST@ NULL};
+clish_plugin_builtin_list_t clish_plugin_builtin_list[] = {@CLISH_PLUGIN_BUILTIN_LIST@ { NULL, NULL } };
 

+ 17 - 1
configure.ac

@@ -535,15 +535,31 @@ AC_CHECK_FUNCS(chroot, [],
 # Check for dlopen
 ################################
 CLISH_PLUGIN_BUILTIN_LIST=
+CLISH_PLUGIN_BUILTIN_DEFS=
+CLISH_PLUGIN_BUILTIN_LIBS=
+
+AC_DEFUN([AC_PLUGIN_BUILTIN],
+[
+  CLISH_PLUGIN_BUILTIN_LIBS="$CLISH_PLUGIN_BUILTIN_LIBS clish_plugin_$1.la"
+  CLISH_PLUGIN_BUILTIN_DEFS="$CLISH_PLUGIN_BUILTIN_DEFS CLISH_PLUGIN_INIT($1);"
+  CLISH_PLUGIN_BUILTIN_LIST="$CLISH_PLUGIN_BUILTIN_LIST { \"$1\", clish_plugin_$1_init },"
+])
+
 AC_CHECK_HEADERS(dlfcn.h, [
         AC_SEARCH_LIBS([dlopen], [dl dld], [], [
           AC_MSG_ERROR([unable to find the dlopen() function])
         ])
     ],[
           AC_MSG_WARN([dlfcn.h not found: the dl operations is not supported])
-          CLISH_PLUGIN_BUILTIN_LIST="$CLISH_PLUGIN_BUILTIN_LIST { "clish", clish_clish_plugin_init },"
+          AC_PLUGIN_BUILTIN([clish])
+          if test x$use_lua != xno; then
+            AC_PLUGIN_BUILTIN([lua])
+          fi
     ])
+
 AC_SUBST([CLISH_PLUGIN_BUILTIN_LIST])
+AC_SUBST([CLISH_PLUGIN_BUILTIN_DEFS])
+AC_SUBST([CLISH_PLUGIN_BUILTIN_LIBS])
 AC_CONFIG_FILES([clish/plugin_builtin.c])
 
 AC_CONFIG_FILES([Makefile])