Module: kamailio Branch: master Commit: 1e1e22c10cdc686fc2b82305990d577aaab7eb58 URL: https://github.com/kamailio/kamailio/commit/1e1e22c10cdc686fc2b82305990d577a...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2019-01-27T21:45:59+01:00
exec: added own exec cmd wrapper not to pass the sip message buffer
---
Modified: src/modules/exec/exec.c Modified: src/modules/exec/exec.h Modified: src/modules/exec/exec_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/1e1e22c10cdc686fc2b82305990d577a... Patch: https://github.com/kamailio/kamailio/commit/1e1e22c10cdc686fc2b82305990d577a...
---
diff --git a/src/modules/exec/exec.c b/src/modules/exec/exec.c index 14c693f95a..6bcf01f74f 100644 --- a/src/modules/exec/exec.c +++ b/src/modules/exec/exec.c @@ -305,3 +305,31 @@ int exec_avp(struct sip_msg *msg, char *cmd, pvname_list_p avpl) } 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; +} diff --git a/src/modules/exec/exec.h b/src/modules/exec/exec.h index 3bc84a7103..45d44f8719 100644 --- a/src/modules/exec/exec.h +++ b/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_msg(struct sip_msg *msg, char *cmd); int exec_avp(struct sip_msg *msg, char *cmd, pvname_list_p avpl); +int exec_cmd(sip_msg_t *msg, char *cmd);
#endif diff --git a/src/modules/exec/exec_mod.c b/src/modules/exec/exec_mod.c index f0e1b986a9..b45e199711 100644 --- a/src/modules/exec/exec_mod.c +++ b/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);
- ret = exec_msg(msg, cmd->s); + ret = exec_cmd(msg, cmd->s);
LM_DBG("execution return code: %d\n", ret);