Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx_link_func_init_cycle() not found on FreeBSD #14

Closed
interkosmos opened this issue May 28, 2020 · 12 comments
Closed

ngx_link_func_init_cycle() not found on FreeBSD #14

interkosmos opened this issue May 28, 2020 · 12 comments

Comments

@interkosmos
Copy link

interkosmos commented May 28, 2020

The following basic example is not accepted by the nginx-link-function module on FreeBSD 12 with nginx 1.18 :

#include <stdio.h>
#include <ngx_link_func_module.h>

int is_service_on = 0;

void ngx_link_func_init_cycle(ngx_link_func_cycle_t* cycle) {
    ngx_link_func_cyc_log(info, cycle, "%s", "starting application");

    is_service_on=1;
}

void greeting(ngx_link_func_ctx_t *ctx) {
    ngx_link_func_log_info(ctx, "Calling back and log from my_app_simple_get");

    ngx_link_func_write_resp(
        ctx,
        200,
        "200 OK",
        "text/plain",
        "greeting from ngx_link_func testing",
        sizeof("greeting from ngx_link_func testing")-1
    );
}

void ngx_link_func_exit_cycle(ngx_link_func_cycle_t* cyc) {
    ngx_link_func_cyc_log(info, cyc, "%s\n", "Shutting down/reloading the Application");

    is_service_on = 0;
}

Compilation:

$ gcc -shared -fPIC -o hello.so hello.c

The shared library is then loaded with:

    server {
        listen       80;
        server_name  localhost;
        ngx_link_func_lib "/usr/local/etc/nginx/hello.so";

        location = /greeting {
            ngx_link_func_call "greeting";
        } 
    }

Starting nginx fails with:

# service nginx start
nginx: [error] function ngx_link_func_init_cycle(ngx_link_func_cycle_t *cycle) not found in "/usr/local/etc/nginx/hello.so", at least create an empty init function block
 Undefined symbol "_nss_cache_cycle_prevention_function" in /usr/local/etc/nginx/nginx.conf:126

But the shared library contains the wanted function:

# nm -D hello.so
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 w __cxa_finalize
00000000000007f4 T _fini
0000000000000510 T _init
00000000000006f7 T greeting
0000000000200bb8 B is_service_on
                 U ngx_link_func_cyc_log_info
0000000000000745 T ngx_link_func_exit_cycle
0000000000000695 T ngx_link_func_init_cycle
                 U ngx_link_func_log_info
                 U ngx_link_func_write_resp
                 U snprintf
@interkosmos
Copy link
Author

A possible fix is to simply call dlerror() before dlsym(scf->_app, (const char*)"ngx_link_func_init_cycle") and dlsym(scf->_app, (const char*)"ngx_link_func_exit_cycle")in ngx_link_func_module.c to clear the error state.

@Taymindis
Copy link
Owner

Hi, it would be great if you could fork and pull request to fix this compatibility issue.

#if __FreeBSD__ 
 
 - flush the dlerror().

#endif

@Taymindis
Copy link
Owner

Hi, Thanks for reporting, new code checked in fixed.

@interkosmos
Copy link
Author

Thank you. Do you mind publishing a new release soon? The FreeBSD port of nginx could be updated then to be compiled with the fix.

@Taymindis
Copy link
Owner

HI @interkosmos , I have just deployed the new release.

https://github.com/Taymindis/nginx-link-function/releases/tag/3.2.2

@interkosmos
Copy link
Author

Thank you for the rapid release. The FreeBSD port of nginx has been updated to include the fix. I recompiled nginx, but unfortunately, the issue is still not resolved. The very same error persists.

@Taymindis
Copy link
Owner

@interkosmos
is your OS FreeBSD or other BSD?

Could you try compile a simple C program and embedded this snippet

#if __FreeBSD__
   printf("I am FreeBSD");
#endif

@interkosmos
Copy link
Author

Example program:

/* test.c */
#include <stdio.h>

int main(void)
{
#if __FreeBSD__
   printf("I am FreeBSD");
#endif

    return 0;
}

Output:

$ uname -a
FreeBSD endeavour 12.1-RELEASE-p3 FreeBSD 12.1-RELEASE-p3 GENERIC  amd64
$ cc -o test test.c
$ ./test
I am FreeBSD

@Taymindis
Copy link
Owner

Taymindis commented Jun 3, 2020

My FreeBSD VM version is

12.1-RELEASE r354233 GENERIC amd64

I could not replicate the issue anymore after i fixed it. The only different is I was not installing from Ports. Maybe you can show me how you install it with Nginx?

Please skype me if you're free live:.cid.307deb505c0a691

Thanks

@interkosmos
Copy link
Author

interkosmos commented Jun 3, 2020

Sorry, I’ve no Skype. But what I did was simply building the Port www/nginx v. 1.18.0_4,2 with LINK option enabled in Poudriere (cd /usr/local/ports/www/nginx/ && make config && make && make install or portmaster www/nginx should work equally). Then, I called pkg install www/nginx to install the (Poudriere-built) package, and service nginx start to start the daemon.

@Taymindis
Copy link
Owner

I replicated the issue, I think the issue is happened when starting nginx for validity checking, I have fixed them and release 3.2.3.

Thanks

@interkosmos
Copy link
Author

Thank you, the FreeBSD port now builds successfully and the issue seems to be solved. I’ve sent the required patches to the port maintainer and suppose that the port will be updated soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants