clean up spacing, clean up new lines

This commit is contained in:
Jonathan Santis 2024-09-19 09:26:07 +02:00
parent 142a850a5b
commit f22ae88b97
2 changed files with 13 additions and 48 deletions

View File

@ -39,13 +39,10 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
} }
*host = strdup(ptr_host); *host = strdup(ptr_host);
printf("my host is:%s\n",*host); printf("my host is:%s\n",*host);
}else{
fprintf(stderr,"keyword Hostname not found in config");
} }
}else{ }else{
break; break;
} }
} }
} }
else if(strcmp(temp_str,"[Services]")==0) else if(strcmp(temp_str,"[Services]")==0)
@ -91,13 +88,10 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
} }
*intervall = atoi(ptr_intervall); *intervall = atoi(ptr_intervall);
printf("intervall:%d\n",*intervall); printf("intervall:%d\n",*intervall);
}else{
fprintf(stderr,"keyword Intervall not found in config\n");
} }
}else{ }else{
break; break;
} }
} }
}else{ }else{
ret = fgets(temp_str,256,f_config); ret = fgets(temp_str,256,f_config);

51
main.c
View File

@ -231,8 +231,7 @@ int ServiceGetSendStatus(DBusConnection *connection,Service *service)
if(ret == 0) if(ret == 0)
{ {
checkState(service->name,result,service); checkState(service->name,result,service);
} else } else {
{
fprintf(stderr,"could not call systemdunit\n"); fprintf(stderr,"could not call systemdunit\n");
} }
return ret; return ret;
@ -242,7 +241,7 @@ int checkState(char *ServiceName,char *result,Service *service)
{ {
int i=0; int i=0;
char *error_strings[]={"dead","inactive","exited"}; char *error_strings[]={"dead","inactive","exited"};
printf("\n\nresult systemdUnitCall: %s\n",result); printf("result systemdUnitCall: %s\n",result);
for(i=0;i<(sizeof(error_strings)/sizeof(error_strings[0]));i++) for(i=0;i<(sizeof(error_strings)/sizeof(error_strings[0]));i++)
{ {
//printf("%s %ld\n",error_strings[i],sizeof(error_strings)/sizeof(error_strings[0])); //printf("%s %ld\n",error_strings[i],sizeof(error_strings)/sizeof(error_strings[0]));
@ -259,7 +258,7 @@ int checkState(char *ServiceName,char *result,Service *service)
gotify_message(service->host,ServiceName,"Running again, after crash"); gotify_message(service->host,ServiceName,"Running again, after crash");
} }
service->alerted=false; service->alerted=false;
printf("!!service seems okay!!\n"); printf("service seems okay!!\n");
return 0; return 0;
} }
} }
@ -296,12 +295,10 @@ int gotify_message(char *url,char *title,char *message)
} }
} }
ret = snprintf(post_buffer,sizeof(post_buffer),"title=%s&message=%s&priority=6",title,message); ret = snprintf(post_buffer,sizeof(post_buffer),"title=%s&message=%s&priority=6",title,message);
if(ret < sizeof(post_buffer)) if(ret < sizeof(post_buffer))
{ {
printf("%s %d\n",post_buffer,ret); printf("%s %d\n",post_buffer,ret);
if(curl) if(curl)
{ {
curl_easy_setopt(curl,CURLOPT_URL,url_buffer); curl_easy_setopt(curl,CURLOPT_URL,url_buffer);
@ -352,7 +349,7 @@ int systemdCall(DBusConnection *connection,char *method,char *param)
msg = dbus_message_new_method_call("org.freedesktop.systemd1","/org/freedesktop/systemd1","org.freedesktop.systemd1.Manager",method); msg = dbus_message_new_method_call("org.freedesktop.systemd1","/org/freedesktop/systemd1","org.freedesktop.systemd1.Manager",method);
if(NULL == msg) if(NULL == msg)
{ {
fprintf(stderr,"Message null, no message created"); fprintf(stderr,"Message null, no message created\n");
return 1; return 1;
} }
else else
@ -366,12 +363,9 @@ int systemdCall(DBusConnection *connection,char *method,char *param)
dbus_message_iter_init_append(msg,&iter); dbus_message_iter_init_append(msg,&iter);
if(!dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&param)) if(!dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&param))
{ {
fprintf(stderr,"Error appending"); fprintf(stderr,"Error appending\n");
return -1; return -1;
} }
else{
printf("message appended\n");
}
} }
ret_msg = dbus_connection_send_with_reply_and_block(connection,msg,DBUS_TIMEOUT_INFINITE,&error); ret_msg = dbus_connection_send_with_reply_and_block(connection,msg,DBUS_TIMEOUT_INFINITE,&error);
@ -409,15 +403,10 @@ int systemdCall(DBusConnection *connection,char *method,char *param)
ret2 = dbus_message_iter_get_arg_type(&array_iter); ret2 = dbus_message_iter_get_arg_type(&array_iter);
while(ret2 != DBUS_TYPE_INVALID) while(ret2 != DBUS_TYPE_INVALID)
{ {
//printf("type:%c\n",ret2);
//dbus_message_iter_get_basic(&array_iter,&reply_msg);
//printf("Received message:%s\n",reply_msg);
ret2 = dbus_message_iter_get_arg_type(&array_iter);
DBusMessageIter sub_iter; DBusMessageIter sub_iter;
int ret3; int ret3;
ret2 = dbus_message_iter_get_arg_type(&array_iter);
dbus_message_iter_recurse(&array_iter,&sub_iter); dbus_message_iter_recurse(&array_iter,&sub_iter);
ret3 = dbus_message_iter_get_arg_type(&sub_iter); ret3 = dbus_message_iter_get_arg_type(&sub_iter);
while(ret3 != DBUS_TYPE_INVALID) while(ret3 != DBUS_TYPE_INVALID)
@ -431,18 +420,12 @@ int systemdCall(DBusConnection *connection,char *method,char *param)
} }
ret3=dbus_message_iter_next(&sub_iter); ret3=dbus_message_iter_next(&sub_iter);
} }
ret2=dbus_message_iter_next(&array_iter); ret2=dbus_message_iter_next(&array_iter);
i2++; i2++;
//printf("i2:%d\n",i2);
} }
} }
//printf("iter:%c\n",ret1);
ret1=dbus_message_iter_next(&reply_iter); ret1=dbus_message_iter_next(&reply_iter);
} }
} }
if(dbus_error_is_set(&error)) if(dbus_error_is_set(&error))
{ {
@ -475,10 +458,6 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
fprintf(stderr,"Message null, no message created\n"); fprintf(stderr,"Message null, no message created\n");
return 1; return 1;
} }
else
{
printf("message created!\n");
}
if(param2 != NULL) if(param2 != NULL)
{ {
@ -488,17 +467,11 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
fprintf(stderr,"Error appending\n"); fprintf(stderr,"Error appending\n");
return -1; return -1;
} }
else{
printf("message appended\n");
}
if(!dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&param)) if(!dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&param))
{ {
fprintf(stderr,"Error appending\n"); fprintf(stderr,"Error appending\n");
return -1; return -1;
} }
else{
printf("message appended\n");
}
} }
ret_msg = dbus_connection_send_with_reply_and_block(connection,msg,DBUS_TIMEOUT_INFINITE,&error); ret_msg = dbus_connection_send_with_reply_and_block(connection,msg,DBUS_TIMEOUT_INFINITE,&error);
@ -512,7 +485,6 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
DBusMessageIter reply_iter; DBusMessageIter reply_iter;
dbus_message_iter_init(ret_msg,&reply_iter); dbus_message_iter_init(ret_msg,&reply_iter);
ret1=dbus_message_iter_get_arg_type(&reply_iter); ret1=dbus_message_iter_get_arg_type(&reply_iter);
printf("ret1 type:%c\n",ret1);
while(ret1 != DBUS_TYPE_INVALID) while(ret1 != DBUS_TYPE_INVALID)
{ {
if(ret1 == DBUS_TYPE_OBJECT_PATH) if(ret1 == DBUS_TYPE_OBJECT_PATH)
@ -532,19 +504,18 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
{ {
dbus_message_iter_recurse(&reply_iter,&variant_iter); dbus_message_iter_recurse(&reply_iter,&variant_iter);
char *type = dbus_message_iter_get_signature(&variant_iter); char *type = dbus_message_iter_get_signature(&variant_iter);
printf("str_val:%s\n",type); //printf("str_val:%s\n",type);
if(type[0] == DBUS_TYPE_STRING) if(type[0] == DBUS_TYPE_STRING)
{ {
printf("[func]&result:%p , result:%p",&result,result); //printf("[func]&result:%p , result:%p\n",&result,result);
dbus_message_iter_get_basic(&variant_iter,result); dbus_message_iter_get_basic(&variant_iter,result);
printf("\n--\n*result:%s",*result); //printf("*result:%s\n",*result);
} }
} }
if(ret1 == DBUS_TYPE_ARRAY) if(ret1 == DBUS_TYPE_ARRAY)
{ {
int element_count = dbus_message_iter_get_element_count(&reply_iter); int element_count = dbus_message_iter_get_element_count(&reply_iter);
printf("Array:Elem count %d\n",element_count); printf("Array:Elem count %d\n",element_count);
//ret2 = dbus_message_iter_get_element_type(&reply_iter);
dbus_message_iter_recurse(&reply_iter,&array_iter); dbus_message_iter_recurse(&reply_iter,&array_iter);
ret2 = dbus_message_iter_get_arg_type(&array_iter); ret2 = dbus_message_iter_get_arg_type(&array_iter);
while(ret2 != DBUS_TYPE_INVALID) while(ret2 != DBUS_TYPE_INVALID)
@ -558,7 +529,7 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
if(ret3 == DBUS_TYPE_STRING) if(ret3 == DBUS_TYPE_STRING)
{ {
dbus_message_iter_get_basic(&sub_iter,&reply_msg); dbus_message_iter_get_basic(&sub_iter,&reply_msg);
printf("%s\n",reply_msg); //printf("%s\n",reply_msg);
} }
ret3=dbus_message_iter_next(&sub_iter); ret3=dbus_message_iter_next(&sub_iter);
} }