FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
common.c
1 /*
2 Author: Daniele Fognini, Andreas Wuerl
3 Copyright (C) 2013-2014, 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 #include <glib.h>
20 #include "monk.h"
21 #include "common.h"
22 #include <libfossology.h>
23 
24 void scheduler_disconnect(MonkState* state, int exitval) {
25  fo_dbManager_finish(state->dbManager);
26  fo_scheduler_disconnect(exitval);
27 }
28 
29 void bail(MonkState* state, int exitval) {
30  if(state->dbManager != NULL) {
31  scheduler_disconnect(state, exitval);
32  }
33  exit(exitval);
34 }
35 
36 void queryAgentId(MonkState* state, const char* agentName, const char* agentDesc) {
37  char* commitHash = fo_sysconfig(agentName, "COMMIT_HASH");
38  char* version = fo_sysconfig(agentName, "VERSION");
39  gchar* agentRevision = g_strdup_printf("%s.%s", version, commitHash);
40 
41  int agentId = fo_GetAgentKey(fo_dbManager_getWrappedConnection(state->dbManager),
42  agentName, 0, agentRevision, agentDesc);
43  g_free(agentRevision);
44 
45  if (agentId > 0)
46  state->agentId = agentId;
47  else
48  bail(state, 1);
49 }
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
Definition: monk.h:55
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
The main FOSSology C library.
int queryAgentId(PGconn *dbConn)
Get agent id, exit if agent id is incorrect.
FUNCTION int fo_GetAgentKey(PGconn *pgConn, const char *agent_name, long Upload_pk, const char *rev, const char *agent_desc)
Get the latest enabled agent key (agent_pk) from the database.
Definition: libfossagent.c:172
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.