14 #include "libfossscheduler.h"
15 #include "libfossdb.h"
41 WHERE agent_name = '%s' AND agent_rev='%s.%s'";
45 INSERT INTO agent (agent_name, agent_rev, agent_desc) \
46 VALUES ('%s', '%s.%s', '%s')";
95 PGresult* db_result = NULL;
101 db_result = PQexec(
db_conn, db_sql);
102 if (PQresultStatus(db_result) != PGRES_TUPLES_OK)
104 fprintf(stderr,
"FATAL %s.%d: unable to check agent table: %s",
105 __FILE__, __LINE__, PQresultErrorMessage(db_result));
113 if (PQntuples(db_result) != 1)
122 db_result = PQexec(
db_conn, db_sql);
123 if (PQresultStatus(db_result) != PGRES_COMMAND_OK)
125 fprintf(stderr,
"FATAL %s.%d: unable to insert into agent table: %s",
126 __FILE__, __LINE__, PQresultErrorMessage(db_result));
172 GError* error = NULL;
173 GOptionContext* parsed;
175 char fname[FILENAME_MAX + 1];
177 char* db_config = NULL;
178 char* db_error = NULL;
181 GOptionEntry options[] =
183 {
"config",
'c', 0, G_OPTION_ARG_STRING, &
sysconfigdir,
""},
184 {
"userID", 0, 0, G_OPTION_ARG_INT, &
userID,
""},
185 {
"groupID", 0, 0, G_OPTION_ARG_INT, &
groupID,
""},
186 {
"scheduler_start", 0, 0, G_OPTION_ARG_NONE, &
sscheduler,
""},
187 {
"jobId", 0, 0, G_OPTION_ARG_INT, &
jobId,
""},
204 LOG_WARNING(
"fo_scheduler_connect() has already been called.");
209 if (getenv(
"FO_SYSCONFDIR"))
213 parsed = g_option_context_new(
"");
214 g_option_context_add_main_entries(parsed, options, NULL);
215 g_option_context_set_ignore_unknown_options(parsed, TRUE);
216 g_option_context_set_help_enabled(parsed, FALSE);
217 g_option_context_parse(parsed, argc, &argv, NULL);
218 g_option_context_free(parsed);
223 snprintf(fname, FILENAME_MAX,
"%s/%s",
sysconfigdir,
"fossology.conf");
227 fprintf(stderr,
"FATAL %s.%d: unable to open system configuration: %s\n",
228 __FILE__, __LINE__, error->message);
232 snprintf(fname, FILENAME_MAX,
"%s/mods-enabled/%s/VERSION",
238 fprintf(stderr,
"FATAL %s.%d: unable to open VERSION configuration: %s\n",
239 __FILE__, __LINE__, error->message);
246 fprintf(stderr,
"FATAL %s.%d: unable to join configuration files: %s\n",
247 __FILE__, __LINE__, error->message);
258 db_config = g_strdup_printf(
"%s/Db.conf",
sysconfigdir);
261 *db_conf = db_config;
266 fprintf(stderr,
"FATAL %s.%d: unable to open database connection: %s\n",
267 __FILE__, __LINE__, db_error);
281 fprintf(stdout,
"VERSION: %s\n",
283 else fprintf(stdout,
"VERSION: unknown\n");
284 fprintf(stdout,
"\nOK\n");
332 PGconn* dbConnection;
334 *
dbManager = fo_dbManager_new_withConf(dbConnection, dbConf);
353 fprintf(stdout,
"\nBYE %d\n", retcode);
408 printf(
"\nNOTE: received %s\n",
buffer);
409 if (strncmp(
buffer,
"CLOSE", 5) == 0)
411 if (strncmp(
buffer,
"END", 3) == 0)
413 fprintf(stdout,
"\nOK\n");
419 else if (strncmp(
buffer,
"VERBOSE", 7) == 0)
425 else if (strncmp(
buffer,
"VERSION", 7) == 0)
428 fprintf(stdout,
"VERSION: %s\n",
430 else fprintf(stdout,
"VERSION: unknown\n");
474 fprintf(stdout,
"SPECIAL: %d %d\n", option, value);
494 fprintf(stdout,
"GETSPECIAL: %d\n", option);
497 if (fscanf(stdin,
"VALUE: %d\n", &value) != 1)
544 GError* error = NULL;
558 g_clear_error(&error);
void fo_config_free(fo_conf *conf)
Frees the memory associated with the internal configuration data structures.
fo_conf * fo_config_load(char *rawname, GError **error)
Load the configuration information from the provided file.
char * fo_config_get(fo_conf *conf, const char *group, const char *key, GError **error)
Gets an element based on its group name and key name. If the group or key is not found,...
void fo_config_join(fo_conf *dst, fo_conf *src, GError **error)
Takes all groups and key from a fo_conf and adds them to another.
int fo_config_has_key(fo_conf *conf, char *group, char *key)
Checks if the a specific group in the currently parsed configuration file has a specific key.
FOSSology library to read config file.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
int groupID
The id of the group of the user that created the job.
void fo_heartbeat()
Internal function to send a heartbeat to the scheduler along with the number of items processed.
volatile int alive
If the agent has updated with a hearbeat.
volatile gint items_processed
The number of items processed by the agent.
void fo_scheduler_set_special(int option, int value)
Sets something special about the agent within the scheduler.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
int jobId
The id of the job.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
int fo_scheduler_get_special(int option)
Gets if a particular special attribute is set in the scheduler.
static const char * sql_insert
void fo_scheduler_connect_dbMan(int *argc, char **argv, fo_dbManager **dbManager)
Make a connection from an agent to the scheduler and create a DB manager as well.
char * module_name
The name of the agent.
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
static const char * sql_check
char * fo_scheduler_current()
Get the last read string from the scheduler.
GRegex * fo_conf_parse
Regex for parsing.
int fo_scheduler_jobId()
Gets the id of the job that the agent is running.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
int fo_scheduler_groupID()
Gets the id of the group that created the job that the agent is running.
int sscheduler
Whether the agent was started by the scheduler.
GRegex * fo_conf_replace
Regex for replace.
int userID
The id of the user that created the job.
void fo_scheduler_connect_conf(int *argc, char **argv, PGconn **db_conn, char **db_conf)
Establish a connection between an agent and the scheduler.
void fo_check_agentdb(PGconn *db_conn)
Checks that the agent is already in the agent table.
int valid
If the information stored in buffer is valid.
char buffer[2048]
The last thing received from the scheduler.
fo_dbManager * dbManager
fo_dbManager object
PGconn * db_conn
The connection to Database.
FUNCTION int processed(PGconn *pgConn, int agent_pk, int nomos_agent_pk, int pfile_pk, int uploadtree_pk, int bucketpool_pk, int bucket_pk)
Has this pfile or uploadtree_pk already been bucket processed? This only works if the bucket has been...