Looking for "damon.cfg" in PREFIX/etc/damon.cfg and bailing out if fails
This commit is contained in:
parent
f1db0c7a76
commit
81b0cfa01b
19
Makefile
19
Makefile
|
@ -1,4 +1,9 @@
|
|||
PACKAGE = Probe
|
||||
VERSION = 0.0.0
|
||||
SUBDIRS = src
|
||||
RM = rm -f
|
||||
LN = ln -sf
|
||||
TAR = tar -czvf
|
||||
|
||||
|
||||
all: subdirs
|
||||
|
@ -12,10 +17,22 @@ clean:
|
|||
distclean:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) distclean) || exit; done
|
||||
|
||||
dist:
|
||||
$(RM) -r $(PACKAGE)-$(VERSION)
|
||||
$(LN) . $(PACKAGE)-$(VERSION)
|
||||
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz \
|
||||
$(PACKAGE)-$(VERSION)/src/probe.c \
|
||||
$(PACKAGE)-$(VERSION)/src/damon.c \
|
||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/config.h \
|
||||
$(PACKAGE)-$(VERSION)/project.conf
|
||||
$(RM) $(PACKAGE)-$(VERSION)
|
||||
|
||||
install: all
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) install) || exit; done
|
||||
|
||||
uninstall:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) uninstall) || exit; done
|
||||
|
||||
.PHONY: all subdirs clean distclean install uninstall
|
||||
.PHONY: all subdirs clean distclean dist install uninstall
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
package=Probe
|
||||
version=0.0.0
|
||||
config=h
|
||||
|
||||
subdirs=src
|
||||
dist=Makefile
|
||||
dist=Makefile,config.h
|
||||
|
|
26
src/damon.c
26
src/damon.c
|
@ -11,9 +11,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "../config.h"
|
||||
|
||||
#define DAMON_DEFAULT_REFRESH 10
|
||||
|
||||
#ifndef ETCDIR
|
||||
# define ETCDIR PREFIX "/etc"
|
||||
#endif
|
||||
|
||||
|
||||
/* types */
|
||||
typedef struct _Host
|
||||
|
@ -26,6 +31,7 @@ typedef struct _Host
|
|||
|
||||
|
||||
/* DaMon */
|
||||
/* types */
|
||||
typedef struct _DaMon
|
||||
{
|
||||
unsigned int refresh;
|
||||
|
@ -33,10 +39,16 @@ typedef struct _DaMon
|
|||
unsigned int hosts_cnt;
|
||||
Event * event;
|
||||
} DaMon;
|
||||
|
||||
/* functions */
|
||||
/* private */
|
||||
static int _damon_error(char * message, int ret);
|
||||
|
||||
/* public */
|
||||
/* _damon */
|
||||
static int _damon_init(DaMon * damon);
|
||||
static void _damon_destroy(DaMon * damon);
|
||||
static int _damon_refresh(DaMon * damon);
|
||||
|
||||
static int _damon(void)
|
||||
{
|
||||
DaMon damon;
|
||||
|
@ -56,7 +68,10 @@ static int _damon_error(char * message, int ret)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* _damon_init */
|
||||
static int _init_config(DaMon * damon);
|
||||
static int _damon_refresh(DaMon * damon);
|
||||
|
||||
static int _damon_init(DaMon * damon)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
@ -73,10 +88,13 @@ static int _damon_init(DaMon * damon)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* _init_config */
|
||||
static int _config_hosts(DaMon * damon, Config * config, char * hosts);
|
||||
|
||||
static int _init_config(DaMon * damon)
|
||||
{
|
||||
Config * config;
|
||||
char * filename = ETCDIR "/damon.cfg";
|
||||
char * p;
|
||||
char * q;
|
||||
int tmp;
|
||||
|
@ -86,10 +104,12 @@ static int _init_config(DaMon * damon)
|
|||
damon->refresh = DAMON_DEFAULT_REFRESH;
|
||||
damon->hosts = NULL;
|
||||
damon->hosts_cnt = 0;
|
||||
if(config_load(config, "damon.cfg") != 0) /* FIXME multiple filenames */
|
||||
if(config_load(config, filename) != 0)
|
||||
{
|
||||
fprintf(stderr, "DaMon: %s: Could not load configuration\n",
|
||||
filename);
|
||||
config_delete(config);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
if((p = config_get(config, "", "refresh")) != NULL)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user