#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);
+ }
}
#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;
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);
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);