FOSSology  4.7.1
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  /* scheduler self-version tracking */
187 
188  /* regular expressions */
189  GRegex* parse_agent_msg;
190  GRegex* parse_db_email;
192 } scheduler_t;
193 
195 void scheduler_destroy(scheduler_t* scheduler);
196 
197 void scheduler_sig_handle(int signo);
198 void scheduler_signal(scheduler_t* scheduler);
199 void scheduler_update(scheduler_t* scheduler);
200 
201 void g_tree_clear(GTree* tree);
202 
203 extern int verbose;
204 extern int closing;
205 extern GThread* main_thread;
206 
207 /* ************************************************************************** */
208 /* *** CONFIGURATION *** */
209 /* *** There are a set of variables that can be defined in the *** */
210 /* *** Configuration file. These are defined used X-Macros so that *** */
211 /* *** adding a new variable can be accomplished by simply changing *** */
212 /* *** just the CONF_VARIABLE_TYPES Macro. *** */
213 /* ************************************************************************** */
214 
222 #define NOOP(val) val
223 
248 #define CONF_VARIABLES_TYPES(apply) \
249  apply(uint32_t, fork_backoff_time, atoi, %d, 5) \
250  apply(uint32_t, agent_death_timer, atoi, %d, 180) \
251  apply(uint32_t, agent_update_interval, atoi, %d, 120) \
252  apply(uint32_t, agent_update_number, atoi, %d, 5) \
253  apply(gint, interface_nthreads, atoi, %d, 10)
254 
256 #define SELECT_DECLS(type, name, l_op, w_op, val) extern type CONF_##name;
258 #undef SELECT_DECLS
259 
261 #define MK_STRING_LIT(passed) #passed
262 
263 /* ************************************************************************** */
264 /* **** Utility Functions *************************************************** */
265 /* ************************************************************************** */
266 
267 /* glib related functions */
268 gint string_is_num(gchar* str);
269 gint string_compare(gconstpointer a, gconstpointer b, gpointer user_data);
270 gint int_compare(gconstpointer a, gconstpointer b, gpointer user_data);
271 
272 /* ************************************************************************** */
273 /* **** Scheduler Functions ************************************************* */
274 /* ************************************************************************** */
275 
276 /* scheduler events */
277 void scheduler_config_event(scheduler_t* scheduler, void*);
278 void scheduler_close_event(scheduler_t* scheduler, void*);
279 void scheduler_test_agents(scheduler_t* scheduler, void*);
280 void scheduler_version_refresh(scheduler_t* scheduler, void* unused);
281 
282 void scheduler_clear_config(scheduler_t* scheduler);
283 void scheduler_agent_config(scheduler_t* scheduler);
284 void scheduler_foss_config(scheduler_t* scheduler);
285 int scheduler_daemonize(scheduler_t* scheduler);
286 
287 void set_usr_grp(gchar* process_name, fo_conf* config);
288 int kill_scheduler(int force);
289 
290 #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:256
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:921
int scheduler_daemonize(scheduler_t *scheduler)
Daemonizes the scheduler.
Definition: scheduler.c:1179
GThread * main_thread
Pointer to the main thread.
Definition: scheduler.c:60
void scheduler_version_refresh(scheduler_t *scheduler, void *unused)
Event run when the scheduler's own version changed.
Definition: scheduler.c:1306
gint string_is_num(gchar *str)
Checks if a string is entirely composed of numeric characters.
Definition: scheduler.c:1328
void scheduler_test_agents(scheduler_t *scheduler, void *)
Event used when the scheduler tests the agents.
Definition: scheduler.c:1235
void g_tree_clear(GTree *tree)
Clears the contents of a GTree.
Definition: scheduler.c:899
void scheduler_config_event(scheduler_t *scheduler, void *)
Load both the fossology configuration and all the agent configurations.
Definition: scheduler.c:1197
void scheduler_close_event(scheduler_t *scheduler, void *)
Sets the closing flag and possibly kills all currently running agents.
Definition: scheduler.c:1220
void scheduler_update(scheduler_t *scheduler)
Update function called after every event.
Definition: scheduler.c:564
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:846
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:1361
void scheduler_foss_config(scheduler_t *scheduler)
Loads the configuration data from fossology.conf.
Definition: scheduler.c:1031
#define CONF_VARIABLES_TYPES(apply)
Definition: scheduler.h:248
gint string_compare(gconstpointer a, gconstpointer b, gpointer user_data)
Definition: scheduler.c:1347
void set_usr_grp(gchar *process_name, fo_conf *config)
Definition: scheduler.c:732
int kill_scheduler(int force)
Kills all other running scheduler.
Definition: scheduler.c:795
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
Definition: scheduler.c:364
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:191
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:189
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:190
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
gchar * scheduler_version
The version string read from VERSION file at last (re)load.
Definition: scheduler.h:186
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