Skip to content

Instantly share code, notes, and snippets.

@nbyouri
Created March 20, 2016 22:03
Show Gist options
  • Save nbyouri/1a8d8051f3c27ce66a6e to your computer and use it in GitHub Desktop.
Save nbyouri/1a8d8051f3c27ce66a6e to your computer and use it in GitHub Desktop.
dbus_shutdown
CODE:
-----
#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>
/*
* Test program requesting shutdown to dbus
*/
int main(void) {
DBusGConnection *conn;
DBusGProxy *proxy = NULL;
GError *err = NULL;
gboolean result = FALSE;
gboolean allow_save;
conn = dbus_g_bus_get(DBUS_BUS_SESSION, &err);
if (conn == NULL) {
errx(EXIT_FAILURE, "Failed to connect to dbus...\n");
}
printf("Connected to dbus...\n");
proxy = dbus_g_proxy_new_for_name_owner(conn,
"org.xfce.SessionManager",
"/org/xfce/SessionManager",
"org.xfce.Session.Manager",
&err);
if (proxy == NULL) {
errx(EXIT_FAILURE, "Failed to get proxy...\n");
}
result = dbus_g_proxy_call(proxy, "Shutdown", &err,
G_TYPE_BOOLEAN, allow_save,
G_TYPE_INVALID, G_TYPE_INVALID);
char *can = result ? "can" : "cannot";
printf("%s shutdown\n", can);
g_object_unref(proxy);
g_error_free(err);
return EXIT_SUCCESS;
}
OUTPUT:
-------
Connected to dbus...
** (process:2369): CRITICAL **: marshal_basic: assertion 'b == TRUE || b == FALSE' failed
** (process:2369): CRITICAL **: Could not marshal argument 0 for Shutdown: type gboolean, value TRUE
cannot shutdown
OS:
---
NetBSD netbsd.home.p4 7.99.26 NetBSD 7.99.26 (GENERIC) #0: Mon Feb 22 18:15:35 CET 2016 [email protected]:/home/youri/cvs/src/sys/arch/amd64/compile/obj/GENERIC amd64
USER:
-----
uid=1000(youri) gid=100(users) groups=100(users),0(wheel),5(operator),1003(pulse),1004(pulseacc),1005(pulsert)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment