}
+static char *
+virZPCIAddrKeyPrintHuman(const void *name)
+{
+ return g_strdup_printf("%u", *((unsigned int *)name));
+}
+
+
static void
virZPCIAddrKeyFree(void *name)
{
virZPCIAddrKeyCode,
virZPCIAddrKeyEqual,
virZPCIAddrKeyCopy,
+ virZPCIAddrKeyPrintHuman,
virZPCIAddrKeyFree)))
goto error;
virZPCIAddrKeyCode,
virZPCIAddrKeyEqual,
virZPCIAddrKeyCopy,
+ virZPCIAddrKeyPrintHuman,
virZPCIAddrKeyFree)))
goto error;
}
}
+static char *
+virCgroupPidPrintHuman(const void *name)
+{
+ return g_strdup_printf("%ld", (const long)name);
+}
+
+
int
virCgroupKillRecursiveInternal(virCgroupPtr group,
int signum,
virCgroupPidCode,
virCgroupPidEqual,
virCgroupPidCopy,
+ virCgroupPidPrintHuman,
NULL);
VIR_DEBUG("group=%p path=%s signum=%d", group, group->path, signum);
virHashKeyCode keyCode;
virHashKeyEqual keyEqual;
virHashKeyCopy keyCopy;
+ virHashKeyPrintHuman keyPrint;
virHashKeyFree keyFree;
};
return ret;
}
+
+static char *
+virHashStrPrintHuman(const void *name)
+{
+ return g_strdup(name);
+}
+
+
static void virHashStrFree(void *name)
{
VIR_FREE(name);
virHashKeyCode keyCode,
virHashKeyEqual keyEqual,
virHashKeyCopy keyCopy,
+ virHashKeyPrintHuman keyPrint,
virHashKeyFree keyFree)
{
virHashTablePtr table = NULL;
table->keyCode = keyCode;
table->keyEqual = keyEqual;
table->keyCopy = keyCopy;
+ table->keyPrint = keyPrint;
table->keyFree = keyFree;
if (VIR_ALLOC_N(table->table, size) < 0) {
virHashStrCode,
virHashStrEqual,
virHashStrCopy,
+ virHashStrPrintHuman,
virHashStrFree);
}
virHashStrCode,
virHashStrEqual,
virHashStrCopy,
+ virHashStrPrintHuman,
virHashStrFree);
}
entry->payload = userdata;
return 0;
} else {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Duplicate key"));
+ g_autofree char *keystr = NULL;
+
+ if (table->keyPrint)
+ keystr = table->keyPrint(name);
+
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Duplicate hash table key '%s'"), NULLSTR(keystr));
return -1;
}
}
* Returns a newly allocated copy of @name
*/
typedef void *(*virHashKeyCopy)(const void *name);
+/**
+ * virHashKeyPrintHuman:
+ * @name: the hash key
+ *
+ * Get a human readable version of the key for error messages. Caller
+ * will free the returned string.
+ *
+ * Returns a string representation of the key for use in error messages. Caller
+ * promises to always free the returned string.
+ */
+typedef char *(*virHashKeyPrintHuman) (const void *name);
+
/**
* virHashKeyFree:
* @name: the hash key
virHashKeyCode keyCode,
virHashKeyEqual keyEqual,
virHashKeyCopy keyCopy,
+ virHashKeyPrintHuman keyPrint,
virHashKeyFree keyFree);
void virHashFree(virHashTablePtr table);
ssize_t virHashSize(const virHashTable *table);