[ic] system() call in usertag, again... :(

Daniel Davenport ddavenport at newagedigital.com
Thu Jul 29 09:29:35 EDT 2004

> -----Original Message-----
> From: interchange-users-bounces at icdevgroup.org
> [mailto:interchange-users-bounces at icdevgroup.org]On Behalf Of Carsten
> Jahnke
> Sent: Thursday, July 29, 2004 3:30 AM
> To: interchange-users at icdevgroup.org
> Subject: [ic] system() call in usertag, again... :(
> Hi list,
> I have perlscript that I want to be executed by a
> system("perl /path/to/script parameters "); command in a controlling
> usertag. It starts fine but it just breaks up after a while. the runtime
>   varies from start to start. sometimes I also get it to run completely
> through the script!
> Unfortunately I get no response of what lets IC stop the execution of
> the script. It just drops out with some strange return values of 265 or
> so...

as far as i am aware, system() is a per-program thing; that is, a program
saying "system 'program1'", which in turn says "system 'program2'", etc.,
shouldn't cause any problem.

Non-zero return values from a system() call usually indicate that the
program that was run (or in some cases one of the programs _it_ ran) had
problems, especially if the return value is 256 or a multiple thereof (a
return value of 256 is equivalent to a program calling exit(1), which is a
common way for programs to signal a generic error). It could be that the
problem isn't with perl, but with the values you're passing to the programs
or the permissions of the account running the script (which, in a usertag,
is often 'interch').

If you had sample code, it'd be a bit easier to tell.

Side note: If you're trying to get the output of the program, you should be
using backquotes (`these things`).  system() doesn't return the
output...just the error code.

> Could it be faulty to call a perlscript with system("...") which itself
> also calls various programms with system("..") (e.g. mysqladmin)?

It's bad, but the reason has nothing to do with perl.  system("...") in most
languages/environments is pretty reckless in its operation; changing the
values of $IFS, $PATH, and any number of other environment variables can
cause a system() call to go horribly wrong.  That's why it's usually a very
bad idea to use it the way you're trying to.  A safer way is to use the
multi-argument form; instead of system("/path/to/program arg1 arg2"), using
system("/path/to/program", "arg1", "arg2") leaves the shell less of a chance
to misinterpret what you want it to do.

BTW....notice that i said "/path/to/program" instead of "program".  If you
insist on using the system() call, you should be as specific as possible
about what program you want to run (for security's sake).

Design note: If you find yourself using a whole lot of system() calls,
perhaps you should be writing a shell script instead.  Aside from the
security features you seem intent on circumventing, a shell script can do
most of the same things that a perl script can (esp when you count the
abilities of sed and awk, from which perl learned about regexps).

> When I run the same script by hand there are absolutely no errors :(

It's quite possible that interchange's user account doesn't have certain
permissions you're taking for granted...or that the script does in fact
return an error, but you don't see it because exit codes aren't normally
printed out.

Looking back, i have to wonder if you (or the scripts you're calling) are
trying to print stuff that you want included in the tag's output.

> Using backticks causes the same strange behavior.

Backticks and system() return two different things--one returns the output
from the program (that is, whatever was printed to STDOUT), and the other
returns the exit code (that is, the value passed to exit()).

The fact that you're trying to use one in place of the other suggests to me
that you're confused about which does which.

> I have no messages in <ic_dir>/error.log or <catroot>/error.log

You wouldn't.  If the tag interpolates to a value (no matter how funky),
then that means that the UserTag's routine succeeded...and that's all that
interchange cares about.  The problem isn't in interchange or in perl...it's
in your script.

Without sample code, though, the above is about all i can offer regarding
what the problem might be.

> What is the problem about calling a perlscript by using system() in a
> usertag?

The only problem i see is that it's horribly insecure.  That, and you might
be using it wrong to begin with.  :P


More information about the interchange-users mailing list