Merge pull request #468 from bebehei/dbus-acquisition-message

Improve wording of DBus name lost error message
This commit is contained in:
Nikos Tsipinakis 2018-01-05 21:50:36 +02:00 committed by GitHub
commit 18df78c115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -425,9 +425,14 @@ static void on_name_acquired(GDBusConnection *connection,
/* /*
* Get the PID of the current process, which acquired FDN DBus Name. * Get the PID of the current process, which acquired FDN DBus Name.
* *
* If name or vendor specified, the name and vendor
* will get additionally get via the FDN GetServerInformation method
*
* Returns: valid PID, else -1 * Returns: valid PID, else -1
*/ */
static int dbus_get_fdn_pid(GDBusConnection *connection) static int dbus_get_fdn_daemon_info(GDBusConnection *connection,
char **name,
char **vendor)
{ {
char *owner = NULL; char *owner = NULL;
GError *error = NULL; GError *error = NULL;
@ -455,6 +460,28 @@ static int dbus_get_fdn_pid(GDBusConnection *connection)
return pid; return pid;
} }
GVariant *daemoninfo;
if (name || vendor) {
daemoninfo = g_dbus_proxy_call_sync(
proxy_fdn,
FDN_IFAC ".GetServerInformation",
NULL,
G_DBUS_CALL_FLAGS_NONE,
/* It's not worth to wait for the info
* longer than half a second when dying */
500,
NULL, /* cancelable */
&error);
}
if (error) {
/* Ignore the error, we may still be able to retrieve the PID */
g_error_free(error);
error = NULL;
} else {
g_variant_get(daemoninfo, "(ssss)", name, vendor, NULL, NULL);
}
owner = g_dbus_proxy_get_name_owner(proxy_fdn); owner = g_dbus_proxy_get_name_owner(proxy_fdn);
proxy_dbus = g_dbus_proxy_new_sync( proxy_dbus = g_dbus_proxy_new_sync(
@ -493,6 +520,8 @@ static int dbus_get_fdn_pid(GDBusConnection *connection)
g_object_unref(proxy_fdn); g_object_unref(proxy_fdn);
g_object_unref(proxy_dbus); g_object_unref(proxy_dbus);
g_free(owner); g_free(owner);
if (daemoninfo)
g_variant_unref(daemoninfo);
if (pidinfo) if (pidinfo)
g_variant_unref(pidinfo); g_variant_unref(pidinfo);
@ -505,10 +534,11 @@ static void on_name_lost(GDBusConnection *connection,
gpointer user_data) gpointer user_data)
{ {
if (connection) { if (connection) {
int pid = dbus_get_fdn_pid(connection); char *name = NULL;
int pid = dbus_get_fdn_daemon_info(connection, &name, NULL);
if (pid > 0) if (pid > 0)
fprintf(stderr, "Cannot acquire '"FDN_NAME"': " fprintf(stderr, "Cannot acquire '"FDN_NAME"': "
"Name is acquired by PID '%d'.\n", pid); "Name is acquired by '%s' with PID '%d'.\n", name, pid);
else else
fprintf(stderr, "Cannot acquire '"FDN_NAME"'.\n"); fprintf(stderr, "Cannot acquire '"FDN_NAME"'.\n");