]> Nishi Git Mirror - mokou.git/commitdiff
add an option to output in stderr instead of syslog
authorNishi <nishi@nishi.boats>
Fri, 6 Sep 2024 09:55:53 +0000 (09:55 +0000)
committerNishi <nishi@nishi.boats>
Fri, 6 Sep 2024 09:55:53 +0000 (09:55 +0000)
git-svn-id: file:///raid/svn-personal/mokou/trunk@4 35d6bad2-6c5c-c749-ada2-a2c82cb3bd79

Mokou/log.c
Mokou/main.c
Mokou/mk_service.h
Mokou/service.c

index 33c1a6108f5d50a9c10ea76410ce43a903b24a8d..cccbd7a88603c1301ce14008fc8a3c14bb40cf74 100644 (file)
@@ -3,7 +3,15 @@
 #include "mk_log.h"
 
 #include <syslog.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+bool mk_syslog = true;
 
 void mk_log(const char* log){
-       syslog(LOG_INFO, log);
+       if(mk_syslog){
+               syslog(LOG_INFO, log);
+       }else{
+               fprintf(stderr, "%s\n", log);
+       }
 }
index 6a6c6005a3f994672c00c0fa15fc9d2b913aa882..04763ed662554cb664e354961a45417a25960608 100644 (file)
@@ -3,13 +3,28 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
 
 #include "mk_service.h"
 #include "mk_log.h"
 #include "mk_util.h"
 #include "mk_version.h"
 
+extern bool mk_syslog;
+
 int main(int argc, char** argv){
+       int i;
+       for(i = 1; i < argc; i++){
+               if(argv[i][0] == '-'){
+                       if(strcmp(argv[i], "--stderr") == 0 || strcmp(argv[i], "-S") == 0){
+                               mk_syslog = false;
+                       }else{
+                               fprintf(stderr, "%s: %s: unknown flag\n", argv[0], argv[i]);
+                               return 1;
+                       }
+               }
+       }
        if(getuid() != 0){
                fprintf(stderr, "Run me as root.\n");
                return 1;
index 27947a400670e655141ce84d30f550d63e5c19e3..c5017e4c7702c749160086adbce41496c8b1fd9f 100644 (file)
@@ -4,7 +4,7 @@
 #define __MK_SERVICE_H__
 
 struct mk_service {
-       char* name;
+       char* description;
        char* exec;
        char* pidfile;
 };
index 0439a833600594de05c596e8feecc311c6b0ee2c..265d3c5687d47204ccedd644fec9080a62a37850 100644 (file)
@@ -17,9 +17,9 @@ 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);
+                       if(services[i]->description != NULL) free(services[i]->description);
+                       if(services[i]->exec != NULL) free(services[i]->exec);
+                       if(services[i]->pidfile != NULL) free(services[i]->pidfile);
                        free(services[i]);
                }
                free(services);
@@ -110,6 +110,11 @@ void mk_service_scan(void){
                                                char* log = mk_strcat3("Adding ", desc == NULL ? path : desc, " to the list");
                                                mk_log(log);
                                                free(log);
+
+                                               struct mk_service* serv = malloc(sizeof(*serv));
+                                               serv->description = desc != NULL ? mk_strdup(desc) : NULL;
+                                               serv->exec = mk_strdup(exec);
+                                               serv->pidfile = mk_strdup(pidfile);
                                        }
 
                                        if(desc != NULL) free(desc);