Skip to content
This repository has been archived by the owner on Jun 24, 2023. It is now read-only.

Commit

Permalink
perl is funny
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Jun 7, 2015
1 parent b791a22 commit 544a9c9
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions plugin-perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@

#define xlog_perl(t, ...) xlog(t, "["_PERL_VERSION_"] " __VA_ARGS__)


static PerlInterpreter *my_perl;
static char *perl_args[] = { "", "-e", "0", "-w", NULL };
static int perl_args_count = 4;


/**
Expand Down Expand Up @@ -101,18 +100,22 @@ int proxenet_perl_load_file(plugin_t* plugin)
plugin->pre_function = proxenet_xmalloc(len);
snprintf(plugin->pre_function, len, "%s::%s",
package_name, CFG_REQUEST_PLUGIN_FUNCTION);
#ifdef DEBUG
xlog_perl(LOG_DEBUG, "Loaded '%s'\n", plugin->pre_function);
#endif

/* Save the reponse function path */
len = package_len + 2 + strlen(CFG_RESPONSE_PLUGIN_FUNCTION) + 1;
plugin->post_function = proxenet_xmalloc(len);
snprintf(plugin->post_function, len, "%s::%s",
package_name, CFG_RESPONSE_PLUGIN_FUNCTION);

#ifdef DEBUG
if (cfg->verbose > 2)
xlog_perl(LOG_DEBUG, "Package '%s' loaded\n", package_name);
xlog_perl(LOG_DEBUG, "Loaded '%s'\n", plugin->post_function);
#endif

if (cfg->verbose > 2)
xlog_perl(LOG_INFO, "Package '%s' loaded\n", package_name);

ret = 0;
}
}
Expand All @@ -135,6 +138,8 @@ int proxenet_perl_load_file(plugin_t* plugin)
int proxenet_perl_initialize_vm(plugin_t* plugin)
{
interpreter_t *interpreter;
char *perl_args[] = { "", "/dev/null", NULL };
int perl_args_count = 2;

#ifdef PERL_SYS_INIT3
int a;
Expand All @@ -148,12 +153,6 @@ int proxenet_perl_initialize_vm(plugin_t* plugin)

interpreter = plugin->interpreter;

/* In order to perl_parse nothing */
char *args[2] = {
"",
"/dev/null"
};

/* checks */
if (interpreter->ready)
return 0;
Expand All @@ -172,9 +171,9 @@ int proxenet_perl_initialize_vm(plugin_t* plugin)
return -1;
}

perl_parse(my_perl, NULL, 2, args, (char **)NULL);
perl_parse(my_perl, NULL, perl_args_count, perl_args, (char **)NULL);

interpreter->vm = (void*) PERL_GET_CONTEXT;
interpreter->vm = (void*) my_perl;
interpreter->ready = true;

return 0;
Expand Down Expand Up @@ -240,9 +239,9 @@ static char* proxenet_perl_execute_function(char* fname, long rid, char* request
SPAGAIN;

if (nb_res != 1) {
xlog_perl(LOG_ERROR, "[Perl] Invalid number of response returned (got %d, expected 1)\n", nb_res);
xlog_perl(LOG_ERROR, "Unexpected number of response (got %d, expected 1)\n", nb_res);
} else if (SvTRUE(ERRSV)) {
xlog_perl(LOG_ERROR, "[Perl] call_pv error for '%s': %s\n", fname, SvPV_nolen(ERRSV));
xlog_perl(LOG_ERROR, "call_pv() error for '%s': %s\n", fname, SvPV_nolen(ERRSV));
} else {
sv = POPs;
res = SvPV(sv, len);
Expand Down

0 comments on commit 544a9c9

Please sign in to comment.