FOSSology
3.2.0rc1
Open Source License Compliance by Open Source Software
|
Scheduler operations. More...
#include <libfossrepo.h>
#include <agent.h>
#include <database.h>
#include <event.h>
#include <host.h>
#include <interface.h>
#include <scheduler.h>
#include <fossconfig.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
#include <glib.h>
#include <gio/gio.h>
Go to the source code of this file.
Macros | |
#define | TEST_ERROR(error, ...) |
#define | SELECT_DECLS(type, name, l_op, w_op, val) type CONF_##name = val; |
#define | MASK_SIGCHLD (1 << 0) |
#define | MASK_SIGALRM (1 << 1) |
#define | MASK_SIGTERM (1 << 2) |
#define | MASK_SIGQUIT (1 << 3) |
#define | MASK_SIGHUP (1 << 4) |
#define | GU_HEADER "DIRECTORIES" |
#define | GU_GROUP "PROJECTGROUP" |
#define | GU_USER "PROJECTUSER" |
#define | SELECT_CONF_INIT(type, name, l_op, w_op, val) |
Functions | |
void | scheduler_sig_handle (int signo) |
Handles any signals sent to the scheduler that are not SIGCHLD. More... | |
void | scheduler_signal (scheduler_t *scheduler) |
Function that handles certain signals being delivered to the scheduler. More... | |
scheduler_t * | scheduler_init (gchar *sysconfigdir, log_t *log) |
Create a new scheduler object. More... | |
void | scheduler_destroy (scheduler_t *scheduler) |
Free any memory associated with a scheduler_t. More... | |
static gboolean | isMaxLimitReached (meta_agent_t *agent) |
Check if the current agent's max limit is respected. More... | |
void | scheduler_update (scheduler_t *scheduler) |
Update function called after every event. More... | |
void | set_usr_grp (gchar *process_name, fo_conf *config) |
int | kill_scheduler (int force) |
Kills all other running scheduler. More... | |
void | scheduler_clear_config (scheduler_t *scheduler) |
Clears any information that is loaded when loading the configuration. More... | |
static gboolean | g_tree_collect (gpointer key, gpointer value, gpointer data) |
GTraverseFunc used by g_tree_clear to collect all the keys in a tree. More... | |
void | g_tree_clear (GTree *tree) |
Clears the contents of a GTree. More... | |
void | scheduler_agent_config (scheduler_t *scheduler) |
Loads a particular agents configuration file. More... | |
void | scheduler_foss_config (scheduler_t *scheduler) |
Loads the configuration data from fossology.conf. More... | |
int | scheduler_daemonize (scheduler_t *scheduler) |
Daemonizes the scheduler. More... | |
void | scheduler_config_event (scheduler_t *scheduler, void *unused) |
Load both the fossology configuration and all the agent configurations. More... | |
void | scheduler_close_event (scheduler_t *scheduler, void *killed) |
Sets the closing flag and possibly kills all currently running agents. More... | |
void | scheduler_test_agents (scheduler_t *scheduler, void *unused) |
Event used when the scheduler tests the agents. More... | |
gint | string_is_num (gchar *str) |
Checks if a string is entirely composed of numeric characters. More... | |
gint | string_compare (gconstpointer a, gconstpointer b, gpointer user_data) |
gint | int_compare (gconstpointer a, gconstpointer b, gpointer user_data) |
Variables | |
int | verbose = 0 |
The verbose level. More... | |
int | closing = 0 |
Set if scheduler is shutting down. | |
GThread * | main_thread |
Pointer to the main thread. | |
int | sigmask = 0 |
Scheduler operations.
Definition in file scheduler.c.
#define SELECT_CONF_INIT | ( | type, | |
name, | |||
l_op, | |||
w_op, | |||
val | |||
) |
#define TEST_ERROR | ( | error, | |
... | |||
) |
Test if error is not NULL then print it to the log.
Definition at line 55 of file scheduler.c.
void g_tree_clear | ( | GTree * | tree | ) |
Clears the contents of a GTree.
tree | the tree to remove all elements from |
Definition at line 732 of file scheduler.c.
|
static |
GTraverseFunc used by g_tree_clear to collect all the keys in a tree.
key | The current key |
value | The value mapped to the current key |
data | A GList** that the key will be appended to |
Definition at line 718 of file scheduler.c.
gint int_compare | ( | gconstpointer | a, |
gconstpointer | b, | ||
gpointer | user_data | ||
) |
Utility function that enable the agents to be stored in a GTree using the PID of the associated process.
a | The pid of the first process |
b | The pid of the second process |
user_data | unused in this function |
Definition at line 1085 of file scheduler.c.
|
static |
Check if the current agent's max limit is respected.
Compare the number of running agents and run limit of the agent.
agent | Agent which has to be scheduled. |
Definition at line 417 of file scheduler.c.
int kill_scheduler | ( | int | force | ) |
Kills all other running scheduler.
force | if the scheduler should shutdown gracefully |
This uses the /proc file system to find all processes that have fo_scheduler in the name and sends a kill signal to them.
Definition at line 631 of file scheduler.c.
void scheduler_agent_config | ( | scheduler_t * | scheduler | ) |
Loads a particular agents configuration file.
This loads and saves the results as a new meta_agent. This assumes that the configuration file for the agent includes the following key/value pairs:
Definition at line 754 of file scheduler.c.
void scheduler_clear_config | ( | scheduler_t * | scheduler | ) |
Clears any information that is loaded when loading the configuration.
scheduler | the scheduler to reset the information on |
Definition at line 682 of file scheduler.c.
void scheduler_close_event | ( | scheduler_t * | scheduler, |
void * | killed | ||
) |
Sets the closing flag and possibly kills all currently running agents.
This function will cause the scheduler to slowly shutdown. If killed is true this is a quick, ungraceful shutdown.
scheduler | the scheduler |
killed | should the scheduler kill all currently executing agents before exiting the event loop, or should it wait for them to finished first. |
Definition at line 1025 of file scheduler.c.
void scheduler_config_event | ( | scheduler_t * | scheduler, |
void * | unused | ||
) |
Load both the fossology configuration and all the agent configurations.
scheduler | the scheduler to load the configuration for |
unused | this can be called as an event |
Definition at line 1002 of file scheduler.c.
int scheduler_daemonize | ( | scheduler_t * | scheduler | ) |
Daemonizes the scheduler.
This will make sure that the pid that is maintained in the scheduler struct is correct during the daemonizing process.
scheduler | the scheduler_t struct |
Definition at line 984 of file scheduler.c.
void scheduler_destroy | ( | scheduler_t * | scheduler | ) |
Free any memory associated with a scheduler_t.
This will stop the interface if it is currently running, and free all the memory associated with the different regular expression and similar structures.
scheduler |
Interface close
Repo close
Definition at line 373 of file scheduler.c.
void scheduler_foss_config | ( | scheduler_t * | scheduler | ) |
Loads the configuration data from fossology.conf.
This assumes that fossology.conf contains the following key/value pairs:
There should be a group named HOSTS with all of the hosts listed as key/value pairs under this category. For each of these hosts, the scheduler will create a new host as an internal representation.
Definition at line 864 of file scheduler.c.
scheduler_t* scheduler_init | ( | gchar * | sysconfigdir, |
log_t * | log | ||
) |
Create a new scheduler object.
This will initialize everything to a point where it can be used. All regular expressions, GTree's and the job_queue will be correctly created.
sysconfigdir | Directory containing the fossology.conf |
log | Log file to log messages to |
Definition at line 260 of file scheduler.c.
void scheduler_sig_handle | ( | int | signo | ) |
Handles any signals sent to the scheduler that are not SIGCHLD.
Currently Handles:
Signal | Effect |
---|---|
SIGCHLD | Scheduler will handle to death of the child process or agent |
SIGALRM | Scheduler will run agent updates and database updates |
SIGTERM | Scheduler will gracefully shut down |
SIGQUIT | Scheduler will forcefully shut down |
SIGHIP | Scheduler will reload configuration data |
signo | the number of the signal that was sent |
Definition at line 104 of file scheduler.c.
void scheduler_signal | ( | scheduler_t * | scheduler | ) |
Function that handles certain signals being delivered to the scheduler.
This function is called every time the event loop attempts to take something from the event queue. It will also get called once a second regardless of if a new event has been queued.
This function checks the sigmask variable to check what signals have been received since the last time it was called. The sigmask variable should always be accessed atomically since it is accessed by the event loop thread as well as the signal handlers.
scheduler | Scheduler to sent signal to |
Definition at line 153 of file scheduler.c.
void scheduler_test_agents | ( | scheduler_t * | scheduler, |
void * | unused | ||
) |
Event used when the scheduler tests the agents.
scheduler | the scheduler struct |
unused |
Definition at line 1040 of file scheduler.c.
void scheduler_update | ( | scheduler_t * | scheduler | ) |
Update function called after every event.
The heart of the scheduler, the actual scheduling algorithm. This will be passed to the event loop as a call back and will be called every time an event is executed. Therefore the code should be light weight since it will be run very frequently.
Currently this will only grab a job and create a single agent to execute the job.
Allow for job preemption. The scheduler can pause jobs, allow it
Allow for specific hosts to be chosen.
Definition at line 444 of file scheduler.c.
void set_usr_grp | ( | gchar * | process_name, |
fo_conf * | config | ||
) |
Correctly set the project user and group. The fossology scheduler must run as the user specified by PROJECT_USER and PROJECT_GROUP since the agents must be able to connect to the database. This ensures that that happens correctly.
process_name | |
config |
Definition at line 568 of file scheduler.c.
gint string_compare | ( | gconstpointer | a, |
gconstpointer | b, | ||
gpointer | user_data | ||
) |
Utility function that enables the use of the strcmp function with a GTree.
a | The first string |
b | The second string |
user_data | unused in this function |
Definition at line 1071 of file scheduler.c.
gint string_is_num | ( | gchar * | str | ) |
Checks if a string is entirely composed of numeric characters.
str | the string to test |
Definition at line 1052 of file scheduler.c.
int verbose = 0 |