mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
libvirt,logging: cleanup VIR_XXX0()
These VIR_XXXX0 APIs make us confused, use the non-0-suffix APIs instead.
How do these coversions works? The magic is using the gcc extension of ##.
When __VA_ARGS__ is empty, "##" will swallow the "," in "fmt," to
avoid compile error.
example: origin after CPP
high_level_api("%d", a_int) low_level_api("%d", a_int)
high_level_api("a string") low_level_api("a string")
About 400 conversions.
8 special conversions:
VIR_XXXX0("") -> VIR_XXXX("msg") (avoid empty format) 2 conversions
VIR_XXXX0(string_literal_with_%) -> VIR_XXXX(%->%%) 0 conversions
VIR_XXXX0(non_string_literal) -> VIR_XXXX("%s", non_string_literal)
(for security) 6 conversions
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
This commit is contained in:
committed by
Eric Blake
parent
0e5a7ace8a
commit
b65f37a4a1
@@ -8,10 +8,8 @@
|
||||
#include <libvirt/libvirt.h>
|
||||
#include <libvirt/virterror.h>
|
||||
|
||||
#define VIR_DEBUG0(fmt) printf("%s:%d :: " fmt "\n", \
|
||||
__func__, __LINE__)
|
||||
#define VIR_DEBUG(fmt, ...) printf("%s:%d: " fmt "\n", \
|
||||
__func__, __LINE__, __VA_ARGS__)
|
||||
__func__, __LINE__, ##__VA_ARGS__)
|
||||
#define STREQ(a,b) (strcmp(a,b) == 0)
|
||||
|
||||
#ifndef ATTRIBUTE_UNUSED
|
||||
@@ -304,7 +302,7 @@ int main(int argc, char **argv)
|
||||
sigaction(SIGTERM, &action_stop, NULL);
|
||||
sigaction(SIGINT, &action_stop, NULL);
|
||||
|
||||
VIR_DEBUG0("Registering domain event cbs");
|
||||
VIR_DEBUG("Registering domain event cbs");
|
||||
|
||||
/* Add 2 callbacks to prove this works with more than just one */
|
||||
callback1ret = virConnectDomainEventRegister(dconn, myDomainEventCallback1,
|
||||
@@ -355,7 +353,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
VIR_DEBUG0("Deregistering event handlers");
|
||||
VIR_DEBUG("Deregistering event handlers");
|
||||
virConnectDomainEventDeregister(dconn, myDomainEventCallback1);
|
||||
virConnectDomainEventDeregisterAny(dconn, callback2ret);
|
||||
virConnectDomainEventDeregisterAny(dconn, callback3ret);
|
||||
@@ -365,7 +363,7 @@ int main(int argc, char **argv)
|
||||
virConnectDomainEventDeregisterAny(dconn, callback7ret);
|
||||
}
|
||||
|
||||
VIR_DEBUG0("Closing connection");
|
||||
VIR_DEBUG("Closing connection");
|
||||
if (dconn && virConnectClose(dconn) < 0) {
|
||||
printf("error closing\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user