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