3 /* Copyright (C) 2009 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_command(int pos, int *rc, int drop_it)
25 char str[OS_MAXSTR+1];
33 debug2("%s: DEBUG: Running command '%s'", ARGV0, logff[pos].command);
36 cmd_output = popen(logff[pos].command, "r");
39 merror("%s: ERROR: Unable to execute command: '%s'.",
40 ARGV0, logff[pos].command);
42 logff[pos].command = NULL;
46 snprintf(str, 256, "ossec: output: '%s': ",
47 (NULL != logff[pos].alias)
49 : logff[pos].command);
50 cmd_size = strlen(str);
53 while(fgets(str + cmd_size, OS_MAXSTR - OS_LOG_HEADER - 256, cmd_output) != NULL)
55 /* Getting the last occurence of \n */
56 if ((p = strrchr(str, '\n')) != NULL)
61 /* Removing empty lines. */
63 if(str[0] == '\r' && str[1] == '\0')
74 debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str);
77 /* Sending message to queue */
80 if(SendMSG(logr_queue,str,
81 (NULL != logff[pos].alias) ? logff[pos].alias : logff[pos].command,
84 merror(QUEUE_SEND, ARGV0);
85 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
87 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);