Re: [OpenSIPS-Devel] [opensips] added exec(cmd, output, input, avpenv) function for exec module (#360)

2014-10-28 Thread Ionut Ionita
Closed #360.

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/pull/360#event-184817940___
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, avpenv) function for exec module (#360)

2014-10-17 Thread Walter Doekes
 @@ -243,6 +246,48 @@ exec_getenv(HOSTNAME);
  exec_getenv(HOSTNAME, $avp(localhost));
  ...
  
 +1.4.5.  exec(command, [output], [input], [envavp])
 +
 +   Executes an external command. The input is passed to the
 +   standard input of the new process, if specified, and the output
 +   is saved in the output variable.
 +
 +   Meaning of the parameters is as follows:
 + * command - command to be executed.It can include
 +   pseudovariables.
 + * output - pseudovariable where to store the output from the
 +   standard output of the command. Keep in mind that if this
 +   parameter is set, the async paramater will not be taken in
 +   consideration.

I see that it's not supported in your code.

My point was that if you define the function like you do:

exec(command, [output], [input], [envavp])

it would be quirky to add stderr later:

exec(command, [output], [input], [envavp], [stderr])

You see how the argument order doesn't make sense.

So, it was less of a question of whether it exists, and more of a suggestion to 
add it now, while you're still free to define the function in the most logical 
manner.

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/pull/360/files#r19004237___
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, avpenv) function for exec module (#360)

2014-10-16 Thread Walter Doekes
 + * output - pseudovariable where to store the output from the
 +   standard output of the command. Keep in mind that if this
 +   parameter is set, the async paramater will not be taken in
 +   consideration.
 + * input - String to be passed to the standard input of the
 +   command. The string can be given as a pseudovariable.
 + * envavp - 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.
 +
 +   WARNING: any OpenSIPS pseudo-vars which may contain special
 +   bash characters should be placed inside quotes, e.g.
 +   exec_getenv('$ct');

getenv? And if you require single quotes, shouldn't you also require the 
contents to be quoted? Or a single quote in $ct would undo the first quote...

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/pull/360/files#r18956585___
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, avpenv) function for exec module (#360)

2014-10-16 Thread Walter Doekes
 + } else if (outvar) {
 + pid = __popen(command-s, r, pout);
 + } else {
 + pid = fork();
 + if (pid == 0) {
 + execl(/bin/sh, /bin/sh, -c, command-s, NULL);
 + exit(-1);
 + }
 + }
 +
 + if (input-len) {
 + if (fwrite(input-s, 1, input-len, pin) != input-len) {
 + LM_ERR(failed to write to pipe\n);
 + ser_error=E_EXEC;
 + goto error;
 + }

This will stall if there is lots of output before the input is needed.

Pipes won't buffer an unlimited amount of data, and I doube that FILE streams 
will either.

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/pull/360/files#r18956935___
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, avpenv) function for exec module (#360)

2014-10-16 Thread Ionut Ionita
 @@ -243,6 +246,48 @@ exec_getenv(HOSTNAME);
  exec_getenv(HOSTNAME, $avp(localhost));
  ...
  
 +1.4.5.  exec(command, [output], [input], [envavp])
 +
 +   Executes an external command. The input is passed to the
 +   standard input of the new process, if specified, and the output
 +   is saved in the output variable.
 +
 +   Meaning of the parameters is as follows:
 + * command - command to be executed.It can include
 +   pseudovariables.
 + * output - pseudovariable where to store the output from the
 +   standard output of the command. Keep in mind that if this
 +   parameter is set, the async paramater will not be taken in
 +   consideration.

No. Stderr is not supported.

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/pull/360/files#r18957003___
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, avpenv) function for exec module (#360)

2014-10-16 Thread Walter Doekes
 +
 + if (ferror(pin)) {
 + LM_ERR(writing pipe: %s\n, strerror(errno));
 + ser_error=E_EXEC;
 + goto error;
 + }
 + pclose(pin);
 + }
 +
 + schedule_to_kill(pid);
 + wait(exit_status);
 +
 + if (outvar) {
 + while (fgets(tmpbuf, MAX_LINE_SIZE, pout)) {
 + tmplen = strlen(tmpbuf);
 + memcpy(buf+buflen, tmpbuf, tmplen);

Who checks that buf doesn't overflow? And use fread instead of fgets, since you 
don't care about there the line feeds are.

---
Reply to this email directly or view it on GitHub:
https://github.com/OpenSIPS/opensips/pull/360/files#r18957149___
Devel mailing list
Devel@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel