0

I'm trying open a so file in apache module with this code :

#include <dlfcn.h>
#include <stdbool.h>
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>



static int helloworld_handler(request_rec* r)
{
if (!r->handler || strcmp(r->handler, "helloworld"))
    return DECLINED;

if (r->method_number != M_GET)
    return HTTP_METHOD_NOT_ALLOWED;


// here i try to load so file --------------------------------
typedef bool (*hello_t)();
void *handle;

handle = dlopen ("/lib.so", RTLD_LAZY);
hello_t echo = (hello_t) dlsym(handle, "echo");

echo();


 // ------------------------------------------------------------
 return OK;
}

static void register_hooks(apr_pool_t* pool)
{
    ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}


module AP_MODULE_DECLARE_DATA helloworld_module = {
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    register_hooks
   };

i'm included dlfcn.h header file but not work! compiling with this : apxs -i -a -c mod_helloworld.c i'm trying compile with -ldl : apxs -i -a -c Wc,-ldl mod_helloworld.c but don't working. i have this error in dlerror() : /usr/lib/apache2/modules/mod_helloworld.so: undefined symbol: echo

Mehdi Homeyli
  • 409
  • 1
  • 4
  • 8
  • 1
    "Doesn't work" isn't a good description to start with. Have you checked and identified errors after `dlopen` and `dlsym`? Take a look at the examples in the [docs](https://linux.die.net/man/3/dlopen) – user3159253 Oct 14 '16 at 00:42
  • Extensive logging is usually a key to success in a new/unknown environment. – user3159253 Oct 14 '16 at 00:43
  • i can't to check error after dlopen and dlsym in apache module, i'm using apxs for compile this module, i cant use gcc to compile and i can't linked -ldl see this : https://httpd.apache.org/docs/2.4/programs/apxs.html – Mehdi Homeyli Oct 14 '16 at 00:50
  • What prevents you from checking dl* functions result codes and logging them using [apache logging API](https://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__LOG.html) ? – user3159253 Oct 14 '16 at 02:07
  • i have this error in dlerror () : /usr/lib/apache2/modules/mod_helloworld.so: undefined symbol: echo – Mehdi Homeyli Oct 14 '16 at 09:03
  • Guess it explains everything. Try this command: `nm -D /var/www/html/mylib.so | grep echo` – Lorinczy Zsigmond Oct 14 '16 at 09:24
  • @LorinczyZsigmond the result is : "00000000000007a0 T echo", my .so file has not problem, i'm using this file on other c++ application but this not work in apache module. i think the problem from compiling with apxs – Mehdi Homeyli Oct 14 '16 at 10:47
  • You seem to have replaced your code with something completely different, but I cannot see any dlerror in it... – Lorinczy Zsigmond Oct 14 '16 at 11:26
  • @LorinczyZsigmond I'm adedd dlerror in my code now and result this massage : /usr/lib/apache2/modules/mod_helloworld.so: undefined symbol: echo.. I'm put all module code in post now – Mehdi Homeyli Oct 14 '16 at 12:43
  • You seem to have replaced your code with something completely different, but I cannot see any dlerror in it... – Lorinczy Zsigmond Oct 15 '16 at 05:28

0 Answers0