[Nagiosplug-devel] complication executing one plugin by another

Bob Ingraham bobi at netshel.net
Thu Sep 22 13:33:22 CEST 2005


I have an idea...  :-)

It seems to me that the plugins are always executed with full path
information contained in argv[0], since the nrpe.cfg file usually contains
the full path information and this is what nrpe use to exec() these
plugins.

Therefore, if you know that you want to execute a fellow plugin (why does
that not sound right? ;-) ), then all you need do is extract the full path
info from main's argv[0] vector, and use that to construct the path the
"peer" plugin.

Something like:

#define PS_COMMAND   "pst3"   /* From config.h */

#ifdef WINDOZE
#define PATH_DELIMITER '\\'
#else
#define PATH_DELIMITER '/'
#endif

int main (int argc, char **argv)
{
    char PluginPath[MAX_PATH+1], *cp;

    /* ...  snip ... */

    /* Build the path to our co-plugin */
    strcpy(PluginPath, argv[0]);
    if ((cp = strrchr(PluginPath, PATH_DELIMITER)) != NULL)
        strcpy(cp+1, PS_COMMAND);
    else  /* No path prefix found - assume that the system path works */
        strcpy(PluginPath, PS_COMMAND);

    /* Now use the spopen() command to exec our co-plugin */
    child_process = spopen (PS_COMMAND);

   /* ...  snip ... */
}

Hope this is helpful...

Bob

> if you've read the subject, you may be thinking "why the hell would
> you want to do that?"
>
> one example is the latest modification i've made (or half-made,
> hence the email) to check_procs, to call the pst3 program submitted
> by bob ingraham, which will also reside in the plugin installation
> dir.
>
> the problem is that to execute pst3, one has to either supply the
> full path or assume that it is in the path.  the problem with the
> latter is that it probably will not be in the system path, and
> the problem with the former is that i can't figure out a good way
> to supply the path to the plugin.
>
> so, i see a couple iof options here:
>
> - modify configure.in, config.h and/or Makefile.am's to pass the
>   information at compile-time
> - modify check_procs to include the pst3 code natively, making this
>   a moot issue.
>
> comments?  in the meantime, i'll leave the CVS HEAD configure.in script
> with ac_cv_ps_command="pst3" (no path), so if someone cares they
> can copy the binary into their paths.  if i don't hear back, i think
> i'll try and work with option 2.
>
>
> 	sean
>





More information about the Devel mailing list