1 /* @(#) $Id: read_command.c,v 1.3 2009/11/05 19:55:34 dcid Exp $ */
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 3) 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': ", logff[pos].command);
47 cmd_size = strlen(str);
50 while(fgets(str + cmd_size, OS_MAXSTR - OS_LOG_HEADER - 256, cmd_output) != NULL)
52 /* Getting the last occurence of \n */
53 if ((p = strrchr(str, '\n')) != NULL)
58 debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str);
61 /* Sending message to queue */
64 if(SendMSG(logr_queue,str,logff[pos].command,
67 merror(QUEUE_SEND, ARGV0);
68 if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0)
70 ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH);