progress
git-svn-id: file:///raid/svn-personal/mokou/trunk@2 35d6bad2-6c5c-c749-ada2-a2c82cb3bd79
This commit is contained in:
parent
3cd035788b
commit
da66e84ceb
19
Control/Makefile
Normal file
19
Control/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
include $(PWD)/Platform/$(PLATFORM).mk
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
.SUFFIXES: .c .o
|
||||||
|
|
||||||
|
OBJS = main.o
|
||||||
|
|
||||||
|
all: mokouctl$(EXEC)
|
||||||
|
|
||||||
|
mokouctl$(EXEC): $(OBJS)
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.exe mokouctl *.o
|
4
Control/main.c
Normal file
4
Control/main.c
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
int main(int argc, char** argv){
|
||||||
|
}
|
20
Makefile
Normal file
20
Makefile
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
PREFIX = /usr/local
|
||||||
|
PLATFORM = generic
|
||||||
|
PWD = `pwd`
|
||||||
|
FLAGS = PLATFORM=$(PLATFORM) PWD=$(PWD) PREFIX=$(PREFIX)
|
||||||
|
|
||||||
|
.PHONY: all clean ./Mokou ./Control
|
||||||
|
|
||||||
|
all: ./Mokou ./Control
|
||||||
|
|
||||||
|
./Mokou::
|
||||||
|
$(MAKE) -C $@ $(FLAGS)
|
||||||
|
|
||||||
|
./Control::
|
||||||
|
$(MAKE) -C $@ $(FLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -C ./Mokou $(FLAGS) clean
|
||||||
|
$(MAKE) -C ./Control $(FLAGS) clean
|
19
Mokou/Makefile
Normal file
19
Mokou/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
include $(PWD)/Platform/$(PLATFORM).mk
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
.SUFFIXES: .c .o
|
||||||
|
|
||||||
|
OBJS = main.o log.o service.o util.o
|
||||||
|
|
||||||
|
all: mokou$(EXEC)
|
||||||
|
|
||||||
|
mokou$(EXEC): $(OBJS)
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.exe mokou *.o
|
9
Mokou/log.c
Normal file
9
Mokou/log.c
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include "mk_log.h"
|
||||||
|
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
void mk_log(const char* log){
|
||||||
|
syslog(LOG_INFO, log);
|
||||||
|
}
|
14
Mokou/main.c
Normal file
14
Mokou/main.c
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "mk_service.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv){
|
||||||
|
if(getuid() != 0){
|
||||||
|
fprintf(stderr, "Run me as root.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
mk_service_scan();
|
||||||
|
}
|
8
Mokou/mk_log.h
Normal file
8
Mokou/mk_log.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef __MK_LOG_H__
|
||||||
|
#define __MK_LOG_H__
|
||||||
|
|
||||||
|
void mk_log(const char* log);
|
||||||
|
|
||||||
|
#endif
|
14
Mokou/mk_service.h
Normal file
14
Mokou/mk_service.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef __MK_SERVICE_H__
|
||||||
|
#define __MK_SERVICE_H__
|
||||||
|
|
||||||
|
struct mk_service {
|
||||||
|
char* name;
|
||||||
|
char* exec;
|
||||||
|
char* pidfile;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mk_service_scan(void);
|
||||||
|
|
||||||
|
#endif
|
13
Mokou/mk_util.h
Normal file
13
Mokou/mk_util.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/* $ID$ */
|
||||||
|
|
||||||
|
#ifndef __MK_UTIL_H__
|
||||||
|
#define __MK_UTIL_H__
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
char* mk_strcat(const char* a, const char* b);
|
||||||
|
char* mk_strcat3(const char* a, const char* b, const char* c);
|
||||||
|
char* mk_strdup(const char* a);
|
||||||
|
bool mk_endswith(const char* str, const char* end);
|
||||||
|
|
||||||
|
#endif
|
43
Mokou/service.c
Normal file
43
Mokou/service.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include "mk_service.h"
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "mk_log.h"
|
||||||
|
#include "mk_util.h"
|
||||||
|
|
||||||
|
struct mk_service** services = NULL;
|
||||||
|
|
||||||
|
void mk_service_scan(void){
|
||||||
|
if(services != NULL){
|
||||||
|
int i;
|
||||||
|
for(i = 0; services[i] != NULL; i++){
|
||||||
|
free(services[i]->name);
|
||||||
|
free(services[i]->exec);
|
||||||
|
free(services[i]->pidfile);
|
||||||
|
free(services[i]);
|
||||||
|
}
|
||||||
|
free(services);
|
||||||
|
}
|
||||||
|
|
||||||
|
mk_log("Scanning the service directory.");
|
||||||
|
|
||||||
|
DIR* dir = opendir(PREFIX "/etc/mokou");
|
||||||
|
if(dir != NULL){
|
||||||
|
struct dirent* d;
|
||||||
|
while((d = readdir(dir)) != NULL){
|
||||||
|
if(mk_endswith(d->d_name, ".conf")){
|
||||||
|
char* path = mk_strcat(PREFIX "/etc/mokou/", d->d_name);
|
||||||
|
char* str = mk_strcat("Reading ", path);
|
||||||
|
mk_log(str);
|
||||||
|
free(str);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
}else{
|
||||||
|
mk_log("Cannot open the directory.");
|
||||||
|
}
|
||||||
|
}
|
34
Mokou/util.c
Normal file
34
Mokou/util.c
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include "mk_util.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char* mk_strcat(const char* a, const char* b){
|
||||||
|
char* str = malloc(strlen(a) + strlen(b) + 1);
|
||||||
|
memcpy(str, a, strlen(a));
|
||||||
|
memcpy(str + strlen(a), b, strlen(b));
|
||||||
|
str[strlen(a) + strlen(b)] = 0;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* mk_strcat3(const char* a, const char* b, const char* c){
|
||||||
|
char* tmp = mk_strcat(a, b);
|
||||||
|
char* str = mk_strcat(tmp, c);
|
||||||
|
free(tmp);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* mk_strdup(const char* a){
|
||||||
|
return mk_strcat(a, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mk_endswith(const char* str, const char* end){
|
||||||
|
if(strlen(str) < strlen(end)) return false;
|
||||||
|
int i;
|
||||||
|
for(i = strlen(str) - strlen(end); str[i] != 0; i++){
|
||||||
|
if(str[i] != end[i - strlen(str) + strlen(end)]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
7
Platform/generic.mk
Normal file
7
Platform/generic.mk
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
CC = cc
|
||||||
|
CFLAGS = -std=c99 -g -DPREFIX=\"$(PREFIX)\"
|
||||||
|
LDFLAGS =
|
||||||
|
LIBS = -lpthread
|
||||||
|
EXEC =
|
Loading…
Reference in New Issue
Block a user