FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
libfossscheduler.h
1 /* **************************************************************
2 Copyright (C) 2010 Hewlett-Packard Development Company, L.P.
3 Copyright (C) 2015 Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 
18 ************************************************************** */
19 
20 #ifndef LIBFOSSSCHEDULER_H_INCLUDE
21 #define LIBFOSSSCHEDULER_H_INCLUDE
22 
23 /* local includes */
24 #include <fossconfig.h>
25 #include <libfossdbmanager.h>
26 
27 /* library includes */
28 #include <stdio.h>
29 #include <signal.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <sys/file.h>
33 #include <unistd.h>
34 
35 /* other libraries */
36 #include <libpq-fe.h>
37 
38 #define ALARM_SECS 30
39 
40 
41 /* ************************************************************************** */
42 /* **** Data Types ********************************************************** */
43 /* ************************************************************************** */
44 
52 enum job_status
53 {
54  RUNNING,
55  KILLED,
56  PAUSED
57 };
58 
65 extern int agent_verbose;
66 
67 extern fo_conf* sysconfig;
68 extern char* sysconfigdir;
69 
70 /*
71  * The following macro definitions are meant to act as their own statement in
72  * the c language. To accomplish this, they needed to not only be able to be used
73  * in the situation of an "if" statement with no body, but also require that
74  * they are followed by a ";".
75  *
76  * To do this the "do {} while(0)" loop is used, the loop will not appear in
77  * result flow control since it does not modify the flow of control, but it is
78  * a single statement that requires a ";" at the end to be syntactically correct
79  */
80 
85 #define LOG_FATAL(...) { \
86  fprintf(stdout, "FATAL %s.%d: ", __FILE__, __LINE__); \
87  fprintf(stdout, __VA_ARGS__); \
88  fprintf(stdout, "\n"); \
89  fflush(stdout); }
90 
95 #define LOG_PQ_FATAL(pg_r, ...) { \
96  fprintf(stdout, "FATAL %s.%d: ", __FILE__, __LINE__); \
97  fprintf(stdout, __VA_ARGS__); \
98  fprintf(stdout, "FATAL postgresql error: %s\n", PQresultErrorMessage(pg_r)); \
99  fflush(stdout); }
100 
105 #define LOG_ERROR(...) { \
106  fprintf(stdout, "ERROR %s.%d: ", __FILE__, __LINE__); \
107  fprintf(stdout, __VA_ARGS__); \
108  fprintf(stdout, "\n"); \
109  fflush(stdout); }
110 
116 #define LOG_PQ_ERROR(pg_r, ...) { \
117  fprintf(stdout, "ERROR %s.%d: ", __FILE__, __LINE__); \
118  fprintf(stdout, __VA_ARGS__); \
119  fprintf(stdout, "ERROR postgresql error: %s\n", PQresultErrorMessage(pg_r)); \
120  fflush(stdout); }
121 
126 #define LOG_WARNING(...) { \
127  fprintf(stdout, "WARNING %s.%d: ", __FILE__, __LINE__); \
128  fprintf(stdout, __VA_ARGS__); \
129  fprintf(stdout, "\n"); \
130  fflush(stdout); }
131 
136 #define LOG_DEBUG(...) { \
137  fprintf(stdout, "DEBUG %s.%d: ", __FILE__, __LINE__); \
138  fprintf(stdout, __VA_ARGS__); \
139  fprintf(stdout, "\n"); \
140  fflush(stdout); }
141 
146 #define LOG_NOTICE(...) { \
147  fprintf(stdout, "NOTICE %s.%d: ", __FILE__, __LINE__); \
148  fprintf(stdout, __VA_ARGS__); \
149  fprintf(stdout, "\n"); \
150  fflush(stdout); }
151 
152 #define TVERBOSE agent_verbose
153 #define TVERBOSE0 (agent_verbose & (1 << 0))
154 #define TVERBOSE1 (agent_verbose & (1 << 1))
155 #define TVERBOSE2 (agent_verbose & (1 << 2))
156 #define TVERBOSE3 (agent_verbose & (1 << 3))
157 #define TVERBOSE4 (agent_verbose & (1 << 4))
158 #define TVERBOSE5 (agent_verbose & (1 << 5))
159 #define TVERBOSE6 (agent_verbose & (1 << 6))
160 #define TVERBOSE7 (agent_verbose & (1 << 7))
161 
162 
171 #define LOG_VERBOSE(...) if(TVERBOSE) LOG_NOTICE(__VA_ARGS__);
172 #define LOG_VERBOSE0(...) if(TVERBOSE0) LOG_NOTICE(__VA_ARGS__);
173 #define LOG_VERBOSE1(...) if(TVERBOSE1) LOG_NOTICE(__VA_ARGS__);
174 #define LOG_VERBOSE2(...) if(TVERBOSE2) LOG_NOTICE(__VA_ARGS__);
175 #define LOG_VERBOSE3(...) if(TVERBOSE3) LOG_NOTICE(__VA_ARGS__);
176 #define LOG_VERBOSE4(...) if(TVERBOSE4) LOG_NOTICE(__VA_ARGS__);
177 #define LOG_VERBOSE5(...) if(TVERBOSE5) LOG_NOTICE(__VA_ARGS__);
178 #define LOG_VERBOSE6(...) if(TVERBOSE6) LOG_NOTICE(__VA_ARGS__);
179 #define LOG_VERBOSE7(...) if(TVERBOSE7) LOG_NOTICE(__VA_ARGS__);
180 
187 #define SPECIAL_NOKILL (1 << 0)
188 
189 /* ************************************************************************** */
190 /* **** Agent api *********************************************************** */
191 /* ************************************************************************** */
192 
199 #define NOTIFY_EMAIL(...) \
200  fprintf(stdout, "EMAIL "); \
201  fprintf(stdout, __VA_ARGS__); \
202  fprintf(stdout, "\n"); \
203  fflush(stdout)
204 
205 void fo_scheduler_heart(int i);
206 void fo_scheduler_connect(int* argc, char** argv, PGconn** db_conn);
207 void fo_scheduler_connect_dbMan(int* argc, char** argv, fo_dbManager** dbManager);
208 void fo_scheduler_disconnect(int retcode);
209 char* fo_scheduler_next();
210 
211 /* ************************************************************************** */
212 /* **** Accessor Functions ************************************************** */
213 /* ************************************************************************** */
214 
215 char* fo_scheduler_current();
216 int fo_scheduler_userID();
218 int fo_scheduler_jobId();
219 void fo_scheduler_set_special(int option, int value);
220 int fo_scheduler_get_special(int option);
221 char* fo_sysconfig(const char* sectionname, const char* variablename);
222 
223 #endif /* LIBFOSSSCHEDULER_H_INCLUDE */
FOSSology library to read config file.
fo_conf * sysconfig
int fo_scheduler_groupID()
Gets the id of the group that created the job that the agent is running.
char * fo_scheduler_current()
Get the last read string from the scheduler.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
void fo_scheduler_set_special(int option, int value)
Sets something special about the agent within the scheduler.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
char * sysconfigdir
int fo_scheduler_get_special(int option)
Gets if a particular special attribute is set in the scheduler.
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
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. ...
int fo_scheduler_jobId()
Gets the id of the job that the agent is running.
PGconn * db_conn
The connection to Database.
Definition: pkgagent.c:34
char * fo_scheduler_next()
Get the next data to process from the scheduler.
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...
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.