[Nagiosplug-devel] Patch for popen.c and check_snmp.c allowing environment to be pas sed

Subhendu Ghosh sghosh at sghosh.org
Wed Jun 19 12:32:08 CEST 2002


In this particular case - you should be able to solve the ld issue by 
editing /etc/ld.so.conf (linux variants) or running crle (solaris)

could you post the patch on sourceforge so we can keep track of it.

tia.
-sg

On Wed, 19 Jun 2002, Karl Ewald wrote:

> Hi developers,
> 
> We have found the need to pass an environment variable to the process called
> by check_snmp (snmpget). In the particular case, this may well be attributed
> to my stupidity while building ucd-snmp, however I can foresee valid reasons
> for wanting to pass an environment to a called program. The following patch
> permits doing this.
> 
> One could also choose to pass the environment inherited, which would be
> somewhat more natural, but it was actually beneficial to us to ensure a
> well-defined state when executing the external program. The definition of
> CHILD_ENV_ARRAY would probably be better placed in the Makefile, however I
> didn't want to touch too many files to keep the change tightly contained. My
> setting can only serve as an example.
> 
> 1.1 is my own version number for each file as distributed with
> netsaint-plugins-1.2.9-4
> 
> I hope it is of some use to you.
> 
> ============================================================================
> ========
> diff -u -r1.1 popen.c
> --- popen.c     2002/06/19 17:20:31     1.1
> +++ popen.c     2002/06/19 18:40:23
> @@ -6,6 +6,7 @@
>   * Provides spopen and spclose
> 
>  FILE * spopen(const char *);
> +FILE *spopene(const char *,const char *[]);
>  int spclose(FILE *);
> 
>   *
> @@ -28,6 +29,7 @@
>  extern FILE *child_process;
> 
>  FILE *spopen(const char *);
> +FILE *spopene(const char *,const char *[]);
>  int spclose(FILE *);
>  RETSIGTYPE popen_timeout_alarm_handler(int);
> 
> @@ -67,6 +69,13 @@
>  FILE *spopen(const char *cmdstring)
>  {
>    char *environ[] = {  NULL };
> +
> +  return(spopene(cmdstring,environ));
> +}
> +
> +FILE *spopene(const char *cmdstring, const char *environ[])
> +{
> +
>    char *cmd=NULL;
>    char **argv=NULL;
>    char *str;
> ============================================================================
> ========
> diff -u -r1.1 popen.h
> --- popen.h     2002/06/19 18:26:48     1.1
> +++ popen.h     2002/06/19 18:27:42
> @@ -1,5 +1,6 @@
>  /* plugins/popen.h.  Generated automatically by configure.  */
>  FILE *spopen(const char *);
> +FILE *spopene(const char *,const char *[]);
>  int spclose(FILE *);
>  RETSIGTYPE popen_timeout_alarm_handler(int);
> 
> ============================================================================
> ========
> diff -u -r1.1 check_snmp.c
> --- check_snmp.c        2002/06/19 17:03:20     1.1
> +++ check_snmp.c        2002/06/19 19:03:38
> @@ -37,6 +37,9 @@
>  #include "utils.h"
>  #include "popen.h"
> 
> +/* this should go into the makefile */
> +#define CHILD_ENV_ARRAY { "LD_LIBRARY_PATH=/usr/local/lib", NULL }
> +
>  #define PROGNAME check_snmp
> 
>  #define mark(a) ((a)!=0?"*":"")
> @@ -132,6 +135,7 @@
>         char *ptr = NULL;
>         char *p2 = NULL;
>         char *show = NULL;
> +       char *environ[] = CHILD_ENV_ARRAY;
> 
>         labels = malloc(labels_size);
>         unitv = malloc(unitv_size);
> @@ -156,7 +160,7 @@
>         }
> 
>         /* run the command */
> -       child_process = spopen(command_line);
> +       child_process = spopene(command_line,environ);
>         if (child_process == NULL) {
>                 printf("Could not open pipe: %s\n", command_line);
>                 exit(STATE_UNKNOWN);
> ============================================================================
> ========
> 
> Happy merging,
> 
> Karl Ewald
> IT Services
> IXOS Software AG, Bretonischer Ring 12, 85630 Grasbrunn
> Tel. +49.89.4629.1350, Fax +49.89.4629.331350
> 
> 
> ----------------------------------------------------------------------------
>                    Bringing you mounds of caffeinated joy
>                    >>>     http://thinkgeek.com/sf    <<<
> 
> _______________________________________________
> Nagiosplug-devel mailing list
> Nagiosplug-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
> 

-- 







More information about the Devel mailing list