Bläddra i källkod

app_ruby: detect if the exception is a script exit

Daniel-Constantin Mierla 6 år sedan
förälder
incheckning
97189d7508
1 ändrade filer med 13 tillägg och 7 borttagningar
  1. 13 7
      src/modules/app_ruby/app_ruby_api.c

+ 13 - 7
src/modules/app_ruby/app_ruby_api.c

@@ -95,15 +95,20 @@ int ruby_sr_init_mod(void)
 	return 0;
 	return 0;
 }
 }
 
 
-static void app_ruby_print_last_exception()
+static int app_ruby_print_last_exception()
 {
 {
 	VALUE rException, rExceptStr;
 	VALUE rException, rExceptStr;
 
 
 	rException = rb_errinfo();         /* get last exception */
 	rException = rb_errinfo();         /* get last exception */
 	rb_set_errinfo(Qnil);              /* clear last exception */
 	rb_set_errinfo(Qnil);              /* clear last exception */
 	rExceptStr = rb_funcall(rException, rb_intern("to_s"), 0, Qnil);
 	rExceptStr = rb_funcall(rException, rb_intern("to_s"), 0, Qnil);
-	LM_ERR("exception: %s\n", StringValuePtr(rExceptStr));
-	return;
+	if(RSTRING_LEN(rExceptStr)!=4
+			|| strncmp(RSTRING_PTR(rExceptStr), "exit", 4)!=0) {
+		LM_ERR("exception: %.*s\n", (int)RSTRING_LEN(rExceptStr),
+				RSTRING_PTR(rExceptStr));
+		return 0;
+	}
+	return 1;
 }
 }
 
 
 /**
 /**
@@ -1073,10 +1078,11 @@ int app_ruby_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
 	_sr_R_env.msg = bmsg;
 	_sr_R_env.msg = bmsg;
 
 
 	if (rberr) {
 	if (rberr) {
-		app_ruby_print_last_exception();
-		LM_ERR("ruby exception (%d) on callback for: %s (res type: %d)\n",
-				rberr, func, TYPE(rbres));
-		return -1;
+		if(app_ruby_print_last_exception()==0) {
+			LM_ERR("ruby exception (%d) on callback for: %s (res type: %d)\n",
+					rberr, func, TYPE(rbres));
+			return -1;
+		}
 	}
 	}
 
 
 	return 1;
 	return 1;