Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
[nagiosplug.git] / plugins / popen.c
index a7e6f9b2f238c202297c95256f5287f530e47059..716bd524042c54b99ed2f69034436a62340e28de 100644 (file)
@@ -1,48 +1,42 @@
-/****************************************************************************
- *
- * Nagios plugins popen
- *
- * License: GPL
- * Copyright (c) 2005 nagios-plugins team
- *
- * Last Modified: $Date$
- *
- * Description:
- *
- * A safe alternative to popen
- * 
- * Provides spopen and spclose
- *
- * FILE * spopen(const char *);
- * int spclose(FILE *);
- *
- *
- * Code taken with liitle modification from "Advanced Programming for the Unix
- * Environment" by W. Richard Stevens
- *
- * This is considered safe in that no shell is spawned, and the environment and
- * path passed to the exec'd program are esstially empty. (popen create a shell
- * and passes the environment to it).
- *
- * License Information:
- *
- * 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
- *
- * $Id$
- *
- ******************************************************************************/
+/*****************************************************************************
+* 
+* Nagios plugins popen
+* 
+* License: GPL
+* Copyright (c) 2005-2007 Nagios Plugins Development Team
+* 
+* Description:
+* 
+* A safe alternative to popen
+* 
+* Provides spopen and spclose
+* 
+* FILE * spopen(const char *);
+* int spclose(FILE *);
+* 
+* Code taken with liitle modification from "Advanced Programming for the Unix
+* Environment" by W. Richard Stevens
+* 
+* This is considered safe in that no shell is spawned, and the environment
+* and path passed to the exec'd program are essentially empty. (popen create
+* a shell and passes the environment to it).
+* 
+* 
+* 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
+* (at your option) any later version.
+* 
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+* 
+* You should have received a copy of the GNU General Public License
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+* 
+* 
+*****************************************************************************/
 
 #include "common.h"
 
@@ -143,7 +137,7 @@ spopen (const char *cmdstring)
        /* there cannot be more args than characters */
        argc = strlen (cmdstring) + 1;  /* add 1 for NULL termination */
        argv = malloc (sizeof(char*)*argc);
-       
+
        if (argv == NULL) {
                printf ("%s\n", _("Could not malloc argv array in popen()"));
                return NULL;
@@ -168,7 +162,7 @@ spopen (const char *cmdstring)
                }
                else if (strcspn(str,"'") < strcspn (str, " \t\r\n")) {
                                                                                /* handle --option='foo bar' strings */
-                       tmp = str + strcspn(str, "'") + 1; 
+                       tmp = str + strcspn(str, "'") + 1;
                        if (!strstr (tmp, "'"))
                                return NULL;                                            /* balanced? */
                        tmp += strcspn(tmp,"'") + 1;
@@ -188,7 +182,6 @@ spopen (const char *cmdstring)
                        cmd = NULL;
 
                argv[i++] = str;
-               printf("arg no.%i: %s\n",i,str);
 
        }
        argv[i] = NULL;