FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
scheduler.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 ************************************************************** */
110 #ifndef SCHEDULER_H_INCLUDE
111 #define SCHEDULER_H_INCLUDE
112 
113 /* local includes */
114 #include <logging.h>
115 
116 /* std library includes */
117 #include <errno.h>
118 #include <limits.h>
119 #include <stdio.h>
120 #include <stdint.h>
121 
122 /* other library includes */
123 #include <gio/gio.h>
124 #include <glib.h>
125 #include <libpq-fe.h>
126 #include <signal.h>
127 
128 /* fo library includes */
129 #include <fossconfig.h>
130 
131 #define CHECKOUT_SIZE 100
132 
133 #define AGENT_BINARY "%s/%s/%s/agent/%s"
134 #define AGENT_CONF "mods-enabled"
135 
136 
140 #define SafePQclear(pgres) if (pgres) {PQclear(pgres); pgres = NULL;}
141 
142 /* ************************************************************************** */
143 /* *** Scheduler structure ************************************************** */
144 /* ************************************************************************** */
145 
150 typedef struct
151 {
152  /* information about the scheduler process */
153  gchar* process_name;
154  gboolean s_pid;
155  gboolean s_daemon;
156  gboolean s_startup;
157  gboolean s_pause;
158 
159  /* loaded configuration information */
161  gchar* sysconfigdir;
162  gchar* logdir;
163  gboolean logcmdline;
165 
166  /* used exclusively in agent.c */
167  GTree* meta_agents;
168  GTree* agents;
169 
170  /* used exclusively in host.c */
171  GTree* host_list;
172  GList* host_queue;
173 
174  /* used exclusively in interface.c */
175  gboolean i_created;
176  gboolean i_terminate;
177  uint16_t i_port;
178  GThread* server;
179  GThreadPool* workers;
180  GCancellable* cancel;
181 
182  /* used exclusively in job.c */
183  GTree* job_list;
184  GSequence* job_queue;
185 
186  /* used exclusively in database.c */
187  PGconn* db_conn;
188  gchar* host_url;
189  gchar* email_subject;
190  gchar* email_header;
191  gchar* email_footer;
192  gchar* email_command;
193  gboolean default_header;
194  gboolean default_footer;
195 
196  /* regular expressions */
197  GRegex* parse_agent_msg;
198  GRegex* parse_db_email;
200 } scheduler_t;
201 
203 void scheduler_destroy(scheduler_t* scheduler);
204 
205 void scheduler_sig_handle(int signo);
206 void scheduler_signal(scheduler_t* scheduler);
207 void scheduler_update(scheduler_t* scheduler);
208 
209 void g_tree_clear(GTree* tree);
210 
211 extern int verbose;
212 extern int closing;
213 extern GThread* main_thread;
214 
215 /* ************************************************************************** */
216 /* *** CONFIGURATION *** */
217 /* *** There are a set of variables that can be defined in the *** */
218 /* *** Configuration file. These are defined used X-Macros so that *** */
219 /* *** adding a new variable can be accomplished by simply changing *** */
220 /* *** just the CONF_VARIABLE_TYPES Macro. *** */
221 /* ************************************************************************** */
222 
230 #define NOOP(val) val
231 
256 #define CONF_VARIABLES_TYPES(apply) \
257  apply(uint32_t, fork_backoff_time, atoi, %d, 5) \
258  apply(uint32_t, agent_death_timer, atoi, %d, 180) \
259  apply(uint32_t, agent_update_interval, atoi, %d, 120) \
260  apply(uint32_t, agent_update_number, atoi, %d, 5) \
261  apply(gint, interface_nthreads, atoi, %d, 10)
262 
264 #define SELECT_DECLS(type, name, l_op, w_op, val) extern type CONF_##name;
266 #undef SELECT_DECLS
267 
269 #define MK_STRING_LIT(passed) #passed
270 
271 /* ************************************************************************** */
272 /* **** Utility Functions *************************************************** */
273 /* ************************************************************************** */
274 
275 /* glib related functions */
276 gint string_is_num(gchar* str);
277 gint string_compare(gconstpointer a, gconstpointer b, gpointer user_data);
278 gint int_compare(gconstpointer a, gconstpointer b, gpointer user_data);
279 
280 /* ************************************************************************** */
281 /* **** Scheduler Functions ************************************************* */
282 /* ************************************************************************** */
283 
284 /* scheduler events */
285 void scheduler_config_event(scheduler_t* scheduler, void*);
286 void scheduler_close_event(scheduler_t* scheduler, void*);
287 void scheduler_test_agents(scheduler_t* scheduler, void*);
288 
289 void scheduler_clear_config(scheduler_t* scheduler);
290 void scheduler_agent_config(scheduler_t* scheduler);
291 void scheduler_foss_config(scheduler_t* scheduler);
292 int scheduler_daemonize(scheduler_t* scheduler);
293 
294 void set_usr_grp(gchar* process_name, fo_conf* config);
295 int kill_scheduler(int force);
296 
297 #endif /* SCHEDULER_H_INCLUDE */
PGconn * db_conn
The database connection.
Definition: scheduler.h:187
void scheduler_agent_config(scheduler_t *scheduler)
Loads a particular agents configuration file.
Definition: scheduler.c:754
void scheduler_clear_config(scheduler_t *scheduler)
Clears any information that is loaded when loading the configuration.
Definition: scheduler.c:682
gchar * email_header
The beginning of the email message.
Definition: scheduler.h:190
gboolean default_footer
Is the footer the default footer.
Definition: scheduler.h:194
GTree * host_list
List of all hosts available to the scheduler.
Definition: scheduler.h:171
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
Definition: scheduler.c:260
GTree * meta_agents
List of all meta agents available to the scheduler.
Definition: scheduler.h:167
FOSSology library to read config file.
void set_usr_grp(gchar *process_name, fo_conf *config)
Definition: scheduler.c:568
gint string_compare(gconstpointer a, gconstpointer b, gpointer user_data)
Definition: scheduler.c:1071
GRegex * parse_db_email
Parses database email text.
Definition: scheduler.h:198
fo_conf * sysconfig
Configuration information loaded from the configuration file.
Definition: scheduler.h:160
GCancellable * cancel
Used to stop the listening thread when it is running.
Definition: scheduler.h:180
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
Definition: scheduler.c:373
gboolean s_pause
Has the scheduler been paused.
Definition: scheduler.h:157
gboolean default_header
Is the header the default header.
Definition: scheduler.h:193
GRegex * parse_interface_cmd
Parses the commands received by the interface.
Definition: scheduler.h:199
GList * host_queue
Round-robin queue for choosing which host use next.
Definition: scheduler.h:172
gboolean i_created
Has the interface been created.
Definition: scheduler.h:175
Definition: logging.h:45
uint16_t i_port
The port that the scheduler is listening on.
Definition: scheduler.h:177
GThread * server
Thread that is listening to the server socket.
Definition: scheduler.h:178
void scheduler_config_event(scheduler_t *scheduler, void *)
Load both the fossology configuration and all the agent configurations.
Definition: scheduler.c:1002
gchar * sysconfigdir
The system directory that contain fossology.conf.
Definition: scheduler.h:161
gboolean logcmdline
Was the log file set by the command line.
Definition: scheduler.h:163
GSequence * job_queue
heap of jobs that still need to be started
Definition: scheduler.h:184
Log related operations.
gchar * host_url
The url that is used to get to the FOSSology instance.
Definition: scheduler.h:188
#define CONF_VARIABLES_TYPES(apply)
Definition: scheduler.h:256
gint int_compare(gconstpointer a, gconstpointer b, gpointer user_data)
Definition: scheduler.c:1085
gint string_is_num(gchar *str)
Checks if a string is entirely composed of numeric characters.
Definition: scheduler.c:1052
void g_tree_clear(GTree *tree)
Clears the contents of a GTree.
Definition: scheduler.c:732
GTree * job_list
List of jobs that have been created.
Definition: scheduler.h:183
char * sysconfigdir
void scheduler_close_event(scheduler_t *scheduler, void *)
Sets the closing flag and possibly kills all currently running agents.
Definition: scheduler.c:1025
gboolean s_daemon
Is the scheduler being run as a daemon.
Definition: scheduler.h:155
gchar * email_footer
The end of the email message.
Definition: scheduler.h:191
void scheduler_sig_handle(int signo)
Handles any signals sent to the scheduler that are not SIGCHLD.
Definition: scheduler.c:104
void scheduler_update(scheduler_t *scheduler)
Update function called after every event.
Definition: scheduler.c:444
gboolean i_terminate
Has the interface been terminated.
Definition: scheduler.h:176
GTree * agents
List of any currently running agents.
Definition: scheduler.h:168
gchar * email_command
The command that will sends emails, usually mailx.
Definition: scheduler.h:192
#define SELECT_DECLS(type, name, l_op, w_op, val)
Definition: scheduler.h:264
void scheduler_signal(scheduler_t *scheduler)
Function that handles certain signals being delivered to the scheduler.
Definition: scheduler.c:153
void scheduler_test_agents(scheduler_t *scheduler, void *)
Event used when the scheduler tests the agents.
Definition: scheduler.c:1040
gboolean s_startup
Has the scheduler finished startup tests.
Definition: scheduler.h:156
void scheduler_foss_config(scheduler_t *scheduler)
Loads the configuration data from fossology.conf.
Definition: scheduler.c:864
GRegex * parse_agent_msg
Parses messages coming from the agents.
Definition: scheduler.h:197
gboolean s_pid
The pid of the scheduler process.
Definition: scheduler.h:154
GThread * main_thread
Pointer to the main thread.
Definition: scheduler.c:71
int closing
Set if scheduler is shutting down.
Definition: scheduler.c:69
log_t * main_log
The main log file for the scheduler.
Definition: scheduler.h:164
GThreadPool * workers
Threads to handle incoming network communication.
Definition: scheduler.h:179
int verbose
The verbose flag for the cli.
Definition: fo_cli.c:49
gchar * logdir
The directory to put the log file in.
Definition: scheduler.h:162
gchar * email_subject
The subject to be used for emails.
Definition: scheduler.h:189
int scheduler_daemonize(scheduler_t *scheduler)
Daemonizes the scheduler.
Definition: scheduler.c:984
int kill_scheduler(int force)
Kills all other running scheduler.
Definition: scheduler.c:631
gchar * process_name
The name of the scheduler process.
Definition: scheduler.h:153