1 /* @(#) $Id: ./src/logcollector/read_fullcommand.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2010 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
17 #include "logcollector.h"
21 /* Read Output of commands */
22 void *read_fullcommand(int pos, int *rc, int drop_it)
27 char str[OS_MAXSTR+1];
28 char strfinal[OS_MAXSTR+1];
33 strfinal[OS_MAXSTR]= '\0';
37 debug2("%s: DEBUG: Running full command '%s'", ARGV0, logff[pos].command);
40 cmd_output = popen(logff[pos].command, "r");
43 merror("%s: ERROR: Unable to execute command: '%s'.",
44 ARGV0, logff[pos].command);
46 logff[pos].command = NULL;
50 snprintf(str, 256, "ossec: output: '%s':\n",
51 (NULL != logff[pos].alias)
53 : logff[pos].command);
54 cmd_size = strlen(str);
56 n = fread(str + cmd_size, 1, OS_MAXSTR - OS_LOG_HEADER - 256, cmd_output);
59 str[cmd_size +n] = '\0';
61 /* Getting the last occurence of \n */
62 if ((p = strrchr(str, '\n')) != NULL)
68 debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str);
70 /* Removing empty lines. */
81 if(p[0] == '\n' && p[1] == '\n')
92 /* Sending message to queue */
95 if(SendMSG(logr_queue,strfinal,
96 (NULL != logff[pos].alias) ? logff[pos].alias : logff[pos].command,
99 merror(QUEUE_SEND, ARGV0);
100 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
102 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);