This commit is contained in:
ccppi 2024-09-06 09:44:21 +02:00
parent 8c4815cd7e
commit 5872d5a21a

18
main.c
View File

@ -21,7 +21,7 @@ int main(void)
dbus_bool_t allow_user=0; dbus_bool_t allow_user=0;
DBusConnection *connection=NULL; DBusConnection *connection=NULL;
DBusError error; DBusError error;
char *result; char *result=NULL;
dbus_error_init(&error); dbus_error_init(&error);
connection = dbus_bus_get(DBUS_BUS_SESSION,&error);//DBUS_BUS_SYSTEM connection = dbus_bus_get(DBUS_BUS_SESSION,&error);//DBUS_BUS_SYSTEM
@ -68,10 +68,11 @@ int main(void)
//org/freedesktop/systemd1 //org/freedesktop/systemd1
//systemdCall(connection,"GetUnit","timers.target"); //systemdCall(connection,"GetUnit","timers.target");
//systemdCall(connection,"ListUnits",NULL); //systemdCall(connection,"ListUnits",NULL);
printf("&result:%p",&result);
systemdUnitCall(connection,"/org/freedesktop/systemd1/unit/timers_2etarget","Get","SubState",&result); systemdUnitCall(connection,"/org/freedesktop/systemd1/unit/timers_2etarget","Get","SubState",&result);
printf("\n\nresult systemdUnitCall: %s\n",result);
systemdUnitCall(connection,"/org/freedesktop/systemd1/unit/sysinit_2etarget","Get","SubState",&result); systemdUnitCall(connection,"/org/freedesktop/systemd1/unit/sysinit_2etarget","Get","SubState",&result);
printf("result systemdUnitCall: %s\n",result); printf("\n\nresult systemdUnitCall: %s\n",result);
gotify_message("https://5ccppi.org:4433/message?token=ApPFbwayM5zDXf3","anothertitle","anothermessage"); gotify_message("https://5ccppi.org:4433/message?token=ApPFbwayM5zDXf3","anothertitle","anothermessage");
return 0; return 0;
@ -239,7 +240,6 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
DBusMessageIter array_iter; DBusMessageIter array_iter;
DBusMessageIter variant_iter; DBusMessageIter variant_iter;
result=NULL;
char *reply_msg=NULL; char *reply_msg=NULL;
int ret1,ret2; int ret1,ret2;
char *param2 = "org.freedesktop.systemd1.Unit"; char *param2 = "org.freedesktop.systemd1.Unit";
@ -301,6 +301,7 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
if(ret1 == DBUS_TYPE_STRING) if(ret1 == DBUS_TYPE_STRING)
{ {
printf("succesfull received message\narg type %c\n",ret1); printf("succesfull received message\narg type %c\n",ret1);
printf("[func]reply_msg:%p , &reply_msg:%p , *reply_msg:%p\n", reply_msg,&reply_msg,*reply_msg);
dbus_message_iter_get_basic(&reply_iter,&reply_msg); dbus_message_iter_get_basic(&reply_iter,&reply_msg);
printf("Received message:%s\n",reply_msg); printf("Received message:%s\n",reply_msg);
} }
@ -311,12 +312,9 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
printf("str_val:%s\n",type); printf("str_val:%s\n",type);
if(type[0] == DBUS_TYPE_STRING) if(type[0] == DBUS_TYPE_STRING)
{ {
// result = malloc(sizeof(char)*64); printf("[func]&result:%p , result:%p",&result,result);
dbus_message_iter_get_basic(&variant_iter,*result); dbus_message_iter_get_basic(&variant_iter,result);
// printf("result inside function:%s\n",*result);
} }
//dbus_message_iter_get_basic(&reply_iter,&value);
} }
if(ret1 == DBUS_TYPE_ARRAY) if(ret1 == DBUS_TYPE_ARRAY)
{ {
@ -336,7 +334,6 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
while(ret3 != DBUS_TYPE_INVALID) while(ret3 != DBUS_TYPE_INVALID)
{ {
ret3 = dbus_message_iter_get_arg_type(&sub_iter); ret3 = dbus_message_iter_get_arg_type(&sub_iter);
//printf("arr_sub_iter:%c\n",ret3);
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);
@ -345,7 +342,6 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
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("i2:%d\n",i2);