1 /* Copyright (C) 2010 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_fullcommand(int pos, int *rc, int drop_it)
20 char str[OS_MAXSTR + 1];
21 char strfinal[OS_MAXSTR + 1];
24 str[OS_MAXSTR] = '\0';
25 strfinal[OS_MAXSTR] = '\0';
28 debug2("%s: DEBUG: Running full command '%s'", ARGV0, logff[pos].command);
30 cmd_output = popen(logff[pos].command, "r");
32 merror("%s: ERROR: Unable to execute command: '%s'.",
33 ARGV0, logff[pos].command);
35 logff[pos].command = NULL;
39 snprintf(str, 256, "ossec: output: '%s':\n",
40 (NULL != logff[pos].alias)
42 : logff[pos].command);
43 cmd_size = strlen(str);
45 n = fread(str + cmd_size, 1, OS_MAXSTR - OS_LOG_HEADER - 256, cmd_output);
47 str[cmd_size + n] = '\0';
49 /* Get the last occurrence of \n */
50 if ((p = strrchr(str, '\n')) != NULL) {
54 debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str);
56 /* Remove empty lines */
65 if (p[0] == '\n' && p[1] == '\n') {
74 /* Send message to queue */
76 if (SendMSG(logr_queue, strfinal,
77 (NULL != logff[pos].alias) ? logff[pos].alias : logff[pos].command,
79 merror(QUEUE_SEND, ARGV0);
80 if ((logr_queue = StartMQ(DEFAULTQPATH, WRITE)) < 0) {
81 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);