Commit b27d4c0f authored by 's avatar
Browse files

Logging Mechanism Updated. Now MAPI supports logging to files and syslog.

In order to log messages to syslog, mapid and/or mapicommd should be executed
with the flag -s (mapid -s and/or mapicommd -s). 
Two different types of messages are sent to syslog, debug messages and
general information messages. In /usr/local/etc/mapi/mapi.conf the syslog
level can be configured.

syslog_level=0 : Log only general information and not debugging messages
syslog_level=1 : Log general information plus debugging information (debug messages are printed to stdout and syslog)
syslog_level=2 : Log general information plus debugging information (debug messages are printed only to syslog)

The default level is 2 (temporary the default level is 1).

In order to log debug messages and general information messages to separate log files,
syslog daemon must be configured as follows:

File /etc/syslog.conf should have the following two entries:

local1.info;local1.!=debug				/var/tmp/info.syslog
local1.debug;local1.!=info				/var/tmp/debug.syslog

/var/tmp/info.syslog & /var/tmp/debug.syslog are indicative names of files, where debug and information messages are appended.
The /var/tmp/info.syslog & /var/tmp/debug.syslog files must exist before the syslogd daemon re-reads the /etc/syslog.conf
configuration file, in order for the syslogd daemon to log messages to these files. To create these files, issue the following commands:

touch /var/tmp/info.syslog
touch /var/tmp/debug.syslog

Then issue the following command to force the syslogd daemon to re-read its configuration file: kill -HUP <syslogd's process id>

Define DEBUG is default enabled. In the future mapi configuration will have an extra flag (--enable-debug), thus a MAPI
user might select if MAPI prints debug messages or no.


git-svn-id: file:///home/svn/mapi/trunk@1292 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 67a8a848
......@@ -3,8 +3,8 @@ drvpath=@DATADIR@
libs=@MAPI_FUNC_LIBS@
debug=2
dimapi_port=2233
syslog_level=1
logfile=
[driver]
......
......@@ -41,7 +41,9 @@ common/libflist.la \
common/libmapiipc.la \
common/libparseconf.la \
common/libprintfstring.la -lpthread -ldl \
common/libdevgroupdb.la
common/libdevgroupdb.la \
common/libdebug.la \
common/liblog.la
mapid_SOURCES = mapid.c mapid.h mapidevices.h debug.h
if BINARY_DIMAPI
......@@ -53,7 +55,9 @@ common/libflist.la \
common/libparseconf.la \
common/libprintfstring.la \
common/libdevgroupdb.la \
lib/libmapi.la -lpthread
lib/libmapi.la -lpthread \
common/libdebug.la \
common/liblog.la
mapicommd_SOURCES = mapicommd.c
endif
......
......@@ -9,6 +9,7 @@ anonflib_la_LDFLAGS = -module
anonflib_la_LIBADD = \
../common/libflist.la \
../common/libmapiipc.la \
../common/libdebug.la \
../common/libfhelp.la -lm @PCRELIB@
anonflib_la_SOURCES = \
aes.c aes.h \
......
......@@ -13,6 +13,7 @@
#include <ctype.h>
#include <mapi.h>
#include "anonymization.h"
#include "debug.h"
#define TIMEBUF_SIZE 26
#define C_OFFSET 49
......@@ -211,7 +212,7 @@ void PrintIPPkt(FILE * fp, MAPI_UNUSED int type, mapipacket * p)
}
if(!p) {
printf("PACKET=NULLLLLLLLLLLLLLLLL\n");
DEBUG_CMD(Debug_Message("PACKET is NULL"));
return;
}
......@@ -745,7 +746,7 @@ void PrintNetData(FILE * fp, u_char * start, const int len)
if(start == NULL)
{
printf("Got NULL ptr in PrintNetData()\n");
DEBUG_CMD(Debug_Message("Got NULL ptr in PrintNetData()"));
return;
}
......@@ -753,8 +754,8 @@ void PrintNetData(FILE * fp, u_char * start, const int len)
if(len > 65535)
{
printf("Got bogus buffer length (%d) for PrintNetData, defaulting to 16 bytes!\n", len);
dbuf_size = (FRAME_SIZE + 8) + (FRAME_SIZE + 8) + 1;
DEBUG_CMD(Debug_Message("Got bogus buffer length (%d) for PrintNetData, defaulting to 16 bytes!", len));
dbuf_size = (FRAME_SIZE + 8) + (FRAME_SIZE + 8) + 1;
/* dbuf_size = 66 + 67; */
end = (char*) (start + 15);
......
......@@ -43,12 +43,11 @@ char *mapidflib_get_libname() {
__attribute__ ((constructor))
void init ()
{
DEBUG_CMD(printf ("Library anonflib loaded\n"));
printf("Library anonflib loaded\n");
}
__attribute__ ((destructor))
void fini ()
{
DEBUG_CMD(printf ("Library anonflib unloaded\n"));
printf("Library anonflib unloaded\n");
}
......@@ -18,6 +18,7 @@
#include "prefix_preserving_map.h"
#include "../extraflib/cooking.h"
#include "mapi_errors.h"
#include "debug.h"
#include "names.h"
extern char *anonnames[];
......@@ -246,29 +247,29 @@ int unmarshalBuffer(int function,char *buffer,struct unmarshal_data *data) {
*pos='\0';
num_of_matches=atoi(tmpbuf);
tmpbuf=pos+1;
printf(">>>>>>> REGEXP: %s %d\n",regexp,num_of_matches);
DEBUG_CMD(Debug_Message(">>>>>>> REGEXP: %s %d", regexp, num_of_matches));
replaceVector=(char **)malloc(num_of_matches*sizeof(char *));
memset(replaceVector,0,num_of_matches*sizeof(char *));
for(i=0;i<(num_of_matches-1);i++) {
pos=strchr(tmpbuf,',');
if(pos==NULL) {
printf("!!!!\n");
DEBUG_CMD(Debug_Message("pos is NULL !"));
return 0;
}
*pos='\0';
printf("REPLACE VECTOR[%d]=%s\n",i,tmpbuf);
DEBUG_CMD(Debug_Message("REPLACE VECTOR[%d]=%s", i, tmpbuf));
if(strcmp(tmpbuf,"NULL")!=0)
replaceVector[i]=(char *)strdup(tmpbuf);
tmpbuf=pos+1;
}
printf("REPLACE VECTOR[%d]=%s\n",i,tmpbuf);
DEBUG_CMD(Debug_Message("REPLACE VECTOR[%d]=%s", i, tmpbuf));
if(strcmp(tmpbuf,"NULL")!=0)
replaceVector[i]=(char *)strdup(tmpbuf);
break;
default:
printf("UNKNOWN FUNCTION\n");
DEBUG_CMD(Debug_Message("UNKNOWN FUNCTION"));
return 0;
}
......@@ -297,18 +298,18 @@ int unmarshalBuffer(int function,char *buffer,struct unmarshal_data *data) {
int can_field_be_applied_to_function(int anonymization_function,int field) {
if((anonymization_function==PREFIX_PRESERVING || anonymization_function==PREFIX_PRESERVING_MAP) && field!=SRC_IP && field!=DST_IP) {
printf("PREFIX_PRESERVING can only be applied to IP addresses\n");
DEBUG_CMD(Debug_Message("PREFIX_PRESERVING can only be applied to IP addresses"));
return 0;
}
if((anonymization_function==MAP ||anonymization_function==MAP_DISTRIBUTION) && (field<CHECKSUM || field>CODE || field==OPTIONS || field==TCP_OPTIONS)) {
printf("MAP/MAP_DISTRIBUTION can only be applied to IP,TCP,UDP and ICMP headers (except IP and TCP options\n");
DEBUG_CMD(Debug_Message("MAP/MAP_DISTRIBUTION can only be applied to IP,TCP,UDP and ICMP headers (except IP and TCP options)"));
return 0;
}
if(anonymization_function==STRIP && (field!=PAYLOAD) && (field!=OPTIONS) && (field!=TCP_OPTIONS) && ((field<=BASE_HTTP_DEFS)
|| (field>=END_HTTP_DEFS)) && ((field<=BASE_FTP_DEFS) || (field>=END_FTP_DEFS))) {
printf("STRIP can only be applied to IP and TCP options, PAYLOAD and all HTTP, FTP headers\n");
DEBUG_CMD(Debug_Message("STRIP can only be applied to IP and TCP options, PAYLOAD and all HTTP, FTP headers"));
return 0;
}
......@@ -318,18 +319,18 @@ int can_field_be_applied_to_function(int anonymization_function,int field) {
}*/
if(anonymization_function==REPLACE && (field>=CHECKSUM && field<=CODE)) {
printf("REPLACE cannot be performed on headers\n");
DEBUG_CMD(Debug_Message("REPLACE cannot be performed on headers"));
return 0;
}
if(anonymization_function==CHECKSUM_ADJUST && field!=CHECKSUM) {
printf("CHECKSUM_ADJUST can only be applied to CHECKSUM field\n");
DEBUG_CMD(Debug_Message("CHECKSUM_ADJUST can only be applied to CHECKSUM field"));
return 0;
}
if(field == FIELD_VERSION || field == IHL)
{
printf("Anonymization of IP fields Version & Internet Header Length is not supported to maintain usability of anonymized data.\n");
DEBUG_CMD(Debug_Message("Anonymization of IP fields Version & Internet Header Length is not supported to maintain usability of anonymized data."));
return(0);
}
......@@ -405,22 +406,22 @@ static int anonymize_instance(mapidflib_function_instance_t *instance,
}
if(anonymization_function<UNCHANGED || anonymization_function>REGEXP) {
printf("UNKNOWN FUNCTION\n");
DEBUG_CMD(Debug_Message("UNKNOWN FUNCTION"));
return MFUNCT_INVALID_ARGUMENT_3;
}
if(!can_field_be_applied_to_protocol(protocol,field_description)) {
printf("FIELD CANNOT BE APPLIED TO SPECIFIC PROTOCOL\n");
DEBUG_CMD(Debug_Message("FIELD CANNOT BE APPLIED TO SPECIFIC PROTOCOL"));
return MFUNCT_INVALID_ARGUMENT_2;
}
if(!can_field_be_applied_to_function(anonymization_function,field_description)) {
printf("FIELD CANNOT BE APPLIED TO SPECIFIC FUNCTION\n");
DEBUG_CMD(Debug_Message("FIELD CANNOT BE APPLIED TO SPECIFIC FUNCTION"));
return MFUNCT_INVALID_ARGUMENT_2;
}
if(marshalledBuffer!=NULL && unmarshalBuffer(anonymization_function,marshalledBuffer,NULL)==0) {
printf("UNMARSHALLING FAILED\n");
DEBUG_CMD(Debug_Message("UNMARSHALLING FAILED"));
return MFUNCT_INVALID_ARGUMENT_4;
}
......@@ -486,7 +487,7 @@ static int anonymize_init(mapidflib_function_instance_t *instance, MAPI_UNUSED i
default:
unmarshaled=(struct unmarshal_data *)malloc(sizeof(struct unmarshal_data));
if(unmarshalBuffer(anonymization_function,marshalledBuffer,unmarshaled)==0) {
printf("UNMARSHALLING FAILED\n");
DEBUG_CMD(Debug_Message("UNMARSHALLING FAILED"));
return -1;
}
......@@ -551,7 +552,7 @@ void anonymize_field(int protocol, int field, int function,mapipacket *packet,st
int i;
if(!packet) {
printf("WARNING: NULL packet\n");
DEBUG_CMD(Debug_Message("WARNING: NULL packet"));
return;
}
......@@ -1029,7 +1030,7 @@ void apply_function_to_field(int function,int protocol,int field,unsigned char *
aes_hash(field_pointer,len,(unsigned char *)AES_keys,params->padding_behavior,packet);
break;
default:
printf("Fatal Error!\n");
DEBUG_CMD(Debug_Message("Fatal Error!"));
exit(0);
}
break;
......
......@@ -15,6 +15,7 @@
#include <ctype.h>
#include "anonymization.h"
#include "debug.h"
char *http_keywords[]=
{"HTTP Version","Method","URI","User-Agent","Accept","Accept-Charset","Accept-Encoding",
......@@ -196,7 +197,7 @@ int pipeline_http_decode(unsigned char *payload,unsigned int dsize,struct httphe
space_finder++;
if(space_finder==end_of_first_line) {
fprintf(stderr,"Invalid first line of HTTP request\n");
DEBUG_CMD(Debug_Message("Invalid first line of HTTP request"));
return -1;
}
h->http_type=HTTP_REQUEST;
......@@ -212,7 +213,7 @@ int pipeline_http_decode(unsigned char *payload,unsigned int dsize,struct httphe
space_finder++;
if(space_finder==end_of_first_line) {
fprintf(stderr,"Invalid first line of HTTP request. Protocol missing!\n");
DEBUG_CMD(Debug_Message("Invalid first line of HTTP request. Protocol missing!"));
return -1;
}
......
......@@ -3,10 +3,11 @@
#endif
#include <stdio.h>
#include <stdlib.h>
#include "prefix_preserving_map.h"
#include <time.h>
#include <netinet/in.h>
#include <strings.h>
#include "prefix_preserving_map.h"
#include "debug.h"
int bi_ffs(u_long value);
void hide_addr(unsigned char *raw_addr);
......@@ -80,7 +81,7 @@ static node_p newnode(void)
node = (node_p) malloc(sizeof *node);
if (node == 0) {
fprintf(stderr, "malloc failed %s:%d\n", __FILE__, __LINE__);
DEBUG_CMD(Debug_Message("malloc failed"));
exit(2);
}
return node;
......@@ -211,7 +212,7 @@ u_long lookup(u_long input, nodehdr_p hdr)
node = hdr->head; /* non-zero, 'cause lookup_init() already called */
if (hdr->head == 0) { /* (but...) */
fprintf(stderr, "unexpected zero head %s:%d\n", __FILE__, __LINE__);
DEBUG_CMD(Debug_Message("unexpected zero head"));
}
while (node) {
......@@ -234,7 +235,7 @@ u_long lookup(u_long input, nodehdr_p hdr)
}
/* ??? should not occur! */
fprintf(stderr, "unexpected loop termination %s:%d\n", __FILE__, __LINE__);
DEBUG_CMD(Debug_Message("unexpected loop termination"));
exit(1);
}
......
......@@ -14,6 +14,7 @@
#include "mapidevices.h"
#include "mapid.h"
#include "fhelp.h"
#include "debug.h"
#include "mapiipc.h"
#include "anonymization.h"
......@@ -45,7 +46,7 @@ void rebuild_fragments(mapidflib_function_instance_t *instance,flist_t *list,uns
flist_node_t *node = NULL, *temp_node = NULL;
if(!list) {
fprintf(stderr,"No list report in rebuild_fragments\n");
DEBUG_CMD(Debug_Message("No list report in rebuild_fragments"));
return;
}
......@@ -53,9 +54,8 @@ void rebuild_fragments(mapidflib_function_instance_t *instance,flist_t *list,uns
//fprintf(stderr,"No payload report in rebuild_fragments\n");
return;
}
printf("in rebuild_fragments before getting headers\n");
DEBUG_CMD(Debug_Message("in rebuild_fragments before getting headers"));
// get data from large payload
eth = (ether_header*)payload;
......@@ -72,7 +72,7 @@ void rebuild_fragments(mapidflib_function_instance_t *instance,flist_t *list,uns
// finished getting data
printf("in rebuild_fragments after getting headers\n");
DEBUG_CMD(Debug_Message("in rebuild_fragments after getting headers"));
// get remainder functions from the list
pthread_spin_lock(&instance->hwinfo->gflist->lock);
......@@ -107,7 +107,7 @@ void rebuild_fragments(mapidflib_function_instance_t *instance,flist_t *list,uns
/*
printf("packet data caplen %d wlen %d\n", pkthdr.caplen, pkthdr.len);
*/
printf("instance->hwinfo->cap_length %d\n", instance->hwinfo->cap_length);
DEBUG_CMD(Debug_Message("instance->hwinfo->cap_length %d", instance->hwinfo->cap_length));
//decode_packet(instance->hwinfo->link_type,instance->hwinfo->cap_length,&pkthdr,(unsigned char *)(data->header),&frag_decoded);
decode_packet(instance->hwinfo->link_type,data->caplen,&pkthdr,(unsigned char *)(data->header),&frag_decoded);
// decode_packet(instance->hwinfo->link_type,instance->hwinfo->cap_length,&pkthdr,payload,&frag_decoded);
......@@ -164,7 +164,7 @@ void rebuild_fragments(mapidflib_function_instance_t *instance,flist_t *list,uns
while(temp_node != NULL) {
traverse = flist_data(temp_node);
printf("calling function %s pkthdr.caplen %d\n", traverse->instance->def->name, pkthdr.caplen);
DEBUG_CMD(Debug_Message("calling function %s pkthdr.caplen %d", traverse->instance->def->name, pkthdr.caplen));
traverse->instance->def->process(traverse->instance, frag_decoded.pkt, frag_decoded.pkt, &new_header);
temp_node = flist_next(temp_node);
......@@ -183,8 +183,8 @@ void rebuild_fragments(mapidflib_function_instance_t *instance,flist_t *list,uns
if((large_payload_size-p_offset)>0) {
data=(struct headers_data *)prev->data;
data->caplen=data->wlen=data->caplen+large_payload_size-p_offset;
fprintf(stderr,"I have %d flow headers and there are %d bytes remaining \n",cnt,large_payload_size-p_offset);
fprintf(stderr,"new data caplen: %d\n",data->caplen);
DEBUG_CMD(Debug_Message("I have %d flow headers and there are %d bytes remaining", cnt, large_payload_size-p_offset));
DEBUG_CMD(Debug_Message("new data caplen: %d", data->caplen));
pkthdr.caplen=data->caplen;
pkthdr.len=data->wlen;
......@@ -206,7 +206,7 @@ void rebuild_fragments(mapidflib_function_instance_t *instance,flist_t *list,uns
}
else {
printf("in here setting it in zero\n");
DEBUG_CMD(Debug_Message("in here setting it in zero"));
mapihdr->caplen = 0;
return;
}
......
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = -I$(srcdir)/.. -I$(srcdir)/../lib -I$(srcdir)/../drivers @SSLINC@ -D_GNU_SOURCE -D_THREAD_SAFE
noinst_LTLIBRARIES = libflist.la libfhelp.la libmapiipc.la libparseconf.la libprintfstring.la libmapilibhandler.la libmsearch.la libacsmx2.la libcbuf.la libdevgroupdb.la
noinst_LTLIBRARIES = libflist.la libfhelp.la libmapiipc.la libparseconf.la libprintfstring.la libmapilibhandler.la libmsearch.la libacsmx2.la libcbuf.la libdevgroupdb.la libdebug.la liblog.la
libflist_la_SOURCES = flist.c flist.h
libflist_la_DEPENDENCIES = mapi_errors.h
libfhelp_la_SOURCES = fhelp.c fhelp.h
......@@ -14,6 +14,8 @@ libmsearch_la_SOURCES = mstring.c mstring.h
libacsmx2_la_SOURCES = acsmx2.c acsmx2.h
libcbuf_la_SOURCES = cbuf.c cbuf.h kernel_memory.h
libdevgroupdb_la_SOURCES = devgroupdb.c devgroupdb.h
libdebug_la_SOURCES = debug.c debug.h
liblog_la_SOURCES = log.c log.h
noinst_HEADERS = mapidflib.h mapi_errors.h
......
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <syslog.h>
#include "debug.h"
#ifdef DEBUG
char *debug_message_file = NULL; // filename information
int debug_message_line = 0; // line number information
void debug_message(char *fmt, ...){
char buf[STD_BUF + 1];
va_list ap;
int len;
buf[STD_BUF] = '\0';
va_start(ap, fmt);
if(log_level == LOG_INFO_DEBUG_ALL || log_level == SYSLOG_DISABLED){ // debug messages are printed to stdout and syslog OR logging to
// syslog is disabled, thus debug messages are printed only to stdout
vprintf(fmt, ap);
if(debug_message_file != NULL) // filename and line number information
printf(" [%s:%d]\n", debug_message_file, debug_message_line);
}
if(log_level == LOG_INFO_DEBUG_SYSLOG || log_level == LOG_INFO_DEBUG_ALL){ // print debug messages to syslog
len = vsnprintf(buf, STD_BUF, fmt, ap);
sprintf(buf + len, " [%s:%d]", debug_message_file, debug_message_line); // filename and line number information
buf[STD_BUF] = '\0';
syslog(LOG_LOCAL1 | LOG_DEBUG, "%s", buf);
}
va_end(ap);
return;
}
#else
void debug_message(MAPI_UNUSED char *fmt, ...){
}
#endif //DEBUG
#ifndef DEBUG_H
#define DEBUG_H
#define SYSLOG_DISABLED -1
#define LOG_INFORMATION 0
#define LOG_INFO_DEBUG_ALL 1
#define LOG_INFO_DEBUG_SYSLOG 2
void debug_message(char *fmt, ...);
#ifdef DEBUG
extern char *debug_message_file; // filename information
extern int debug_message_line; // line number information
extern int log_level;
#define Debug_Message debug_message_file = __FILE__; debug_message_line = __LINE__; debug_message
#define DEBUG_CMD(code) code
#define STD_BUF 1024
#define ERROR_CMD(code) code // leave them temporary here
#define WARNING_CMD(code) code
#define DEBUG_CMD2(code) code
#define DEBUG_CMD3(code) code
void debug_message(char *fmt, ...);
#else
#define DEBUG_CMD(code)
#define ERROR_CMD(code) // leave them temporary here
#define WARNING_CMD(code)
#define DEBUG_CMD2(code)
#define DEBUG_CMD3(code)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define MAPI_UNUSED \
__attribute__((__unused__))
#else
#define MAPI_UNUSED
#endif
#endif // DEBUG
#endif // DEBUG_H
......@@ -71,6 +71,7 @@
#include <grp.h>
#include "mapi.h"
#include "mapi_errors.h"
#include "debug.h"
#include "devgroupdb.h"
......@@ -82,7 +83,7 @@ struct devgroupdb *new_devgroupdb(int defaultgroupid) {
db = (struct devgroupdb *) malloc(sizeof(struct devgroupdb));
if (db == NULL) {
fputs("new_devgroup(): could not allocate internal data.\n", stderr);
DEBUG_CMD(Debug_Message("new_devgroup(): could not allocate internal data"));
exit(MAPID_MEM_ALLOCATION_ERROR);
}
db->first = NULL;
......@@ -97,7 +98,7 @@ struct devgroupdbitem *new_devgroupdbitem(char *device, int groupid) {
item = (struct devgroupdbitem *) malloc(sizeof(struct devgroupdbitem));
if (item == NULL) {
fputs("new_devgroup(): could not allocate internal data.\n", stderr);
DEBUG_CMD(Debug_Message("new_devgroup(): could not allocate internal data"));
exit(MAPID_MEM_ALLOCATION_ERROR);
}
item->device = strdup(device);
......@@ -189,7 +190,7 @@ int devgroupdb_acquire_rw_lock(char *filename) {
if(fd == -1) {
fd = open(filename, O_RDWR | O_CREAT, 0660); /* write */
if(fd == -1) {
fprintf(stderr, "devgroupdb_acquire_rw_lock(): could not open devgroupdb %s.\n", filename);
DEBUG_CMD(Debug_Message("devgroupdb_acquire_rw_lock(): could not open devgroupdb %s", filename));
exit(EXIT_FAILURE);
} else {
mapi_group = getgrnam(MAPI_GROUP_NAME);
......@@ -200,7 +201,7 @@ int devgroupdb_acquire_rw_lock(char *filename) {
}
if(fcntl(fd, F_SETLKW, &fl) == -1) { /* Note: BLOCKING until acquired. */
fputs("devgroupdb_acquire_rw_lock(): could not acquire.\n", stderr);
DEBUG_CMD(Debug_Message("devgroupdb_acquire_rw_lock(): could not acquire"));
exit(EXIT_FAILURE);
}
......@@ -217,7 +218,7 @@ void devgroupdb_release_rw_lock(int fd) {
fl.l_pid = getpid();
if(fcntl(fd, F_SETLK, &fl) == -1) {
fputs("devgroupdb_acquire_rw_lock(): could not release.\n", stderr);
DEBUG_CMD(Debug_Message("devgroupdb_acquire_rw_lock(): could not release"));
exit(EXIT_FAILURE);
}
......@@ -355,7 +356,7 @@ struct devgroupdb *devgroupdb_open(int local) {
}
if(fd == -1) {
fprintf(stderr, "devgroupdb_open(): could not open devgroupdb.\n");
DEBUG_CMD(Debug_Message("devgroupdb_open(): could not open devgroupdb"));
exit(EXIT_FAILURE);
}
......
......@@ -139,7 +139,7 @@ int fhlp_create_semaphore(fhlp_sem_t *sem, int num)
return MDLIB_SEM_ERR;
if( semctl(sem->id, 0, SETVAL, argument) < 0) {
ERROR_CMD(printf("Error setting semaphore (%s) [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
DEBUG_CMD(Debug_Message("ERROR: setting semaphore (%s)", strerror(errno)));
return MDLIB_SEM_ERR;
}
......@@ -149,17 +149,15 @@ int fhlp_create_semaphore(fhlp_sem_t *sem, int num)
mapi_group = getgrnam(MAPI_GROUP_NAME);
if (mapi_group != NULL) {
if (semctl(sem->id, 0, IPC_STAT, &sem_data) < 0) {
WARNING_CMD(printf("Warning: semctl IPC_STAT of %d failed (%s) [%s:%d]\n",
sem->id,strerror(errno),__FILE__,__LINE__));
DEBUG_CMD(Debug_Message("WARNING: semctl IPC_STAT of %d failed (%s)", sem->id, strerror(errno)));
}
sem_data.sem_perm.gid = mapi_group->gr_gid;
if (semctl(sem->id, 0, IPC_SET, &sem_data) != 0) {
WARNING_CMD(printf("Warning: semctl IPC_SET of %d failed (%s) [%s:%d]\n",
sem->id,strerror(errno),__FILE__,__LINE__));
DEBUG_CMD(Debug_Message("WARNING: semctl IPC_SET of %d failed (%s)", sem->id, strerror(errno)));
}
}
DEBUG_CMD(printf("Semaphore created. key=%d, id=%d, file=%s [%s:%d]\n",sem->key,sem->id,sem->fname,__FILE__,__LINE__));
DEBUG_CMD(Debug_Message("Semaphore created. key=%d, id=%d, file=%s", sem->key, sem->id, sem->fname));
return 0;
}
......@@ -167,14 +165,14 @@ int fhlp_create_semaphore(fhlp_sem_t *sem, int num)
void fhlp_free_semaphore(fhlp_sem_t *sem)
{
if (semctl(sem->id,0,IPC_RMID)) {
WARNING_CMD(printf("Could not free semaphore id=%d (%s) [%s:%d]\n",sem->id,strerror(errno),__FILE__,__LINE__));
DEBUG_CMD(Debug_Message("WARNING: Could not free semaphore id=%d (%s)", sem->id, strerror(errno)));
}
if (remove(sem->fname)<0) {
WARNING_CMD(printf("Could not remove semaphore file %s (%s) [%s:%d]\n",sem->fname,strerror(errno),__FILE__,__LINE__));
DEBUG_CMD(Debug_Message("WARNING: Could not remove semaphore file %s (%s)", sem->fname, strerror(errno)));
}
DEBUG_CMD(printf("Removed semaphore id=%d [%s:%d]\n",sem->id,__FILE__,__LINE__));
DEBUG_CMD(Debug_Message("Removed semaphore id=%d", sem->id));
}
......
......@@ -6,6 +6,7 @@
#include <string.h>
#include <pthread.h>
#include "flist.h"
#include "debug.h"
int flist_append(flist_t *list,int id,void *data)
{
......@@ -13,7 +14,7 @@ int flist_append(flist_t *list,int id,void *data)
if(list == NULL)
{
fprintf(stderr,"flist_append in NULL List\n");
DEBUG_CMD(Debug_Message("flist_append in NULL list"));
return -1;