1 /* @(#) $Id: agent_op.c,v 1.8 2009/12/01 20:27:01 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
17 /** Checks if syscheck is to be executed/restarted.
18 * Returns 1 on success or 0 on failure (shouldn't be executed now).
20 int os_check_restart_syscheck()
22 struct stat restart_status;
24 /* If the restart is not present, return 0.
29 if(stat(SYSCHECK_RESTART, &restart_status) == -1)
32 unlink(SYSCHECK_RESTART);
36 if(stat(SYSCHECK_RESTART_PATH, &restart_status) == -1)
39 unlink(SYSCHECK_RESTART_PATH);
48 /** Sets syscheck to be restarted.
49 * Returns 1 on success or 0 on failure.
51 int os_set_restart_syscheck()
55 fp = fopen(SYSCHECK_RESTART, "w");
58 merror(FOPEN_ERROR, __local_name, SYSCHECK_RESTART);
62 fprintf(fp, "%s\n", SYSCHECK_RESTART);
71 /** char *os_read_agent_name()
72 * Reads the agent name for the current agent.
73 * Returns NULL on error.
75 char* os_read_agent_name()
82 fp = fopen(AGENT_INFO_FILE, "r");
84 fp = fopen(AGENT_INFO_FILEP, "r");
86 /* We give 1 second for the file to be created... */
92 fp = fopen(AGENT_INFO_FILE, "r");
94 fp = fopen(AGENT_INFO_FILEP, "r");
99 debug1(FOPEN_ERROR, __local_name, AGENT_INFO_FILE);
107 if(fgets(buf, 1024, fp))
122 /** char *os_read_agent_ip()
123 * Reads the agent ip for the current agent.
124 * Returns NULL on error.
126 char *os_read_agent_ip()
131 fp = fopen(AGENT_INFO_FILE, "r");
134 merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE);
142 if(fgets(buf, 1024, fp) && fgets(buf, 1024, fp))
157 /** char *os_read_agent_id()
158 * Reads the agent id for the current agent.
159 * Returns NULL on error.
161 char *os_read_agent_id()
166 fp = fopen(AGENT_INFO_FILE, "r");
169 merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE);
177 if(fgets(buf, 1024, fp) && fgets(buf, 1024, fp) && fgets(buf, 1024, fp))
192 /** int os_write_agent_info(char *agent_name, char *agent_ip, char *agent_id)
193 * Writes the agent info inside the queue, for the other processes to read.
194 * Returns 1 on success or <= 0 on failure.
196 int os_write_agent_info(char *agent_name, char *agent_ip, char *agent_id)
200 fp = fopen(AGENT_INFO_FILE, "w");
203 merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE);
207 fprintf(fp, "%s\n-\n%s\n", agent_name, agent_id);
214 int os_agent_config_changed()