This commit is contained in:
Jonathan Santis 2024-09-16 09:51:17 +02:00
parent 7bdc8c9080
commit e173906cdf
2 changed files with 41 additions and 6 deletions

View File

@ -2,12 +2,10 @@
#include<stdio.h> #include<stdio.h>
#include<stdlib.h> #include<stdlib.h>
#include<string.h> #include<string.h>
#include<stdbool.h>
int loadConfig(char *file, char **str_entry,int size) int loadConfig(char *file, char **str_entry,int size)
{ {
int i=0; int i=0;
bool terminate=false;
FILE *f_config; FILE *f_config;
char temp_str[256]; char temp_str[256];

45
main.c
View File

@ -5,6 +5,7 @@
#include<dbus/dbus.h> #include<dbus/dbus.h>
#include<stdbool.h> #include<stdbool.h>
#include<time.h> #include<time.h>
#include<unistd.h>
#include"config.h" #include"config.h"
@ -27,7 +28,7 @@ typedef struct service
{ {
char *name; char *name;
char *targetPath; char *targetPath;
bool alert; bool alerted;
int priority; int priority;
} Service; } Service;
@ -78,9 +79,8 @@ int main(int argc,char *argv[])
} }
else if(strcmp(argv[1],"config")==0) else if(strcmp(argv[1],"config")==0)
{ {
if(argc>2) if(argc==3)
{ {
Service service1[64];
char *str_entry[64]={'\0'}; char *str_entry[64]={'\0'};
int i=0; int i=0;
@ -91,9 +91,46 @@ int main(int argc,char *argv[])
GetSendStatus(connection,str_entry[i]); GetSendStatus(connection,str_entry[i]);
} }
} }
else if(argc==4 && strcmp(argv[3],"-d")==0)
{
printf("Running as a daemon\n");
char *str_entry[64]={'\0'};
int i=0;
Service services[64];
char *ptr_name=NULL;
loadConfig(argv[2],str_entry,64);
for(i=0;str_entry[i];i++)
{
services[i].targetPath = strdup(str_entry[i]);
ptr_name = strrchr(services[i].targetPath,'/');
if(ptr_name!=NULL)
{
printf("strrchr:%s\n",ptr_name);
services[i].name = strdup(ptr_name);
services[i].name = services[i].name + 1;
}
else{
fprintf(stderr,"does not seem to be a valid target\n");
services[i].name = strdup("Undefined");
}
services[i].alerted = false;
services[i].priority = 6;
printf("Name:%s\ntarget:%s\n",services[i].name,services[i].targetPath);
}
while(true)
{
for(i=0;str_entry[i];i++)
{
printf("entry in config:%s\n",str_entry[i]);
GetSendStatus(connection,str_entry[i]);
}
sleep(10);
}
}
else else
{ {
fprintf(stderr,"config requires a config file as argument\n"); fprintf(stderr,"config requires a config file as argument\nAppend -d for daemonizing\n");
} }
} }
else else