FOSSology  4.4.0
Open Source License Compliance by Open Source Software
agent.h
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2010, 2011, 2012 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #ifndef AGENT_H_INCLUDE
8 #define AGENT_H_INCLUDE
9 
10 /* local includes */
11 #include <host.h>
12 #include <job.h>
13 #include <scheduler.h>
14 
15 /* unix library includes */
16 #include <sys/types.h>
17 
18 /* glib includes */
19 #include <gio/gio.h>
20 #include <glib.h>
21 
22 /* ************************************************************************** */
23 /* **** Data Types ********************************************************** */
24 /* ************************************************************************** */
25 
26 #define MAX_CMD 1023
27 #define MAX_NAME 255
28 #define MAX_ARGS 32
29 #define DEFAULT_RET -1
30 
31 #define LOCAL_HOST "localhost"
32 
33 #define SAG_NOKILL (1 << 0)
34 #define SAG_EXCLUSIVE (1 << 1)
35 #define SAG_NOEMAIL (1 << 2)
36 #define SAG_LOCAL (1 << 3)
37 
50 #define AGENT_STATUS_TYPES(apply) \
51  \
52  apply(FAILED) \
53  \
54  apply(CREATED) \
55  \
56  apply(SPAWNED) \
57  \
58  apply(RUNNING) \
59  \
60  apply(PAUSED) \
61  \
62  apply(CLOSED) \
63 
65 #define SELECT_ENUM(passed) AG_##passed,
66 typedef enum { AGENT_STATUS_TYPES(SELECT_ENUM) } agent_status;
67 #undef SELECT_ENUM
68 
69 extern const char* agent_status_strings[];
70 
74 typedef int agent_pk;
75 
81 typedef struct
82 {
83  char name[256];
84  char raw_cmd[MAX_CMD + 1];
85  int max_run;
86  int special;
88  char* version;
89  int valid;
90  int run_count;
91 } meta_agent_t;
92 
99 typedef struct
100 {
101  /* we need all the information on creating the agent */
104 
105  /* thread management */
106  agent_status status;
107  GThread* thread;
108  time_t check_in;
109  uint8_t n_updates;
110  pid_t pid;
111 
112  /* pipes connecting to the child */
114  int to_child;
116  int to_parent;
117  FILE* read;
118  FILE* write;
119 
120  /* data management */
122  gchar* data;
123  gboolean updated;
124  uint64_t total_analyzed;
125  gboolean alive;
126  uint8_t return_code;
127  uint32_t special;
128 } agent_t;
129 
130 /* ************************************************************************** */
131 /* **** Constructor Destructor ********************************************** */
132 /* ************************************************************************** */
133 
134 /* meta agent */
135 meta_agent_t* meta_agent_init(char* name, char* cmd, int max, int spc);
136 void meta_agent_destroy(meta_agent_t* meta_agent);
137 
138 /* agent */
139 agent_t* agent_init(scheduler_t* scheduler, host_t* host, job_t* owner);
140 void agent_destroy(agent_t* agent);
141 
142 /* ************************************************************************** */
143 /* **** Modifier Functions and events *************************************** */
144 /* ************************************************************************** */
145 
146 void agent_death_event(scheduler_t* scheduler, pid_t* pids);
147 void agent_create_event(scheduler_t* scheduler, agent_t* agent);
148 void agent_ready_event(scheduler_t* scheduler, agent_t* agent);
149 void agent_update_event(scheduler_t* scheduler, void* unused);
150 void agent_fail_event(scheduler_t* scheduler, agent_t* agent);
151 void list_agents_event(scheduler_t* scheduler, GOutputStream* ostr);
152 
153 void agent_transition(agent_t* agent, agent_status new_status);
154 void agent_pause(agent_t* agent);
155 void agent_unpause(agent_t* agent);
156 void agent_print_status(agent_t* agent, GOutputStream* ostr);
157 void agent_kill(agent_t* agent);
158 int aprintf(agent_t* agent, const char* fmt, ...);
159 ssize_t agent_write(agent_t* agent, const void* buf, int count);
160 
161 /* ************************************************************************** */
162 /* **** static functions and meta agents ************************************ */
163 /* ************************************************************************** */
164 
165 void test_agents(scheduler_t* scheduler);
166 int add_meta_agent(GTree* meta_agents, char* name, char* cmd, int max, int spc);
167 
168 void kill_agents(scheduler_t* scheduler);
169 
170 int is_meta_special(meta_agent_t* ma, int special_type);
171 int is_agent_special(agent_t* agent, int special_type);
172 
175 
176 #endif /* AGENT_H_INCLUDE */
void meta_agent_destroy(meta_agent_t *meta_agent)
Definition: agent.c:784
void agent_ready_event(scheduler_t *scheduler, agent_t *agent)
Event created when an agent is ready for more data.
Definition: agent.c:1042
int aprintf(agent_t *agent, const char *fmt,...)
Definition: agent.c:1238
ssize_t agent_write(agent_t *agent, const void *buf, int count)
Definition: agent.c:1274
void agent_update_event(scheduler_t *scheduler, void *unused)
Definition: agent.c:1087
agent_t * agent_init(scheduler_t *scheduler, host_t *host, job_t *owner)
Allocate and spawn a new agent.
Definition: agent.c:802
void agent_destroy(agent_t *agent)
Frees the memory associated with an agent.
Definition: agent.c:924
#define MAX_CMD
the size of the agent's command buffer (arbitrary)
Definition: agent.h:26
void agent_fail_event(scheduler_t *scheduler, agent_t *agent)
Fails an agent.
Definition: agent.c:1102
meta_agent_t * meta_agent_init(char *name, char *cmd, int max, int spc)
Creates a new meta agent.
Definition: agent.c:744
void agent_kill(agent_t *agent)
Unclean kill of an agent.
Definition: agent.c:1223
void agent_pause(agent_t *agent)
Definition: agent.c:1164
#define SELECT_ENUM(passed)
Definition: agent.h:65
int add_meta_agent(GTree *meta_agents, char *name, char *cmd, int max, int spc)
Definition: agent.c:1316
void meta_agent_increase_count(meta_agent_t *)
Definition: agent.c:1362
void agent_create_event(scheduler_t *scheduler, agent_t *agent)
Event created when a new agent has been created.
Definition: agent.c:1021
#define AGENT_STATUS_TYPES(apply)
Definition: agent.h:50
void agent_transition(agent_t *agent, agent_status new_status)
Definition: agent.c:1136
void meta_agent_decrease_count(meta_agent_t *)
Definition: agent.c:1372
void agent_unpause(agent_t *agent)
Definition: agent.c:1177
void test_agents(scheduler_t *scheduler)
Calls the agent test function for every type of agent.
Definition: agent.c:1290
void kill_agents(scheduler_t *scheduler)
Call the agent_kill function for every agent within the system.
Definition: agent.c:1301
int is_agent_special(agent_t *agent, int special_type)
tests if a particular agent has a specific special flag set
Definition: agent.c:1353
void list_agents_event(scheduler_t *scheduler, GOutputStream *ostr)
Receive agent on interface.
Definition: agent.c:1118
int agent_pk
Definition: agent.h:74
void agent_death_event(scheduler_t *scheduler, pid_t *pids)
Definition: agent.c:952
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:1341
void agent_print_status(agent_t *agent, GOutputStream *ostr)
Prints the status of the agent to the output stream provided.
Definition: agent.c:1193
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
Definition: libfossagent.c:295
Header file for the scheduler.
Definition: agent.h:100
time_t check_in
the time that the agent last generated anything
Definition: agent.h:108
int to_child
file identifier to print to the child
Definition: agent.h:114
agent_status status
the state of execution the agent is currently in
Definition: agent.h:106
meta_agent_t * type
the type of agent this is i.e. bucket, copyright...
Definition: agent.h:102
int from_child
file identifier to read from child
Definition: agent.h:115
gchar * data
the data that has been sent to the agent for analysis
Definition: agent.h:122
FILE * write
FILE* that abstracts the use of the to_child socket.
Definition: agent.h:118
gboolean alive
flag to tell the scheduler if the agent is still alive
Definition: agent.h:125
job_t * owner
the job that this agent is assigned to
Definition: agent.h:121
FILE * read
FILE* that abstracts the use of the from_child socket.
Definition: agent.h:117
uint32_t special
any special flags that the agent has set
Definition: agent.h:127
int to_parent
file identifier to print to the parent (child stdout)
Definition: agent.h:116
uint8_t n_updates
keeps track of the number of times the agent has updated
Definition: agent.h:109
uint64_t total_analyzed
the total number that this agent has analyzed
Definition: agent.h:124
host_t * host
the host that this agent will start on
Definition: agent.h:103
GThread * thread
the thread that communicates with this agent
Definition: agent.h:107
int from_parent
file identifier to read from the parent (child stdin)
Definition: agent.h:113
uint8_t return_code
what was returned by the agent when it disconnected
Definition: agent.h:126
pid_t pid
the pid of the process this agent is running in
Definition: agent.h:110
gboolean updated
boolean flag to indicate if the scheduler has updated the data
Definition: agent.h:123
Definition: host.h:26
The job structure.
Definition: job.h:51
int valid
flag indicating if the meta_agent is valid
Definition: agent.h:89
int max_run
the maximum number that can run at once -1 if no limit
Definition: agent.h:85
int run_count
the count of agents in running state
Definition: agent.h:90
char * version
the version of the agent that is running on all hosts
Definition: agent.h:88
char * version_source
the machine that reported the version information
Definition: agent.h:87
int special
any special condition associated with the agent
Definition: agent.h:86