Code

Fix --help output when MAX_OIDS is altered.
[nagiosplug.git] / lib / utils_cmd.c
index aaf055a9f0a86c228fe00daf85e2035b08f6d778..0c853dcc687d99ba2479e43c40edfa5d37fa6f22 100644 (file)
@@ -5,8 +5,6 @@
 * License: GPL
 * Copyright (c) 2005-2006 Nagios Plugins Development Team
 *
-* Last Modified: $Date$
-*
 * Description :
 *
 * A simple interface to executing programs from other programs, using an
@@ -35,7 +33,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$
 *
 *****************************************************************************/
 
 #include "common.h"
 #include "utils_cmd.h"
 #include "utils_base.h"
+#include <fcntl.h>
 
 #ifdef HAVE_SYS_WAIT_H
 # include <sys/wait.h>
 #endif
 
+/* used in _cmd_open to pass the environment to commands */
+extern char **environ;
+
 /** macros **/
 #ifndef WEXITSTATUS
 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
@@ -124,7 +125,6 @@ cmd_init (void)
 static int
 _cmd_open (char *const *argv, int *pfd, int *pfderr)
 {
-       char *env[2];
        pid_t pid;
 #ifdef RLIMIT_CORE
        struct rlimit limit;
@@ -139,8 +139,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr)
        if (!_cmd_pids)
                CMD_INIT;
 
-       env[0] = strdup ("LC_ALL=C");
-       env[1] = '\0';
+       setenv("LC_ALL", "C", 1);
 
        if (pipe (pfd) < 0 || pipe (pfderr) < 0 || (pid = fork ()) < 0)
                return -1;                                                                      /* errno set by the failing function */
@@ -171,7 +170,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr)
                        if (_cmd_pids[i] > 0)
                                close (i);
 
-               execve (argv[0], argv, env);
+               execve (argv[0], argv, environ);
                _exit (STATE_UNKNOWN);
        }
 
@@ -377,3 +376,20 @@ cmd_run_array (char *const *argv, output * out, output * err, int flags)
 
        return _cmd_close (fd);
 }
+
+int
+cmd_file_read ( char *filename, output *out, int flags)
+{
+       int fd;
+       if(out)
+               memset (out, 0, sizeof(output));
+
+       if ((fd = open(filename, O_RDONLY)) == -1) {
+               die( STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno) );
+       }
+       
+       if(out)
+               out->lines = _cmd_fetch_output (fd, out, flags);
+
+       return 0;
+}