From 0fb0373460e10e698fa51fb570e1745643bdb985 Mon Sep 17 00:00:00 2001 From: Nishi Date: Fri, 6 Sep 2024 09:55:53 +0000 Subject: [PATCH] add an option to output in stderr instead of syslog git-svn-id: file:///raid/svn-personal/mokou/trunk@4 35d6bad2-6c5c-c749-ada2-a2c82cb3bd79 --- Mokou/log.c | 10 +++++++++- Mokou/main.c | 15 +++++++++++++++ Mokou/mk_service.h | 2 +- Mokou/service.c | 11 ++++++++--- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Mokou/log.c b/Mokou/log.c index 33c1a61..cccbd7a 100644 --- a/Mokou/log.c +++ b/Mokou/log.c @@ -3,7 +3,15 @@ #include "mk_log.h" #include +#include +#include + +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); + } } diff --git a/Mokou/main.c b/Mokou/main.c index 6a6c600..04763ed 100644 --- a/Mokou/main.c +++ b/Mokou/main.c @@ -3,13 +3,28 @@ #include #include #include +#include +#include #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; diff --git a/Mokou/mk_service.h b/Mokou/mk_service.h index 27947a4..c5017e4 100644 --- a/Mokou/mk_service.h +++ b/Mokou/mk_service.h @@ -4,7 +4,7 @@ #define __MK_SERVICE_H__ struct mk_service { - char* name; + char* description; char* exec; char* pidfile; }; diff --git a/Mokou/service.c b/Mokou/service.c index 0439a83..265d3c5 100644 --- a/Mokou/service.c +++ b/Mokou/service.c @@ -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); -- 2.43.0