Bläddra i källkod

exec: added own exec cmd wrapper not to pass the sip message buffer

Daniel-Constantin Mierla 6 år sedan
förälder
incheckning
1e1e22c10c
3 ändrade filer med 30 tillägg och 1 borttagningar
  1. 28 0
      src/modules/exec/exec.c
  2. 1 0
      src/modules/exec/exec.h
  3. 1 1
      src/modules/exec/exec_mod.c

+ 28 - 0
src/modules/exec/exec.c

@@ -305,3 +305,31 @@ error:
 	}
 	}
 	return ret;
 	return ret;
 }
 }
+
+int exec_cmd(sip_msg_t *msg, char *cmd)
+{
+	FILE *pipe;
+	int exit_status;
+	int ret;
+
+	pipe = popen(cmd, "r");
+	if(pipe == NULL) {
+		LM_ERR("cannot open pipe: %s\n", cmd);
+		ser_error = E_EXEC;
+		return -1;
+	}
+
+	ret = 1;
+	exit_status = pclose(pipe);
+	if(WIFEXITED(exit_status)) { /* exited properly .... */
+		/* return false if script exited with non-zero status */
+		if(WEXITSTATUS(exit_status) != 0)
+			ret = -1;
+	} else { /* exited erroneously */
+		LM_ERR("cmd %s failed. exit_status=%d, errno=%d: %s\n", cmd,
+				exit_status, errno, strerror(errno));
+		ret = -1;
+	}
+
+	return ret;
+}

+ 1 - 0
src/modules/exec/exec.h

@@ -32,5 +32,6 @@
 int exec_str(struct sip_msg *msg, char *cmd, char *param, int param_len);
 int exec_str(struct sip_msg *msg, char *cmd, char *param, int param_len);
 int exec_msg(struct sip_msg *msg, char *cmd);
 int exec_msg(struct sip_msg *msg, char *cmd);
 int exec_avp(struct sip_msg *msg, char *cmd, pvname_list_p avpl);
 int exec_avp(struct sip_msg *msg, char *cmd, pvname_list_p avpl);
+int exec_cmd(sip_msg_t *msg, char *cmd);
 
 
 #endif
 #endif

+ 1 - 1
src/modules/exec/exec_mod.c

@@ -277,7 +277,7 @@ static int ki_exec_cmd(sip_msg_t *msg, str *cmd)
 
 
 	LM_DBG("executing [%s]\n", cmd->s);
 	LM_DBG("executing [%s]\n", cmd->s);
 
 
-	ret = exec_msg(msg, cmd->s);
+	ret = exec_cmd(msg, cmd->s);
 
 
 	LM_DBG("execution return code: %d\n", ret);
 	LM_DBG("execution return code: %d\n", ret);