3 /* Copyright (C) 2010 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
16 #include "logcollector.h"
20 /* Read Output of commands */
21 void *read_fullcommand(int pos, int *rc, int drop_it)
26 char str[OS_MAXSTR+1];
27 char strfinal[OS_MAXSTR+1];
32 strfinal[OS_MAXSTR]= '\0';
36 debug2("%s: DEBUG: Running full command '%s'", ARGV0, logff[pos].command);
39 cmd_output = popen(logff[pos].command, "r");
42 merror("%s: ERROR: Unable to execute command: '%s'.",
43 ARGV0, logff[pos].command);
45 logff[pos].command = NULL;
49 snprintf(str, 256, "ossec: output: '%s':\n",
50 (NULL != logff[pos].alias)
52 : logff[pos].command);
53 cmd_size = strlen(str);
55 n = fread(str + cmd_size, 1, OS_MAXSTR - OS_LOG_HEADER - 256, cmd_output);
58 str[cmd_size +n] = '\0';
60 /* Getting the last occurence of \n */
61 if ((p = strrchr(str, '\n')) != NULL)
67 debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str);
69 /* Removing empty lines. */
80 if(p[0] == '\n' && p[1] == '\n')
91 /* Sending message to queue */
94 if(SendMSG(logr_queue,strfinal,
95 (NULL != logff[pos].alias) ? logff[pos].alias : logff[pos].command,
98 merror(QUEUE_SEND, ARGV0);
99 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
101 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);