--- /dev/null
+# $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
--- /dev/null
+/* $Id$ */
+
+int main(int argc, char** argv){
+}
--- /dev/null
+# $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
--- /dev/null
+# $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
--- /dev/null
+/* $Id$ */
+
+#include "mk_log.h"
+
+#include <syslog.h>
+
+void mk_log(const char* log){
+ syslog(LOG_INFO, log);
+}
--- /dev/null
+/* $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();
+}
--- /dev/null
+/* $Id$ */
+
+#ifndef __MK_LOG_H__
+#define __MK_LOG_H__
+
+void mk_log(const char* log);
+
+#endif
--- /dev/null
+/* $Id$ */
+
+#ifndef __MK_SERVICE_H__
+#define __MK_SERVICE_H__
+
+struct mk_service {
+ char* name;
+ char* exec;
+ char* pidfile;
+};
+
+void mk_service_scan(void);
+
+#endif
--- /dev/null
+/* $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
--- /dev/null
+/* $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.");
+ }
+}
--- /dev/null
+/* $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;
+}
--- /dev/null
+# $Id$
+
+CC = cc
+CFLAGS = -std=c99 -g -DPREFIX=\"$(PREFIX)\"
+LDFLAGS =
+LIBS = -lpthread
+EXEC =