1 /* @(#) $Id: ./src/logcollector/read_command.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 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_command(int pos, int *rc, int drop_it)
26 char str[OS_MAXSTR+1];
34 debug2("%s: DEBUG: Running command '%s'", ARGV0, logff[pos].command);
37 cmd_output = popen(logff[pos].command, "r");
40 merror("%s: ERROR: Unable to execute command: '%s'.",
41 ARGV0, logff[pos].command);
43 logff[pos].command = NULL;
47 snprintf(str, 256, "ossec: output: '%s': ",
48 (NULL != logff[pos].alias)
50 : logff[pos].command);
51 cmd_size = strlen(str);
54 while(fgets(str + cmd_size, OS_MAXSTR - OS_LOG_HEADER - 256, cmd_output) != NULL)
56 /* Getting the last occurence of \n */
57 if ((p = strrchr(str, '\n')) != NULL)
62 /* Removing empty lines. */
64 if(str[0] == '\r' && str[1] == '\0')
75 debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str);
78 /* Sending message to queue */
81 if(SendMSG(logr_queue,str,
82 (NULL != logff[pos].alias) ? logff[pos].alias : logff[pos].command,
85 merror(QUEUE_SEND, ARGV0);
86 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
88 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);