Perl Inline C code inside nginx Perl module

Maxim Dounin mdounin at
Fri Apr 13 14:03:40 UTC 2018


On Fri, Apr 13, 2018 at 02:40:17AM +0200, Ondrej Jombik wrote:

> We have some proprietary code in C language, which we cannot convert
> into Perl. We would like to use this C code in Perl nginx module. Code
> runs well under Perl's Inline C.
> However when I try to run Inline C code in nginx Perl module, it does
> not work. Not only this code does not work, in fact no Inline C code
> work inside Perl nginx environment.
> For example, look at this very simple Perl module
> package inlinetest;
> use strict;
> use nginx;
> $ENV{'PATH'} = '/bin/:/usr/bin/';
> use Inline Config =>
>  		DIRECTORY => '/tmp/';
> use Inline "C" => <<'...';
>  	void test_fnc(int num)
>  	{
>  		fprintf(stderr, "%d\n", num);
>  	}


> As you can see in my example, I am not even using or calling test_fnc()
> yet. But Perl code simply fails on startup with this error message:
> -- Unit nginx.service has begun starting up.
> nginx[20011]: nginx: [emerg] require_pv("") failed: "Running Mkbootstrap for inlinetest_0cff 
> nginx[20011]: chmod 644 ""
> nginx[20011]: "/usr/bin/perl" "/usr/share/perl/5.24/ExtUtils/xsubpp"  -typemap "/usr/share/perl/5.24/ExtUt
> nginx[20011]: x86_64-linux-gnu-gcc -c  -I"/" -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-alias
> nginx[20011]: x86_64-linux-gnu-gcc: error trying to exec 'cc1': execvp: No such file or directory
> nginx[20011]: Makefile:332: recipe for target 'inlinetest_0cff.o' failed

The problem is that your PATH is empty when relevant compilation 
happens.  You try to set it in the code using "$ENV{'PATH'} = 
...", but it doesn't work as this happens _after_ "use Inline...", 
because "use ..." operators are executed at compile time in Perl, 
much like BEGIN{}.

A simple fix would be to set PATH in a BEGIN{} block at compile 

BEGIN { $ENV{'PATH'} = '/bin/:/usr/bin/'; }
use Inline ...

Alternativel, you can use nginx "env" directive to set PATH or 
preserve it from original environment, see

Maxim Dounin

More information about the nginx mailing list