FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
agent.h
Go to the documentation of this file.
1 /* **************************************************************
2 Copyright (C) 2010, 2011, 2012 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 ************************************************************** */
17 
18 #ifndef AGENT_H_INCLUDE
19 #define AGENT_H_INCLUDE
20 
21 /* local includes */
22 #include <host.h>
23 #include <job.h>
24 #include <scheduler.h>
25 
26 /* unix library includes */
27 #include <sys/types.h>
28 
29 /* glib includes */
30 #include <gio/gio.h>
31 #include <glib.h>
32 
33 /* ************************************************************************** */
34 /* **** Data Types ********************************************************** */
35 /* ************************************************************************** */
36 
37 #define MAX_CMD 1023
38 #define MAX_NAME 255
39 #define MAX_ARGS 32
40 #define DEFAULT_RET -1
41 
42 #define LOCAL_HOST "localhost"
43 
44 #define SAG_NOKILL (1 << 0)
45 #define SAG_EXCLUSIVE (1 << 1)
46 #define SAG_NOEMAIL (1 << 2)
47 #define SAG_LOCAL (1 << 3)
48 
49 
61 #define AGENT_STATUS_TYPES(apply) \
62  \
63  apply(FAILED) \
64  \
65  apply(CREATED) \
66  \
67  apply(SPAWNED) \
68  \
69  apply(RUNNING) \
70  \
71  apply(PAUSED) \
72  \
73  apply(CLOSED) \
74 
75 
76 #define SELECT_ENUM(passed) AG_##passed,
77 typedef enum { AGENT_STATUS_TYPES(SELECT_ENUM) } agent_status;
78 #undef SELECT_ENUM
79 
80 extern const char* agent_status_strings[];
81 
85 typedef int agent_pk;
86 
92 typedef struct
93 {
94  char name[256];
95  char raw_cmd[MAX_CMD + 1];
96  int max_run;
97  int special;
99  char* version;
100  int valid;
101  int run_count;
102 } meta_agent_t;
103 
110 typedef struct
111 {
112  /* we need all the information on creating the agent */
115 
116  /* thread management */
117  agent_status status;
118  GThread* thread;
119  time_t check_in;
120  uint8_t n_updates;
121  pid_t pid;
122 
123  /* pipes connecting to the child */
125  int to_child;
127  int to_parent;
128  FILE* read;
129  FILE* write;
130 
131  /* data management */
133  gchar* data;
134  gboolean updated;
135  uint64_t total_analyzed;
136  gboolean alive;
137  uint8_t return_code;
138  uint32_t special;
139 } agent_t;
140 
141 /* ************************************************************************** */
142 /* **** Constructor Destructor ********************************************** */
143 /* ************************************************************************** */
144 
145 /* meta agent */
146 meta_agent_t* meta_agent_init(char* name, char* cmd, int max, int spc);
147 void meta_agent_destroy(meta_agent_t* meta_agent);
148 
149 /* agent */
150 agent_t* agent_init(scheduler_t* scheduler, host_t* host, job_t* owner);
151 void agent_destroy(agent_t* agent);
152 
153 /* ************************************************************************** */
154 /* **** Modifier Functions and events *************************************** */
155 /* ************************************************************************** */
156 
157 void agent_death_event(scheduler_t* scheduler, pid_t* pids);
158 void agent_create_event(scheduler_t* scheduler, agent_t* agent);
159 void agent_ready_event(scheduler_t* scheduler, agent_t* agent);
160 void agent_update_event(scheduler_t* scheduler, void* unused);
161 void agent_fail_event(scheduler_t* scheduler, agent_t* agent);
162 void list_agents_event(scheduler_t* scheduler, GOutputStream* ostr);
163 
164 void agent_transition(agent_t* agent, agent_status new_status);
165 void agent_pause(agent_t* agent);
166 void agent_unpause(agent_t* agent);
167 void agent_print_status(agent_t* agent, GOutputStream* ostr);
168 void agent_kill(agent_t* agent);
169 int aprintf(agent_t* agent, const char* fmt, ...);
170 ssize_t agent_write(agent_t* agent, const void* buf, int count);
171 
172 /* ************************************************************************** */
173 /* **** static functions and meta agents ************************************ */
174 /* ************************************************************************** */
175 
176 void test_agents(scheduler_t* scheduler);
177 int add_meta_agent(GTree* meta_agents, char* name, char* cmd, int max, int spc);
178 
179 void kill_agents(scheduler_t* scheduler);
180 
181 int is_meta_special(meta_agent_t* ma, int special_type);
182 int is_agent_special(agent_t* agent, int special_type);
183 
186 
187 #endif /* AGENT_H_INCLUDE */
gboolean alive
flag to tell the scheduler if the agent is still alive
Definition: agent.h:136
uint8_t n_updates
keeps track of the number of times the agent has updated
Definition: agent.h:120
void list_agents_event(scheduler_t *scheduler, GOutputStream *ostr)
Receive agent on interface.
Definition: agent.c:1129
int is_agent_special(agent_t *agent, int special_type)
tests if a particular agent has a specific special flag set
Definition: agent.c:1364
uint64_t total_analyzed
the total number that this agent has analyzed
Definition: agent.h:135
int run_count
the count of agents in running state
Definition: agent.h:101
void agent_fail_event(scheduler_t *scheduler, agent_t *agent)
Fails an agent.
Definition: agent.c:1113
#define AGENT_STATUS_TYPES(apply)
Definition: agent.h:61
meta_agent_t * meta_agent_init(char *name, char *cmd, int max, int spc)
Creates a new meta agent.
Definition: agent.c:755
void agent_ready_event(scheduler_t *scheduler, agent_t *agent)
Event created when an agent is ready for more data.
Definition: agent.c:1053
host_t * host
the host that this agent will start on
Definition: agent.h:114
GThread * thread
the thread that communicates with this agent
Definition: agent.h:118
gboolean updated
boolean flag to indicate if the scheduler has updated the data
Definition: agent.h:134
int add_meta_agent(GTree *meta_agents, char *name, char *cmd, int max, int spc)
Definition: agent.c:1327
int max_run
the maximum number that can run at once -1 if no limit
Definition: agent.h:96
meta_agent_t * type
the type of agent this is i.e. bucket, copyright...
Definition: agent.h:113
agent_t * agent_init(scheduler_t *scheduler, host_t *host, job_t *owner)
Allocate and spawn a new agent.
Definition: agent.c:813
void agent_print_status(agent_t *agent, GOutputStream *ostr)
Prints the status of the agent to the output stream provided.
Definition: agent.c:1204
void test_agents(scheduler_t *scheduler)
Calls the agent test function for every type of agent.
Definition: agent.c:1301
void meta_agent_decrease_count(meta_agent_t *)
Definition: agent.c:1383
int to_parent
file identifier to print to the parent (child stdout)
Definition: agent.h:127
void agent_transition(agent_t *agent, agent_status new_status)
Definition: agent.c:1147
time_t check_in
the time that the agent last generated anything
Definition: agent.h:119
void agent_pause(agent_t *agent)
Definition: agent.c:1175
void agent_create_event(scheduler_t *scheduler, agent_t *agent)
Event created when a new agent has been created.
Definition: agent.c:1032
int from_parent
file identifier to read from the parent (child stdin)
Definition: agent.h:124
uint8_t return_code
what was returned by the agent when it disconnected
Definition: agent.h:137
char * version_source
the machine that reported the version information
Definition: agent.h:98
FILE * write
FILE* that abstracts the use of the to_child socket.
Definition: agent.h:129
agent_status status
the state of execution the agent is currently in
Definition: agent.h:117
void meta_agent_increase_count(meta_agent_t *)
Definition: agent.c:1373
int is_meta_special(meta_agent_t *ma, int special_type)
tests if a particular meta agent has a specific special flag set
Definition: agent.c:1352
int aprintf(agent_t *agent, const char *fmt,...)
Definition: agent.c:1249
void agent_destroy(agent_t *agent)
Frees the memory associated with an agent.
Definition: agent.c:935
void agent_update_event(scheduler_t *scheduler, void *unused)
Definition: agent.c:1098
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
Definition: libfossagent.c:309
#define MAX_CMD
the size of the agent&#39;s command buffer (arbitrary)
Definition: agent.h:37
#define SELECT_ENUM(passed)
Definition: agent.h:76
void kill_agents(scheduler_t *scheduler)
Call the agent_kill function for every agent within the system.
Definition: agent.c:1312
Definition: agent.h:110
void agent_unpause(agent_t *agent)
Definition: agent.c:1188
int from_child
file identifier to read from child
Definition: agent.h:126
int agent_pk
Definition: agent.h:85
pid_t pid
the pid of the process this agent is running in
Definition: agent.h:121
ssize_t agent_write(agent_t *agent, const void *buf, int count)
Definition: agent.c:1285
void agent_death_event(scheduler_t *scheduler, pid_t *pids)
Definition: agent.c:963
int valid
flag indicating if the meta_agent is valid
Definition: agent.h:100
int special
any special condition associated with the agent
Definition: agent.h:97
Definition: host.h:38
int to_child
file identifier to print to the child
Definition: agent.h:125
The job structure.
Definition: job.h:61
FILE * read
FILE* that abstracts the use of the from_child socket.
Definition: agent.h:128
uint32_t special
any special flags that the agent has set
Definition: agent.h:138
gchar * data
the data that has been sent to the agent for analysis
Definition: agent.h:133
Header file for the scheduler.
char * version
the version of the agent that is running on all hosts
Definition: agent.h:99
job_t * owner
the job that this agent is assigned to
Definition: agent.h:132
void meta_agent_destroy(meta_agent_t *meta_agent)
Definition: agent.c:795
void agent_kill(agent_t *agent)
Unclean kill of an agent.
Definition: agent.c:1234