batch checking from config

This commit is contained in:
Jonathan Santis 2024-09-11 11:31:04 +02:00
parent 632efc640d
commit ffe88a7133
3 changed files with 17 additions and 4 deletions

2
config
View File

@ -1,3 +1,5 @@
/org/freedesktop/systemd1/unit/NetworkManager_2dwait_2donline_2eservice
/org/freedesktop/systemd1/unit/NetworkManager_2eservice
/systemd/blalbla/1
/systemd/blalbla/2
/systemd/blalbla/3

View File

@ -9,7 +9,7 @@ int loadConfig(char *file, char **str_entry,int size)
int i=0;
bool terminate=false;
FILE *f_config;
char temp_str[64];
char temp_str[256];
printf("\nopening config file\n");
f_config = fopen("config","r");
@ -19,8 +19,10 @@ int loadConfig(char *file, char **str_entry,int size)
{
printf("for loop:%d\n",i);
printf("str:%s\n",str_entry[i]);
if(fgets(temp_str,64,f_config)!=NULL)
if(fgets(temp_str,256,f_config)!=NULL)
{
temp_str[strcspn(temp_str,"\n")]=0;
str_entry[i]=strdup(temp_str);
printf("module path:%s",str_entry[i]);
}

13
main.c
View File

@ -83,6 +83,7 @@ int main(int argc,char *argv[])
for(i=0;str_entry[i];i++)
{
printf("entry in config:%s\n",str_entry[i]);
GetSendStatus(connection,str_entry[i]);
}
}
else
@ -158,7 +159,14 @@ int GetSendStatus(DBusConnection *connection,char *objectpath)
{
char *result=0;
int ret = systemdUnitCall(connection,objectpath,"Get","SubState",&result);
checkState(objectpath,result);
if(ret == 0)
{
checkState(objectpath,result);
}
else
{
fprintf(stderr,"could not call systemdunit");
}
return ret;
}
@ -409,6 +417,7 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
if(ret_msg == NULL)
{
fprintf(stderr,"error ond receiving message from peer\n");
return 1;
}
else
{
@ -474,7 +483,7 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
if(dbus_error_is_set(&error))
{
fprintf(stderr,"%s\n",error.message);
return -1;
return 1;
}
return 0;
}