[netcf-devel] [PATCH 1/1] API: ncf_close now returns an int
David Lutterkort
lutter at redhat.com
Mon Jul 13 20:58:41 UTC 2009
Since struct netcf is ref counted, users can call it before they release
all references to it - that needs to be flagged as an error.
* src/netcf.h (ncf_close): changed prototype
* src/netcf.c: new error code NETCF_EINUSE, check refcount in ncf_close
---
src/netcf.c | 10 ++++++++--
src/netcf.h | 15 +++++++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/netcf.c b/src/netcf.c
index b1a5c4e..f2c545d 100644
--- a/src/netcf.c
+++ b/src/netcf.c
@@ -50,7 +50,8 @@ static const char *const errmsgs[] = {
"XML parser failed", /* EXMLPARSER */
"XML invalid", /* EXMLINVALID */
"required entry missing", /* ENOENT */
- "failed to execute external program" /* EEXEC */
+ "failed to execute external program", /* EEXEC */
+ "instance still in use" /* EINUSE */
};
static void free_netcf(struct netcf *ncf) {
@@ -91,11 +92,16 @@ int ncf_init(struct netcf **ncf, const char *root) {
return -2;
}
-void ncf_close(struct netcf *ncf) {
+int ncf_close(struct netcf *ncf) {
API_ENTRY(ncf);
+ ERR_COND_BAIL(ncf->ref > 1, ncf, EINUSE);
+
drv_close(ncf);
unref(ncf, netcf);
+ return 0;
+ error:
+ return -1;
}
/* Number of known interfaces and list of them.
diff --git a/src/netcf.h b/src/netcf.h
index e9978fd..786aac5 100644
--- a/src/netcf.h
+++ b/src/netcf.h
@@ -46,7 +46,10 @@ typedef enum {
NETCF_EXMLPARSER, /* XML parser choked */
NETCF_EXMLINVALID, /* XML invalid in some form */
NETCF_ENOENT, /* Required entry in a tree is missing */
- NETCF_EEXEC /* external program execution failed or returned non-0 */
+ NETCF_EEXEC, /* external program execution failed or returned
+ * non-0 */
+ NETCF_EINUSE /* attempt to close a netcf instance that is still
+ * used by other data structures */
} netcf_errcode_t;
@@ -72,7 +75,15 @@ typedef enum {
*/
int ncf_init(struct netcf **netcf, const char *root);
-void ncf_close(struct netcf *);
+/* Close the connection to netcf and release any resources associated with
+ * it. It is an error to call this function before all data structeres
+ * retrieved using this netcf instance have been free'd; in particular, any
+ * struct netcf_if retrieved with this netcf instance must be cleaned up
+ * with NCF_IF_FREE before calling this function.
+ *
+ * Returns 0 on success, and -1 on error.
+ */
+int ncf_close(struct netcf *);
/* Number of known interfaces and list of them. For listing, interfaces are
* identified by their name.
--
1.6.0.6
More information about the netcf-devel
mailing list