[netcf-devel] [PATCH 1/7] Moving of more functions to utility files

Jonas Eriksson jonas.j.eriksson at ericsson.com
Thu Jul 23 12:37:02 UTC 2009


dutil.{c,h}: Added defnode, make_netcf_if, run1

drv_initscripts.c: Removed defnode, make_netcf_if, run1
---
 src/drv_initscripts.c |   47 -------------------------------------------
 src/dutil.c           |   53 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/dutil.h           |   11 ++++++++++
 3 files changed, 64 insertions(+), 47 deletions(-)

diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index d4e2259..dc8d471 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -91,30 +91,6 @@ static const char *const subif_paths[] = {
     "MASTER", "BRIDGE"
 };
 
-ATTRIBUTE_FORMAT(printf, 4, 5)
-static int defnode(struct netcf *ncf, const char *name, const char *value,
-                   const char *format, ...) {
-    struct augeas *aug = get_augeas(ncf);
-    va_list ap;
-    char *expr = NULL;
-    int r, created;
-
-    va_start(ap, format);
-    r = vasprintf (&expr, format, ap);
-    va_end (ap);
-    if (r < 0)
-        expr = NULL;
-    ERR_THROW(r < 0, ncf, ENOMEM, "failed to format node expression");
-
-    r = aug_defnode(aug, name, expr, value, &created);
-    ERR_THROW(r < 0, ncf, EOTHER, "failed to define node %s", name);
-
-    /* Fallthrough intentional */
- error:
-    free(expr);
-    return (r < 0) ? -1 : created;
-}
-
 static int is_slave(struct netcf *ncf, const char *intf) {
     for (int s = 0; s < ARRAY_CARDINALITY(subif_paths); s++) {
         int r;
@@ -376,21 +352,6 @@ int drv_num_of_interfaces(struct netcf *ncf, unsigned int flags) {
     return list_interface_ids(ncf, 0, NULL, flags, "DEVICE");
 }
 
-static struct netcf_if *make_netcf_if(struct netcf *ncf, char *name) {
-    int r;
-    struct netcf_if *result = NULL;
-
-    r = make_ref(result);
-    ERR_THROW(r < 0, ncf, ENOMEM, NULL);
-    result->ncf = ref(ncf);
-    result->name = name;
-    return result;
-
- error:
-    unref(result, netcf_if);
-    return result;
-}
-
 struct netcf_if *drv_lookup_by_name(struct netcf *ncf, const char *name) {
     struct netcf_if *nif = NULL;
     char *pathx = NULL;
@@ -836,14 +797,6 @@ const char *drv_mac_string(struct netcf_if *nif) {
  * Bringing interfaces up/down
  */
 
-static void run1(struct netcf *ncf, const char *prog, const char *name) {
-    const char *const argv[] = {
-        prog, name, NULL
-    };
-
-    run_program(ncf, argv);
-}
-
 int drv_if_up(struct netcf_if *nif) {
     static const char *const ifup = "ifup";
     struct netcf *ncf = nif->ncf;
diff --git a/src/dutil.c b/src/dutil.c
index bb03f39..28832b3 100644
--- a/src/dutil.c
+++ b/src/dutil.c
@@ -125,6 +125,30 @@ struct augeas *get_augeas(struct netcf *ncf) {
     return NULL;
 }
 
+ATTRIBUTE_FORMAT(printf, 4, 5)
+int defnode(struct netcf *ncf, const char *name, const char *value,
+                   const char *format, ...) {
+    struct augeas *aug = get_augeas(ncf);
+    va_list ap;
+    char *expr = NULL;
+    int r, created;
+
+    va_start(ap, format);
+    r = vasprintf (&expr, format, ap);
+    va_end (ap);
+    if (r < 0)
+        expr = NULL;
+    ERR_THROW(r < 0, ncf, ENOMEM, "failed to format node expression");
+
+    r = aug_defnode(aug, name, expr, value, &created);
+    ERR_THROW(r < 0, ncf, EOTHER, "failed to define node %s", name);
+
+    /* Fallthrough intentional */
+ error:
+    free(expr);
+    return (r < 0) ? -1 : created;
+}
+
 int aug_fmt_match(struct netcf *ncf, char ***matches, const char *fmt, ...) {
     struct augeas *aug = NULL;
     char *path = NULL;
@@ -301,6 +325,22 @@ int is_active(struct netcf *ncf, const char *intf) {
     return ((ifr.ifr_flags & IFF_UP) == IFF_UP);
 }
 
+/* Create a new netcf if instance for interface NAME */
+struct netcf_if *make_netcf_if(struct netcf *ncf, char *name) {
+    int r;
+    struct netcf_if *result = NULL;
+
+    r = make_ref(result);
+    ERR_THROW(r < 0, ncf, ENOMEM, NULL);
+    result->ncf = ref(ncf);
+    result->name = name;
+    return result;
+
+ error:
+    unref(result, netcf_if);
+    return result;
+}
+
 /*
  * Test interface
  */
@@ -349,6 +389,19 @@ int dutil_put_aug(struct netcf *ncf, const char *aug_xml, char **ncf_xml) {
 }
 
 /*
+ * Bringing interfaces up/down
+ */
+
+/* Run the program PROG with the single argument ARG */
+void run1(struct netcf *ncf, const char *prog, const char *arg) {
+    const char *const argv[] = {
+        prog, arg, NULL
+    };
+
+    run_program(ncf, argv);
+}
+
+/*
  * Local variables:
  *  indent-tabs-mode: nil
  *  c-indent-level: 4
diff --git a/src/dutil.h b/src/dutil.h
index b22c512..6dc05e2 100644
--- a/src/dutil.h
+++ b/src/dutil.h
@@ -48,6 +48,11 @@ int xasprintf(char **strp, const char *format, ...);
 /* Get or create the augeas instance from NCF */
 struct augeas *get_augeas(struct netcf *ncf);
 
+/* Define a node inside the augeas tree */
+ATTRIBUTE_FORMAT(printf, 4, 5)
+int defnode(struct netcf *ncf, const char *name, const char *value,
+                   const char *format, ...);
+
 /* Format a path by doing a printf of FMT and the var args, then call
    AUG_MATCH on that path. Sets NCF->ERRCODE on error */
 ATTRIBUTE_FORMAT(printf, 3, 4)
@@ -83,12 +88,18 @@ int init_ioctl_fd(struct netcf *ncf);
 /* Check if the interface INTF is up using a ioctl call */
 int is_active(struct netcf *ncf, const char *intf);
 
+/* Create a new netcf if instance for interface NAME */
+struct netcf_if *make_netcf_if(struct netcf *ncf, char *name);
+
 /* Transform the interface XML NCF_XML into Augeas XML AUG_XML */
 int dutil_get_aug(struct netcf *ncf, const char *ncf_xml, char **aug_xml);
 
 /* Transform the Augeas XML AUG_XML into interface XML NCF_XML */
 int dutil_put_aug(struct netcf *ncf, const char *aug_xml, char **ncf_xml);
 
+/* Run the program PROG with the single argument ARG */
+void run1(struct netcf *ncf, const char *prog, const char *arg);
+
 #endif
 
 /*
-- 
1.6.2



More information about the netcf-devel mailing list