提交 d9b04947 编写于 作者: E Eric Blake

datatypes: avoid redundant __FUNCTION__

virLibConnError already includes __FUNCTION__ in its output, so we
were redundant.  Furthermore, clang warns that __FUNCTION__ is not
a string literal (at least __FUNCTION__ will never contain %, so
it was not a security risk).

* src/datatypes.c: Replace __FUNCTION__ with a descriptive string.
上级 fe053dbe
/* /*
* datatypes.h: management of structs for public data types * datatypes.h: management of structs for public data types
* *
* Copyright (C) 2006-2010 Red Hat, Inc. * Copyright (C) 2006-2011 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -310,8 +310,8 @@ virUnrefConnect(virConnectPtr conn) { ...@@ -310,8 +310,8 @@ virUnrefConnect(virConnectPtr conn) {
int refs; int refs;
if ((!VIR_IS_CONNECT(conn))) { if ((!VIR_IS_CONNECT(conn))) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return(-1); return -1;
} }
virMutexLock(&conn->lock); virMutexLock(&conn->lock);
DEBUG("unref connection %p %d", conn, conn->refs); DEBUG("unref connection %p %d", conn, conn->refs);
...@@ -344,9 +344,17 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) { ...@@ -344,9 +344,17 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virDomainPtr ret = NULL; virDomainPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) { if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return(NULL); return NULL;
}
if (name == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
return NULL;
}
if (uuid == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
return NULL;
} }
virMutexLock(&conn->lock); virMutexLock(&conn->lock);
...@@ -455,8 +463,8 @@ virUnrefDomain(virDomainPtr domain) { ...@@ -455,8 +463,8 @@ virUnrefDomain(virDomainPtr domain) {
int refs; int refs;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) { if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("bad domain or no connection"));
return(-1); return -1;
} }
virMutexLock(&domain->conn->lock); virMutexLock(&domain->conn->lock);
DEBUG("unref domain %p %s %d", domain, domain->name, domain->refs); DEBUG("unref domain %p %s %d", domain, domain->name, domain->refs);
...@@ -490,9 +498,17 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) { ...@@ -490,9 +498,17 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virNetworkPtr ret = NULL; virNetworkPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) { if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return(NULL); return NULL;
}
if (name == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
return NULL;
}
if (uuid == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
return NULL;
} }
virMutexLock(&conn->lock); virMutexLock(&conn->lock);
...@@ -593,8 +609,9 @@ virUnrefNetwork(virNetworkPtr network) { ...@@ -593,8 +609,9 @@ virUnrefNetwork(virNetworkPtr network) {
int refs; int refs;
if (!VIR_IS_CONNECTED_NETWORK(network)) { if (!VIR_IS_CONNECTED_NETWORK(network)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG,
return(-1); _("bad network or no connection"));
return -1;
} }
virMutexLock(&network->conn->lock); virMutexLock(&network->conn->lock);
DEBUG("unref network %p %s %d", network, network->name, network->refs); DEBUG("unref network %p %s %d", network, network->name, network->refs);
...@@ -629,9 +646,13 @@ virInterfacePtr ...@@ -629,9 +646,13 @@ virInterfacePtr
virGetInterface(virConnectPtr conn, const char *name, const char *mac) { virGetInterface(virConnectPtr conn, const char *name, const char *mac) {
virInterfacePtr ret = NULL; virInterfacePtr ret = NULL;
if ((!VIR_IS_CONNECT(conn)) || (name == NULL)) { if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return(NULL); return NULL;
}
if (name == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
return NULL;
} }
/* a NULL mac from caller is okay. Treat it as blank */ /* a NULL mac from caller is okay. Treat it as blank */
...@@ -775,8 +796,9 @@ virUnrefInterface(virInterfacePtr iface) { ...@@ -775,8 +796,9 @@ virUnrefInterface(virInterfacePtr iface) {
int refs; int refs;
if (!VIR_IS_CONNECTED_INTERFACE(iface)) { if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG,
return(-1); _("bad interface or no connection"));
return -1;
} }
virMutexLock(&iface->conn->lock); virMutexLock(&iface->conn->lock);
DEBUG("unref interface %p %s %d", iface, iface->name, iface->refs); DEBUG("unref interface %p %s %d", iface, iface->name, iface->refs);
...@@ -807,13 +829,22 @@ virUnrefInterface(virInterfacePtr iface) { ...@@ -807,13 +829,22 @@ virUnrefInterface(virInterfacePtr iface) {
* Returns a pointer to the network, or NULL in case of failure * Returns a pointer to the network, or NULL in case of failure
*/ */
virStoragePoolPtr virStoragePoolPtr
virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uuid) { virGetStoragePool(virConnectPtr conn, const char *name,
const unsigned char *uuid) {
virStoragePoolPtr ret = NULL; virStoragePoolPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) { if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return(NULL); return NULL;
}
if (name == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
return NULL;
}
if (uuid == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
return NULL;
} }
virMutexLock(&conn->lock); virMutexLock(&conn->lock);
...@@ -915,8 +946,9 @@ virUnrefStoragePool(virStoragePoolPtr pool) { ...@@ -915,8 +946,9 @@ virUnrefStoragePool(virStoragePoolPtr pool) {
int refs; int refs;
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG,
return(-1); _("bad storage pool or no connection"));
return -1;
} }
virMutexLock(&pool->conn->lock); virMutexLock(&pool->conn->lock);
DEBUG("unref pool %p %s %d", pool, pool->name, pool->refs); DEBUG("unref pool %p %s %d", pool, pool->name, pool->refs);
...@@ -948,12 +980,21 @@ virUnrefStoragePool(virStoragePoolPtr pool) { ...@@ -948,12 +980,21 @@ virUnrefStoragePool(virStoragePoolPtr pool) {
* Returns a pointer to the storage vol, or NULL in case of failure * Returns a pointer to the storage vol, or NULL in case of failure
*/ */
virStorageVolPtr virStorageVolPtr
virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, const char *key) { virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
const char *key) {
virStorageVolPtr ret = NULL; virStorageVolPtr ret = NULL;
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (key == NULL)) { if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return(NULL); return NULL;
}
if (name == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
return NULL;
}
if (key == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing key"));
return NULL;
} }
virMutexLock(&conn->lock); virMutexLock(&conn->lock);
...@@ -1063,8 +1104,9 @@ virUnrefStorageVol(virStorageVolPtr vol) { ...@@ -1063,8 +1104,9 @@ virUnrefStorageVol(virStorageVolPtr vol) {
int refs; int refs;
if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) { if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG,
return(-1); _("bad storage volume or no connection"));
return -1;
} }
virMutexLock(&vol->conn->lock); virMutexLock(&vol->conn->lock);
DEBUG("unref vol %p %s %d", vol, vol->name, vol->refs); DEBUG("unref vol %p %s %d", vol, vol->name, vol->refs);
...@@ -1098,9 +1140,13 @@ virGetNodeDevice(virConnectPtr conn, const char *name) ...@@ -1098,9 +1140,13 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
{ {
virNodeDevicePtr ret = NULL; virNodeDevicePtr ret = NULL;
if ((!VIR_IS_CONNECT(conn)) || (name == NULL)) { if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return(NULL); return NULL;
}
if (name == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
return NULL;
} }
virMutexLock(&conn->lock); virMutexLock(&conn->lock);
...@@ -1230,8 +1276,16 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid, ...@@ -1230,8 +1276,16 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid,
virSecretPtr ret = NULL; virSecretPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
if (!VIR_IS_CONNECT(conn) || uuid == NULL || usageID == NULL) { if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return NULL;
}
if (uuid == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
return NULL;
}
if (usageID == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing usageID"));
return NULL; return NULL;
} }
virMutexLock(&conn->lock); virMutexLock(&conn->lock);
...@@ -1330,7 +1384,7 @@ virUnrefSecret(virSecretPtr secret) { ...@@ -1330,7 +1384,7 @@ virUnrefSecret(virSecretPtr secret) {
int refs; int refs;
if (!VIR_IS_CONNECTED_SECRET(secret)) { if (!VIR_IS_CONNECTED_SECRET(secret)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("bad secret or no connection"));
return -1; return -1;
} }
virMutexLock(&secret->conn->lock); virMutexLock(&secret->conn->lock);
...@@ -1424,9 +1478,17 @@ virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid) ...@@ -1424,9 +1478,17 @@ virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid)
virNWFilterPtr ret = NULL; virNWFilterPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) { if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
return(NULL); return NULL;
}
if (name == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
return NULL;
}
if (uuid == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing uuid"));
return NULL;
} }
virMutexLock(&conn->lock); virMutexLock(&conn->lock);
...@@ -1528,7 +1590,8 @@ virUnrefNWFilter(virNWFilterPtr pool) { ...@@ -1528,7 +1590,8 @@ virUnrefNWFilter(virNWFilterPtr pool) {
int refs; int refs;
if (!VIR_IS_CONNECTED_NWFILTER(pool)) { if (!VIR_IS_CONNECTED_NWFILTER(pool)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG,
_("bad nwfilter or no connection"));
return -1; return -1;
} }
virMutexLock(&pool->conn->lock); virMutexLock(&pool->conn->lock);
...@@ -1551,9 +1614,13 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name) ...@@ -1551,9 +1614,13 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name)
{ {
virDomainSnapshotPtr ret = NULL; virDomainSnapshotPtr ret = NULL;
if ((!VIR_IS_DOMAIN(domain)) || (name == NULL)) { if (!VIR_IS_DOMAIN(domain)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("bad domain"));
return(NULL); return NULL;
}
if (name == NULL) {
virLibConnError(VIR_ERR_INVALID_ARG, _("missing name"));
return NULL;
} }
virMutexLock(&domain->conn->lock); virMutexLock(&domain->conn->lock);
...@@ -1632,8 +1699,8 @@ virUnrefDomainSnapshot(virDomainSnapshotPtr snapshot) ...@@ -1632,8 +1699,8 @@ virUnrefDomainSnapshot(virDomainSnapshotPtr snapshot)
int refs; int refs;
if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) { if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(VIR_ERR_INVALID_ARG, _("not a snapshot"));
return(-1); return -1;
} }
virMutexLock(&snapshot->domain->conn->lock); virMutexLock(&snapshot->domain->conn->lock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册