[OpenSIPS-Users] return code from perl_exec() versus perl_exec_simple()

Bogdan-Andrei Iancu bogdan at opensips.org
Thu Jul 7 11:44:12 CEST 2016


Hi Jeff,

I think the difference is a mis. Could you please test the attached patch.

Regards,

Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
http://www.opensips-solutions.com

On 07.07.2016 04:42, Jeff Pyle wrote:
> Hello,
>
> I'm using 2.1 cloned from git earlier today.  I notice when I use 
> perl_exec_simple(), the return code is always 1, regardless of the 
> return code at the end of the perl function.  With perl_exec(), 
> however, the return code matches the return code in the function.  Is 
> this difference intentional?
>
>
> - Jeff
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20160707/eb02780f/attachment.htm>
-------------- next part --------------
diff --git a/modules/perl/perlfunc.c b/modules/perl/perlfunc.c
index f3b0f2e..68a9509 100644
--- a/modules/perl/perlfunc.c
+++ b/modules/perl/perlfunc.c
@@ -54,18 +54,37 @@ int perl_checkfnc(char *fnc) {
  * Run function without parameters
  */
 
-int perl_exec_simple(char* fnc, char* args[], int flags) {
+int perl_exec_simple(char* fnc, char* args[], int flags)
+{
+	dSP;
+	int ret;
+	int cnt;
 
 	if (perl_checkfnc(fnc)) {
 		LM_DBG("running perl function \"%s\"", fnc);
 
-		call_argv(fnc, flags, args);
-	} else {
-		LM_ERR("unknown function '%s' called.\n", fnc);
-		return -1;
-	}
+		ENTER;
+		SAVETMPS;
+
+		cnt = call_argv(fnc, flags, args);
 
-	return 1;
+		SPAGAIN;
+
+		if (cnt!=1) {
+			LM_ERR("function %s failed to return anything\n",fnc);
+			ret = -1;
+		} else {
+			ret = POPi;
+			PUTBACK;
+		}
+
+		FREETMPS;
+		LEAVE;
+
+		return ret;
+	}
+	LM_ERR("unknown function '%s' called.\n", fnc);
+	return -1;
 }
 
 int perl_exec_simple1(struct sip_msg* _msg, char* fnc, char* str2) {


More information about the Users mailing list