From: Nishi Date: Thu, 5 Sep 2024 18:31:51 +0000 (+0000) Subject: progress X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=da66e84cebf727def371d5c3520758b52388f9fc;p=mokou.git progress git-svn-id: file:///raid/svn-personal/mokou/trunk@2 35d6bad2-6c5c-c749-ada2-a2c82cb3bd79 --- diff --git a/Control/Makefile b/Control/Makefile new file mode 100644 index 0000000..88a5fb6 --- /dev/null +++ b/Control/Makefile @@ -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 diff --git a/Control/main.c b/Control/main.c new file mode 100644 index 0000000..c1885e1 --- /dev/null +++ b/Control/main.c @@ -0,0 +1,4 @@ +/* $Id$ */ + +int main(int argc, char** argv){ +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cd5d3e5 --- /dev/null +++ b/Makefile @@ -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 diff --git a/Mokou/Makefile b/Mokou/Makefile new file mode 100644 index 0000000..57ff221 --- /dev/null +++ b/Mokou/Makefile @@ -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 diff --git a/Mokou/log.c b/Mokou/log.c new file mode 100644 index 0000000..33c1a61 --- /dev/null +++ b/Mokou/log.c @@ -0,0 +1,9 @@ +/* $Id$ */ + +#include "mk_log.h" + +#include + +void mk_log(const char* log){ + syslog(LOG_INFO, log); +} diff --git a/Mokou/main.c b/Mokou/main.c new file mode 100644 index 0000000..b7d4fe0 --- /dev/null +++ b/Mokou/main.c @@ -0,0 +1,14 @@ +/* $Id$ */ + +#include +#include + +#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(); +} diff --git a/Mokou/mk_log.h b/Mokou/mk_log.h new file mode 100644 index 0000000..bc41731 --- /dev/null +++ b/Mokou/mk_log.h @@ -0,0 +1,8 @@ +/* $Id$ */ + +#ifndef __MK_LOG_H__ +#define __MK_LOG_H__ + +void mk_log(const char* log); + +#endif diff --git a/Mokou/mk_service.h b/Mokou/mk_service.h new file mode 100644 index 0000000..27947a4 --- /dev/null +++ b/Mokou/mk_service.h @@ -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 diff --git a/Mokou/mk_util.h b/Mokou/mk_util.h new file mode 100644 index 0000000..680ef7c --- /dev/null +++ b/Mokou/mk_util.h @@ -0,0 +1,13 @@ +/* $ID$ */ + +#ifndef __MK_UTIL_H__ +#define __MK_UTIL_H__ + +#include + +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 diff --git a/Mokou/service.c b/Mokou/service.c new file mode 100644 index 0000000..58fa194 --- /dev/null +++ b/Mokou/service.c @@ -0,0 +1,43 @@ +/* $Id$ */ + +#include "mk_service.h" + +#include +#include + +#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."); + } +} diff --git a/Mokou/util.c b/Mokou/util.c new file mode 100644 index 0000000..aff928a --- /dev/null +++ b/Mokou/util.c @@ -0,0 +1,34 @@ +/* $Id$ */ + +#include "mk_util.h" + +#include +#include + +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; +} diff --git a/Platform/generic.mk b/Platform/generic.mk new file mode 100644 index 0000000..ac9d896 --- /dev/null +++ b/Platform/generic.mk @@ -0,0 +1,7 @@ +# $Id$ + +CC = cc +CFLAGS = -std=c99 -g -DPREFIX=\"$(PREFIX)\" +LDFLAGS = +LIBS = -lpthread +EXEC =