Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
@@ -332,6 +332,76 @@ exec_getenv(HOSTNAME, $avp(localhost)); /example /section + section + title + function moreinfo=noneexec(command, [output], [input], [error],[envavp])/function Could you change that to [input], [output], [error] ? That makes sense for everyone familiar with standard unix convention (0=stdin, 1=stdout, 2=stderr). It's not too late to fix now. And add a space before `[envavp]`. --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19524707___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
+ paraemphasiserror/emphasis - pseudovariable where to store the error from + the standard error of the process. + /para + /listitem + listitem + paraemphasisenvavp/emphasis - Avp where to store the values for the + environment variables to be passed for the command. The names of the environment + variables will be OSIPS_EXEC_# where # will start from 0. For example if you + store 2 values into an avp (a and b) OSIPS_EXEC_0 will contain the first value + and OSIPS_EXEC_1 the second value. + /para + /listitem + /itemizedlist + para + WARNING: any OpenSIPS pseudo-vars which may contain special bash + characters should be placed inside quotes, e.g. exec(update-stats.sh '$ct'); This does not help. You need to quote the contents of $ct too, or else I could do this: Contact: sip:'; rm -rf /; echo '@whatever.com --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19524753___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
+ para + WARNING: input/output/error parameters are not designed for a large amount of + data so one should be careful when using them because server could considerably be + slowed down. + /para + para + This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, + LOCAL_ROUTE, STARTUP_ROUTE, TIMER_ROUTE, EVENT_ROUTE, ONREPLY_ROUTE. + /para + example + titlefunction moreinfo=noneexec/function usage/title + programlisting format=linespecific +... +$avp(env) = a; +$avp(env) = b; +exec(ls -l, $var(out),, $avp(env)); This example does not take stderr into account. --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19524764___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
+ /para + para + This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, + LOCAL_ROUTE, STARTUP_ROUTE, TIMER_ROUTE, EVENT_ROUTE, ONREPLY_ROUTE. + /para + example + titlefunction moreinfo=noneexec/function usage/title + programlisting format=linespecific +... +$avp(env) = a; +$avp(env) = b; +exec(ls -l, $var(out),, $avp(env)); +xlog(The output is $var(out)\n); +... +$var(input) = input; +exec(/home/../myscript.sh,, this is my $var(input) for exec\n, $avp(env)); Nor does this. --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19524771___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
@@ -51,6 +51,7 @@ int schedule_to_kill( int pid ); * @stream: stream to be returned to the caller */ pid_t __popen(const char *cmd, const char *type, FILE **stream); +pid_t ___popen(const char *cmd, FILE **, FILE**, FILE**); That's not very inventively named, is it? :-D Python popen2 lib called it popen3: popen2.popen3(cmd[, bufsize[, mode]]) Perhaps `__popen3` is a better name. --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19525000___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
+ if ((buflen + tmplen) = MAX_BUF_SIZE) { + LM_WARN(no more space in output buffer\n); + break; + } + memcpy(buf+buflen, tmpbuf, tmplen); + buflen += tmplen; + + outval.flags = PV_VAL_STR; + outval.rs.s = buf; + outval.rs.len = buflen; + + if (buflen + pv_set_value(msg, outvar-v.pve-spec, 0, outval) 0) { + LM_ERR(cannot set output pv value\n); + return -1; + } Seems redundant to re-set outval.flags and rs.s every iteration (and rs.len for that matter). Shouldn't you move everything from outval.flags to the end of this block to outside the `while{}`? --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19525189___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
+ goto error; + } + + if (ferror(pin)) { + ser_error=E_EXEC; + goto error; + } + pclose(pin); + } + + schedule_to_kill(pid); + wait(exit_status); + + if (outvar) { + if (read_and_write2var(msg, pout, outvar) 0) { + LM_ERR(failed reading from pipe\n); + stdout --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19525389___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
+ return -1; + } + } + + if (errvar) { + if (read_and_write2var(msg, perr, errvar) 0) { + LM_ERR(failed reading stderr from pipe\n); + return -1; + } + } + + ret=1; + +error: + if (outvar ferror(pout)) { + LM_ERR(reading pipe: %s\n, strerror(errno)); `+ stdout` --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19525424___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
+ } + return 0; +} + +static inline int setenvvar(struct hf_wrapper** hf, int_str* value, int idx) +{ + #define OSIPS_EXEC OSIPS_EXEC_ + + + int len=0; + str sidx; + + sidx.s = int2str((unsigned long)idx, sidx.len); + + (*hf)-envvar=pkg_malloc(strlen(OSIPS_EXEC) + sidx.len + 1/*=*/ + + (*value).s.len + 1/*\0*/); `(*value).s` == `value-s`, the latter is more common. Applies to this entire function. --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375/files#r19525529___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
Thanks for fixing the other issues :) --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375#issuecomment-60891337___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
[OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
You can merge this Pull Request by running: git pull https://github.com/ionutrazvanionita/opensips master Or you can view, comment on it, or merge it online at: https://github.com/OpenSIPS/opensips/pull/375 -- Commit Summary -- * added exec(cmd,output,input,error,avpenv) function for exec -- File Changes -- M modules/exec/README (58) M modules/exec/doc/exec_admin.xml (98) M modules/exec/exec.c (179) M modules/exec/exec.h (4) M modules/exec/exec_hf.c (4) M modules/exec/exec_hf.h (3) M modules/exec/exec_mod.c (213) M modules/exec/kill.c (75) M modules/exec/kill.h (1) -- Patch Links -- https://github.com/OpenSIPS/opensips/pull/375.patch https://github.com/OpenSIPS/opensips/pull/375.diff --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375 ___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, error, avpenv) function for exec (#375)
Merged #375. --- Reply to this email directly or view it on GitHub: https://github.com/OpenSIPS/opensips/pull/375#event-184825804___ Devel mailing list Devel@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/devel