]> Nishi Git Mirror - mokou.git/commitdiff
adding some stuff
authorNishi <nishi@nishi.boats>
Fri, 6 Sep 2024 09:21:55 +0000 (09:21 +0000)
committerNishi <nishi@nishi.boats>
Fri, 6 Sep 2024 09:21:55 +0000 (09:21 +0000)
git-svn-id: file:///raid/svn-personal/mokou/trunk@3 35d6bad2-6c5c-c749-ada2-a2c82cb3bd79

Mokou/Makefile
Mokou/main.c
Mokou/mk_version.h [new file with mode: 0644]
Mokou/service.c
Mokou/version.c [new file with mode: 0644]

index 57ff2219e6fc62628879cee7faf23ddb741a3d94..656b1fb1f99c07c4bada79a6d99ff8fd8c0babc9 100644 (file)
@@ -5,7 +5,7 @@ include $(PWD)/Platform/$(PLATFORM).mk
 .PHONY: all clean
 .SUFFIXES: .c .o
 
-OBJS = main.o log.o service.o util.o
+OBJS = main.o log.o service.o util.o version.o
 
 all: mokou$(EXEC)
 
index b7d4fe0b8aac950bdb7955dac4290dd3b113f6cc..6a6c6005a3f994672c00c0fa15fc9d2b913aa882 100644 (file)
@@ -2,13 +2,20 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#include <stdlib.h>
 
 #include "mk_service.h"
+#include "mk_log.h"
+#include "mk_util.h"
+#include "mk_version.h"
 
 int main(int argc, char** argv){
        if(getuid() != 0){
                fprintf(stderr, "Run me as root.\n");
                return 1;
        }
+       char* log = mk_strcat3("Mokou version ", mk_get_version(), " starting up");
+       mk_log(log);
+       free(log);
        mk_service_scan();
 }
diff --git a/Mokou/mk_version.h b/Mokou/mk_version.h
new file mode 100644 (file)
index 0000000..73862a3
--- /dev/null
@@ -0,0 +1,8 @@
+/* $Id$ */
+
+#ifndef __MK_VERSION_H__
+#define __MK_VERSION_H__
+
+const char* mk_get_version(void);
+
+#endif
index 58fa1944436bacc94d36755f990cd66b6e44b5ee..0439a833600594de05c596e8feecc311c6b0ee2c 100644 (file)
@@ -2,8 +2,11 @@
 
 #include "mk_service.h"
 
+#include <stdio.h>
 #include <dirent.h>
 #include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
 
 #include "mk_log.h"
 #include "mk_util.h"
@@ -20,7 +23,10 @@ void mk_service_scan(void){
                        free(services[i]);
                }
                free(services);
+               mk_log("Cleaning up the list");
        }
+       services = malloc(sizeof(*services));
+       services[0] = NULL;
 
        mk_log("Scanning the service directory.");
 
@@ -33,6 +39,84 @@ void mk_service_scan(void){
                                char* str = mk_strcat("Reading ", path);
                                mk_log(str);
                                free(str);
+
+                               FILE* f = fopen(path, "r");
+                               if(f != NULL){
+                                       struct stat s;
+                                       stat(path, &s);
+                                       char* buffer = malloc(s.st_size + 1);
+                                       buffer[s.st_size] = 0;
+                                       fread(buffer, s.st_size, 1, f);
+                                       int i;
+                                       int incr = 0;
+
+                                       char* desc = NULL;
+                                       char* exec = NULL;
+                                       char* pidfile = NULL;
+                                       
+                                       for(i = 0;; i++){
+                                               if(buffer[i] == '\n' || buffer[i] == 0){
+                                                       char oldc = buffer[i];
+                                                       buffer[i] = 0;
+
+                                                       char* line = buffer + incr;
+
+                                                       if(strlen(line) > 0 && line[0] != '#'){
+                                                               int j;
+
+                                                               for(j = 0; line[j] != 0; j++){
+                                                                       if(line[j] == '='){
+                                                                               line[j] = 0;
+                                                                               
+                                                                               char* key = line;
+                                                                               char* value = line + j + 1;
+                                                                               if(strcmp(key, "description") == 0){
+                                                                                       if(desc != NULL) free(desc);
+                                                                                       desc = mk_strdup(value);
+                                                                               }else if(strcmp(key, "exec") == 0){
+                                                                                       if(exec != NULL) free(exec);
+                                                                                       exec = mk_strdup(value);
+                                                                               }else if(strcmp(key, "pidfile") == 0){
+                                                                                       if(pidfile != NULL) free(pidfile);
+                                                                                       pidfile = mk_strdup(value);
+                                                                               }
+       
+                                                                               break;
+                                                                       }
+                                                               }
+                                                       }
+
+                                                       incr = i + 1;
+                                                       if(oldc == 0) break;
+                                               }
+                                       }
+                                       fclose(f);
+
+                                       bool bad = false;
+                                       if(exec == NULL){
+                                               char* log = mk_strcat(desc == NULL ? path : desc, ": Missing exec");
+                                               mk_log(log);
+                                               free(log);
+                                               bad = true;
+                                       }
+                                       if(pidfile == NULL){
+                                               char* log = mk_strcat(desc == NULL ? path : desc, ": Missing pidfile");
+                                               mk_log(log);
+                                               free(log);
+                                               bad = true;
+                                       }
+
+                                       if(!bad){
+                                               char* log = mk_strcat3("Adding ", desc == NULL ? path : desc, " to the list");
+                                               mk_log(log);
+                                               free(log);
+                                       }
+
+                                       if(desc != NULL) free(desc);
+                                       if(exec != NULL) free(exec);
+                                       if(pidfile != NULL) free(pidfile);
+                               }
+
                                free(path);
                        }
                }
diff --git a/Mokou/version.c b/Mokou/version.c
new file mode 100644 (file)
index 0000000..b2fa85f
--- /dev/null
@@ -0,0 +1,9 @@
+/* $Id$ */
+
+#include "mk_version.h"
+
+const char* MOKOU_VERSION = "0.0";
+
+const char* mk_get_version(void){
+       return MOKOU_VERSION;
+}