FOSSology  4.4.0
Open Source License Compliance by Open Source Software
libfossscheduler.h
1 /*
2  SPDX-FileCopyrightText: © 2010 Hewlett-Packard Development Company, L.P.
3  SPDX-FileCopyrightText: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 #ifndef LIBFOSSSCHEDULER_H_INCLUDE
9 #define LIBFOSSSCHEDULER_H_INCLUDE
10 
11 /* local includes */
12 #include <fossconfig.h>
13 #include <libfossdbmanager.h>
14 
15 /* library includes */
16 #include <stdio.h>
17 #include <signal.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <sys/file.h>
21 #include <unistd.h>
22 
23 /* other libraries */
24 #include <libpq-fe.h>
25 
26 #define ALARM_SECS 30
27 
28 
29 /* ************************************************************************** */
30 /* **** Data Types ********************************************************** */
31 /* ************************************************************************** */
32 
40 enum job_status
41 {
42  RUNNING,
43  KILLED,
44  PAUSED
45 };
46 
53 extern int agent_verbose;
54 
55 extern fo_conf* sysconfig;
56 extern char* sysconfigdir;
57 
58 /*
59  * The following macro definitions are meant to act as their own statement in
60  * the c language. To accomplish this, they needed to not only be able to be used
61  * in the situation of an "if" statement with no body, but also require that
62  * they are followed by a ";".
63  *
64  * To do this the "do {} while(0)" loop is used, the loop will not appear in
65  * result flow control since it does not modify the flow of control, but it is
66  * a single statement that requires a ";" at the end to be syntactically correct
67  */
68 
73 #define LOG_FATAL(...) { \
74  fprintf(stdout, "FATAL %s.%d: ", __FILE__, __LINE__); \
75  fprintf(stdout, __VA_ARGS__); \
76  fprintf(stdout, "\n"); \
77  fflush(stdout); }
83 #define LOG_PQ_FATAL(pg_r, ...) { \
84  fprintf(stdout, "FATAL %s.%d: ", __FILE__, __LINE__); \
85  fprintf(stdout, __VA_ARGS__); \
86  fprintf(stdout, "FATAL postgresql error: %s\n", PQresultErrorMessage(pg_r)); \
87  fflush(stdout); }
88 
93 #define LOG_ERROR(...) { \
94  fprintf(stdout, "ERROR %s.%d: ", __FILE__, __LINE__); \
95  fprintf(stdout, __VA_ARGS__); \
96  fprintf(stdout, "\n"); \
97  fflush(stdout); }
98 
104 #define LOG_PQ_ERROR(pg_r, ...) { \
105  fprintf(stdout, "ERROR %s.%d: ", __FILE__, __LINE__); \
106  fprintf(stdout, __VA_ARGS__); \
107  fprintf(stdout, "ERROR postgresql error: %s\n", PQresultErrorMessage(pg_r)); \
108  fflush(stdout); }
109 
114 #define LOG_WARNING(...) { \
115  fprintf(stdout, "WARNING %s.%d: ", __FILE__, __LINE__); \
116  fprintf(stdout, __VA_ARGS__); \
117  fprintf(stdout, "\n"); \
118  fflush(stdout); }
119 
124 #define LOG_DEBUG(...) { \
125  fprintf(stdout, "DEBUG %s.%d: ", __FILE__, __LINE__); \
126  fprintf(stdout, __VA_ARGS__); \
127  fprintf(stdout, "\n"); \
128  fflush(stdout); }
129 
134 #define LOG_NOTICE(...) { \
135  fprintf(stdout, "NOTICE %s.%d: ", __FILE__, __LINE__); \
136  fprintf(stdout, __VA_ARGS__); \
137  fprintf(stdout, "\n"); \
138  fflush(stdout); }
139 
140 #define TVERBOSE agent_verbose
141 #define TVERBOSE0 (agent_verbose & (1 << 0))
142 #define TVERBOSE1 (agent_verbose & (1 << 1))
143 #define TVERBOSE2 (agent_verbose & (1 << 2))
144 #define TVERBOSE3 (agent_verbose & (1 << 3))
145 #define TVERBOSE4 (agent_verbose & (1 << 4))
146 #define TVERBOSE5 (agent_verbose & (1 << 5))
147 #define TVERBOSE6 (agent_verbose & (1 << 6))
148 #define TVERBOSE7 (agent_verbose & (1 << 7))
149 
159 #define LOG_VERBOSE(...) if(TVERBOSE) LOG_NOTICE(__VA_ARGS__);
160 #define LOG_VERBOSE0(...) if(TVERBOSE0) LOG_NOTICE(__VA_ARGS__);
161 #define LOG_VERBOSE1(...) if(TVERBOSE1) LOG_NOTICE(__VA_ARGS__);
162 #define LOG_VERBOSE2(...) if(TVERBOSE2) LOG_NOTICE(__VA_ARGS__);
163 #define LOG_VERBOSE3(...) if(TVERBOSE3) LOG_NOTICE(__VA_ARGS__);
164 #define LOG_VERBOSE4(...) if(TVERBOSE4) LOG_NOTICE(__VA_ARGS__);
165 #define LOG_VERBOSE5(...) if(TVERBOSE5) LOG_NOTICE(__VA_ARGS__);
166 #define LOG_VERBOSE6(...) if(TVERBOSE6) LOG_NOTICE(__VA_ARGS__);
167 #define LOG_VERBOSE7(...) if(TVERBOSE7) LOG_NOTICE(__VA_ARGS__);
168 
175 #define SPECIAL_NOKILL (1 << 0)
176 
177 /* ************************************************************************** */
178 /* **** Agent api *********************************************************** */
179 /* ************************************************************************** */
180 
187 #define NOTIFY_EMAIL(...) \
188  fprintf(stdout, "EMAIL "); \
189  fprintf(stdout, __VA_ARGS__); \
190  fprintf(stdout, "\n"); \
191  fflush(stdout)
192 
193 void fo_scheduler_heart(int i);
194 void fo_scheduler_connect(int* argc, char** argv, PGconn** db_conn);
195 void fo_scheduler_connect_dbMan(int* argc, char** argv, fo_dbManager** dbManager);
196 void fo_scheduler_disconnect(int retcode);
197 char* fo_scheduler_next();
198 
199 /* ************************************************************************** */
200 /* **** Accessor Functions ************************************************** */
201 /* ************************************************************************** */
202 
203 char* fo_scheduler_current();
204 int fo_scheduler_userID();
206 int fo_scheduler_jobId();
207 void fo_scheduler_set_special(int option, int value);
208 int fo_scheduler_get_special(int option);
209 char* fo_sysconfig(const char* sectionname, const char* variablename);
210 
211 #endif /* LIBFOSSSCHEDULER_H_INCLUDE */
FOSSology library to read config file.
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...
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 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.
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 * sysconfigdir
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
char * fo_scheduler_current()
Get the last read string from the scheduler.
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.
fo_conf * sysconfig
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
PGconn * db_conn
The connection to Database.
Definition: pkgagent.c:22