1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
11 #include "logcollector.h"
14 /* Read Output of commands */
15 void *read_command(int pos, int *rc, int drop_it)
19 char str[OS_MAXSTR + 1];
22 str[OS_MAXSTR] = '\0';
25 debug2("%s: DEBUG: Running command '%s'", ARGV0, logff[pos].command);
27 cmd_output = popen(logff[pos].command, "r");
29 merror("%s: ERROR: Unable to execute command: '%s'.",
30 ARGV0, logff[pos].command);
32 logff[pos].command = NULL;
36 snprintf(str, 256, "ossec: output: '%s': ",
37 (NULL != logff[pos].alias)
39 : logff[pos].command);
40 cmd_size = strlen(str);
42 while (fgets(str + cmd_size, OS_MAXSTR - OS_LOG_HEADER - 256, cmd_output) != NULL) {
43 /* Get the last occurrence of \n */
44 if ((p = strrchr(str, '\n')) != NULL) {
48 /* Remove empty lines */
50 if (str[0] == '\r' && str[1] == '\0') {
58 debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str);
60 /* Send message to queue */
62 if (SendMSG(logr_queue, str,
63 (NULL != logff[pos].alias) ? logff[pos].alias : logff[pos].command,
65 merror(QUEUE_SEND, ARGV0);
66 if ((logr_queue = StartMQ(DEFAULTQPATH, WRITE)) < 0) {
67 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);