Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
[nagiosplug.git] / lib / extra_opts.c
index e4251215abf467102972e36723fa133386932a47..2939c7a14e1ad80364c8a822664f4ae41b8b4ee3 100644 (file)
@@ -5,9 +5,6 @@
 * License: GPL
 * Copyright (c) 2007 Nagios Plugins Development Team
 * 
-* Last Modified: $Date: 2008-03-15 18:42:01 -0400 (Sat, 15 Mar 2008) $
-* 
-* 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
@@ -21,8 +18,6 @@
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
-* $Id: parse_ini.c 1950 2008-03-15 22:42:01Z dermoth $
-* 
 *****************************************************************************/
 
 #include "common.h"
 
 /* FIXME: copied from utils.h; we should move a bunch of libs! */
 int
-is_option (char *str)
+is_option2 (char *str)
 {
        if (!str)
-               return 0;
+               return FALSE;
        else if (strspn (str, "-") == 1 || strspn (str, "-") == 2)
-               return 1;
+               return TRUE;
        else
-               return 0;
+               return FALSE;
 }
 
 /* this is the externally visible function used by plugins */
@@ -67,7 +62,7 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){
                        i--;
                        *argc-=1;
                }else if(strcmp(argv[i], "--extra-opts")==0){
-                       if(!is_option(argv[i+1])){
+                       if((i+1<*argc)&&!is_option2(argv[i+1])){
                                /* It is a argument with separate value */
                                argptr=argv[i+1];
                                /* Delete the extra-opts argument/value */
@@ -103,14 +98,13 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){
                                ea_tmp=extra_args;
                                while(ea_tmp->next) {
                                        ea_tmp=ea_tmp->next;
-                                       ea_num++;
                                }
                                ea_tmp->next=ea1;
+                               while(ea1=ea1->next) ea_num++;
                        }
                        ea1=ea_tmp=NULL;
                }
-               /* lather, rince, repeat */
-       }
+       } /* lather, rince, repeat */
 
        if(ea_num==*argc && extra_args==NULL){
                /* No extra-opts */
@@ -122,7 +116,7 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){
        if(argv_new==NULL) die(STATE_UNKNOWN, _("malloc() failed!\n"));
 
        /* starting with program name */
-       argv_new[0]=strdup(argv[0]);
+       argv_new[0]=argv[0];
        argc_new=1;
        /* then parsed ini opts (frying them up in the same run) */
        while(extra_args){
@@ -132,7 +126,7 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){
                free(ea1);
        }
        /* finally the rest of the argv array */
-       for (i=1; i<*argc; i++) argv_new[argc_new++]=strdup(argv[i]);
+       for (i=1; i<*argc; i++) argv_new[argc_new++]=argv[i];
        *argc=argc_new;
        /* and terminate. */
        argv_new[argc_new]=NULL;