summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2011-03-02 18:53:27 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2011-03-02 18:53:27 -0800
commit92a6e0844ffd1614eb30ae093d3e6e7e5540321f (patch)
treebd5e3aea16606d248cd010a7a3b3c883907d2af1 /src
parent521e99d155759a80b2b97c6d5b827d490426c0b6 (diff)
downloadvyatta-cfg-92a6e0844ffd1614eb30ae093d3e6e7e5540321f.tar.gz
vyatta-cfg-92a6e0844ffd1614eb30ae093d3e6e7e5540321f.zip
clean up commit dead code etc. etc. etc.
Diffstat (limited to 'src')
-rw-r--r--src/commit2.cpp725
-rw-r--r--src/common/common.c11
-rw-r--r--src/common/common.h6
-rw-r--r--src/common/unionfs.c225
4 files changed, 418 insertions, 549 deletions
diff --git a/src/commit2.cpp b/src/commit2.cpp
index 9e78a68..f3ec50f 100644
--- a/src/commit2.cpp
+++ b/src/commit2.cpp
@@ -9,6 +9,16 @@
#include "common/common.h"
#include "cli_path_utils.h"
+#define cond_plog(cond, prio, fmt, ...) do { \
+ if (cond) { \
+ printf(fmt "\n", ##__VA_ARGS__); \
+ syslog(prio, fmt, ##__VA_ARGS__) ;\
+ } \
+} while (0);
+
+#define dplog(fmt, ...) cond_plog(true, LOG_DEBUG, fmt, ##__VA_ARGS__);
+#define d_dplog(fmt, ...) cond_plog(g_debug, LOG_DEBUG, fmt, ##__VA_ARGS__);
+
boolean g_debug = FALSE;
boolean g_display_error_node = FALSE;
boolean g_coverage = FALSE;
@@ -21,18 +31,16 @@ boolean g_old_print_output = FALSE;
extern "C" void g_type_init();
+// this uses the vtw_act_type enum
const int ActionOrder[g_num_actions] = {
- // 4, //syntax
- // 5, //commit
- 6,
- 0,
- 1,
- // 2, //activate
- 3,
- 7
+ begin_act,
+ delete_act,
+ create_act,
+ update_act,
+ end_act
};
-
+// this corresponds to the vtw_act_type enum
static const char* ActionNames[top_act] = {
"delete", //0
"create", //1
@@ -103,17 +111,18 @@ char*
process_script_path(char* in);
/*
-NOTES: reverse: use the n-nary tree in commit2.c and only encapuslate data store. pass in func pointer for processing of commands below.
-
-also, the algorithm for collapsing the tree into a transaction list is:
-1) iterate through tree and mark all explicit transactions
-2) when done, prune the tree of all root explicit transactions
-3) Now iterate through remaining tree and remove each node and append to transaction list.
+ * NOTES: reverse: use the n-nary tree in commit2.c and only encapuslate
+ * data store. pass in func pointer for processing of commands below.
+ *
+ * also, the algorithm for collapsing the tree into a transaction list is:
+ * 1) iterate through tree and mark all explicit transactions
+ * 2) when done, prune the tree of all root explicit transactions
+ * 3) Now iterate through remaining tree and remove each node and append
+ * to transaction list.
*/
/**
*
- *
**/
void
usage(void)
@@ -137,7 +146,6 @@ usage(void)
/**
*
- *
**/
int
main(int argc, char** argv)
@@ -216,24 +224,20 @@ main(int argc, char** argv)
g_print_error_location_all = TRUE;
}
-
if (disable_hook == FALSE) {
execute_hook(PRE_COMMIT_HOOK_DIR,commit_comment);
}
initialize_output("Commit");
init_paths(TRUE);
- if (g_debug) {
- printf("commit2: starting up\n");
- syslog(LOG_DEBUG,"commit2: starting up");
- }
+ d_dplog("commit2: starting up");
if (get_config_lock() != 0) {
- fprintf(out_stream,"Configuration system temporarily locked due to another commit in progress\n");
+ fprintf(out_stream, "Configuration system temporarily locked "
+ "due to another commit in progress\n");
exit(1);
}
-
//get local session data plus configuration data
GNode *config_data = common_get_local_session_data();
if (g_node_n_children(config_data) == 0) {
@@ -279,8 +283,7 @@ main(int argc, char** argv)
//open the changes file and clear
FILE *fp_changes = fopen(COMMIT_CHANGES_FILE,"w");
if (fp_changes == NULL) {
- printf("commit2: Cannot access changes file, exiting\n");
- syslog(LOG_ERR,"commit2: Cannot access changes file, exiting");
+ cond_plog(true, LOG_ERR, "commit2: Cannot access changes file, exiting");
exit(0);
}
@@ -290,16 +293,11 @@ main(int argc, char** argv)
int i = 0;
do {
boolean success = FALSE;
- if (g_debug == TRUE) {
- if (trans_child_node != NULL && trans_child_node->data != NULL && ((struct VyattaNode*)(trans_child_node->data))->_data._name != NULL) {
- printf("commit2: Starting new transaction processing pass on root: %s\n", ((struct VyattaNode*)(trans_child_node->data))->_data._name);
- syslog(LOG_DEBUG,"commit2: Starting new transaction processing pass on root: %s", ((struct VyattaNode*)(trans_child_node->data))->_data._name);
- }
- else {
- printf("commit2: Starting new transaction processing pass on root:\n");
- syslog(LOG_DEBUG,"commit2: Starting new transaction processing pass on root:");
- }
- }
+ d_dplog("commit2: Starting new transaction processing pass on root: [%s]",
+ ((trans_child_node && trans_child_node->data
+ && ((struct VyattaNode*)(trans_child_node->data))->_data._name)
+ ? ((struct VyattaNode*)(trans_child_node->data))->_data._name
+ : ""));
if (break_priority) {
gpointer gp = ((GNode*)trans_child_node)->data;
@@ -331,16 +329,20 @@ main(int argc, char** argv)
//on each priority node now execute actions
nodes_visited_coll = NULL;
- if ((validate_configuration(trans_child_node, full_commit_check, &nodes_visited_coll) == TRUE) && (success = process_priority_node(trans_child_node)) == TRUE) {
+ if (validate_configuration(trans_child_node, full_commit_check,
+ &nodes_visited_coll) == TRUE
+ && (success = process_priority_node(trans_child_node)) == TRUE) {
//this below copies the node directory from the local to active location
//if this is true root skip
- if (trans_child_node != NULL && trans_child_node->data != NULL && strcmp(((struct VyattaNode*)(trans_child_node->data))->_data._path,"/") == 0) {
+ if (trans_child_node != NULL && trans_child_node->data != NULL
+ && strcmp(((struct VyattaNode*)(trans_child_node->data))
+ ->_data._path, "/") == 0) {
//no op, need better way to define true root
}
else {
if (disable_partial_commit == FALSE && g_dump_actions == FALSE) {
- // complete(comp_cp_node, test_mode);
- completed_root_node_coll = g_slist_append(completed_root_node_coll,comp_cp_node);
+ completed_root_node_coll
+ = g_slist_append(completed_root_node_coll, comp_cp_node);
}
}
}
@@ -351,10 +353,7 @@ main(int argc, char** argv)
if (success == FALSE) {
errors |= 1;
- if (g_debug == TRUE) {
- printf("commit2: Failed in processing node\n");
- syslog(LOG_DEBUG,"commit2: Failed in processing node\n");
- }
+ d_dplog("commit2: Failed in processing node");
}
else {
errors |= 2;
@@ -365,24 +364,19 @@ main(int argc, char** argv)
fflush(fp_changes);
++i;
- } while ((trans_child_node = (GNode*)g_node_nth_child((GNode*)trans_coll,(guint)i)) != NULL);
+ } while ((trans_child_node
+ = (GNode*) g_node_nth_child((GNode*) trans_coll,
+ (guint) i)) != NULL);
if (errors == 2) {
- // if (disable_partial_commit == TRUE && g_dump_actions == FALSE) {
- // completed_root_node_coll = g_slist_append(completed_root_node_coll,orig_node_tree);
- // }
/*
* Need to add to the following func below to clean up dangling .wh. files
*/
if (g_dump_actions == FALSE) {
- // complete(orig_node_tree, test_mode);
common_commit_copy_to_live_config(orig_node_tree, TRUE, test_mode);
common_commit_clean_temp_config(orig_node_tree, test_mode);
}
- if (g_debug == TRUE) {
- printf("commit2: successful commit, now cleaning up temp directories\n");
- syslog(LOG_DEBUG,"commit2: successful commit, now cleaning up temp directories");
- }
+ d_dplog("commit2: successful commit, now cleaning up temp directories");
}
else {
fprintf(out_stream,"Commit failed\n");
@@ -390,14 +384,7 @@ main(int argc, char** argv)
}
set_in_commit(FALSE);
-
- // cleanup(config_data);
- // cleanup(trans_child_node);
-
- if (g_debug) {
- printf("DONE\n");
- syslog(LOG_DEBUG,"DONE");
- }
+ d_dplog("DONE");
if (fp_changes != NULL) {
fclose(fp_changes);
@@ -424,7 +411,6 @@ main(int argc, char** argv)
exit (errors == 2 ? 0 : 1);
}
-
struct ExecuteHookData
{
char *_dir;
@@ -433,7 +419,6 @@ struct ExecuteHookData
/**
*
- *
**/
void
execute_hook(const char* dir, const char* comment)
@@ -446,11 +431,7 @@ execute_hook(const char* dir, const char* comment)
gparray = g_ptr_array_new();
DIR *dp;
if ((dp = opendir(dir)) == NULL){
- if (g_debug) {
- //could also be a terminating value now
- printf("could not open hook directory\n");
- syslog(LOG_DEBUG,"could not open hook directory");
- }
+ d_dplog("could not open hook directory");
return;
}
@@ -480,7 +461,6 @@ execute_hook(const char* dir, const char* comment)
/**
*
- *
**/
gboolean
execute_hook_compare_func(gconstpointer a, gconstpointer b, gpointer data)
@@ -495,7 +475,6 @@ execute_hook_compare_func(gconstpointer a, gconstpointer b, gpointer data)
/**
*
- *
**/
gboolean
execute_hook_func(GNode *node, gpointer data)
@@ -527,10 +506,8 @@ execute_hook_func(GNode *node, gpointer data)
return FALSE;
}
-
/**
*
- *
**/
static gboolean
process_func(GNode *node, gpointer data)
@@ -549,60 +526,67 @@ process_func(GNode *node, gpointer data)
int status = 0;
if (c->_def.actions &&
c->_def.actions[result->_action].vtw_list_head){
-
- if (g_debug) {
- if (d->_name != NULL) {
- printf("commit2::process_func(), calling process on : %s for action %d, type: %d, operation: %d, path: %s, disable state: %d\n",d->_name,result->_action,c->_def.def_type, op, d->_path,d->_disable_op);
- syslog(LOG_DEBUG,"commit2::process_func(), calling process on : %s for action %d, type: %d, operation: %d, path: %s, disable state: %d",d->_name,result->_action,c->_def.def_type, op, d->_path,d->_disable_op);
- }
- else {
- printf("commit2::process_func(), calling process on : [n/a] for action %d, operation: %d, path: %s, disable state: %d\n",result->_action, op, d->_path,d->_disable_op);
- syslog(LOG_DEBUG,"commit2::process_func(), calling process on : [n/a] for action %d, operation: %d, path: %s, disable state: %d",result->_action, op, d->_path, d->_disable_op);
- }
- }
+ d_dplog("commit2::process_func(), calling process on : %s for action "
+ "%d, type: %d, operation: %d, path: %s, disable state: %d",
+ (d->_name ? d->_name : "[n/a]"), result->_action,
+ (d->_name ? c->_def.def_type : -1), op, d->_path, d->_disable_op);
//FIRST LET'S COMPUTE THE DEACTIVATE->ACTIVATE OVERRIDE
if (d->_disable_op != K_NO_DISABLE_OP) {
if (IS_DELETE(op) && (d->_disable_op & K_ACTIVE_DISABLE_OP)) {
- return FALSE; //if this was actively disabled and is being deleted do nothing.
- }
- else if ((d->_disable_op & K_LOCAL_DISABLE_OP) && (d->_disable_op & K_ACTIVE_DISABLE_OP)) {
+ //if this was actively disabled and is being deleted do nothing.
+ return FALSE;
+ } else if ((d->_disable_op & K_LOCAL_DISABLE_OP)
+ && (d->_disable_op & K_ACTIVE_DISABLE_OP)) {
//no state change: deactivated
return FALSE; //skip operation on node
- }
- else if (!(d->_disable_op & K_LOCAL_DISABLE_OP) && (d->_disable_op & K_ACTIVE_DISABLE_OP)) {
+ } else if (!(d->_disable_op & K_LOCAL_DISABLE_OP)
+ && (d->_disable_op & K_ACTIVE_DISABLE_OP)) {
//node will be activated on commit
//LET'S SPOOF the operation... convert it to CREATE
op = K_CREATE_OP;
- }
- else if ((d->_disable_op & K_LOCAL_DISABLE_OP) && !(d->_disable_op & K_ACTIVE_DISABLE_OP)) {
+ } else if ((d->_disable_op & K_LOCAL_DISABLE_OP)
+ && !(d->_disable_op & K_ACTIVE_DISABLE_OP)) {
//node will be deactivated on commit
//LET'S SPOOF the operation... convert it to DELETE
op = K_DEL_OP;
}
}
- /*
- Needs to be cleaned up a bit such that this convoluted if clause is easier to read. Basically
- is says:
- if a node is SET, is not ACTIVE and is not a DELETE ACTION
- or
- if a node is SET, is ACTIVE, is not a DELETE ACTION or a CREATE ACTION
- or
- if a node is DELETE, is a DELETE ACTION or a END ACTION, or a BEGIN ACTION
+ /* Needs to be cleaned up a bit such that this convoluted if clause
+ * is easier to read.
+ * (XXX original comment no longer correct and therefore is removed.)
*/
- if ((IS_SET(op) && !IS_ACTIVE(op) && (result->_action != delete_act && result->_action != create_act)) ||
- (IS_CREATE(op) && !IS_ACTIVE(op) && (result->_action == begin_act || result->_action == end_act || result->_action == create_act || (result->_action == update_act && !c->_def.actions[create_act].vtw_list_head))) ||
- (IS_ACTIVE(op) && ((result->_action == begin_act) || (result->_action == end_act))) ||
- (IS_DELETE(op) && ((result->_action == delete_act) || (result->_action == begin_act) || (result->_action == end_act)) )) {
+ if ((IS_SET(op) && !IS_ACTIVE(op)
+ && (result->_action != delete_act && result->_action != create_act))
+ ||
+ (IS_CREATE(op) && !IS_ACTIVE(op)
+ && (result->_action == begin_act || result->_action == end_act
+ || result->_action == create_act
+ || (result->_action == update_act
+ && !c->_def.actions[create_act].vtw_list_head)))
+ ||
+ (IS_ACTIVE(op) && ((result->_action == begin_act)
+ || (result->_action == end_act)))
+ ||
+ (IS_DELETE(op) && ((result->_action == delete_act)
+ || (result->_action == begin_act)
+ || (result->_action == end_act)))) {
//NEED TO ADD IF CREATE, THEN CREATE OR UPDATE
//IF SET THEN UPDATE
- //let's skip the case where this is active and it's a delete--shouldn't be done, but needs to be include in the rule set above
- if (IS_DELETE(op) && IS_ACTIVE(op) && result->_action == delete_act && d->_disable_op == K_NO_DISABLE_OP) { //only apply this when no disable operation is set
+ /* let's skip the case where this is active and it's a
+ * delete--shouldn't be done, but needs to be include in the rule
+ * set above
+ */
+ if (IS_DELETE(op) && IS_ACTIVE(op) && result->_action == delete_act
+ && d->_disable_op == K_NO_DISABLE_OP) {
+ //only apply this when no disable operation is set
return FALSE;
}
- //let's skip any multi-node that does not have have a value (an empty multi-node)
+ /* let's skip any multi-node that does not have have a value
+ * (an empty multi-node)
+ */
if (c->_multi && node->children == NULL) {
return FALSE;
}
@@ -610,41 +594,39 @@ process_func(GNode *node, gpointer data)
//look at parent for multi tag
if (d->_value && d->_name) {
char *val = d->_name;
- if (c->_def.tag) { //need to handle the embedded multinode as a special case--should be fixed!
+ if (c->_def.tag) {
+ /* need to handle the embedded multinode as a special
+ * case--should be fixed!
+ */
val = (char*)clind_unescape(d->_name);
}
- if (g_debug) {
- printf("commit2::process_func(): @ value: %s\n",(char*)val);
- syslog(LOG_DEBUG,"commit2::process_func(): @ value: %s",(char*)val);
- }
+ d_dplog("commit2::process_func(): @ value: %s", (char *) val);
set_at_string(val); //embedded multinode value
}
else {
if (g_debug) {
- printf("commit2::process_func(): boolean value is: %d\n",d->_value);
- syslog(LOG_DEBUG,"commit2::process_func(): boolean value is: %d",d->_value);
- if (node->parent != NULL && ((struct VyattaNode*)(node->parent->data))->_data._name != NULL) {
- printf("commit2::process_func(): parent has a name and it is: %s\n",((struct VyattaNode*)(node->parent->data))->_data._name);
- syslog(LOG_DEBUG,"commit2::process_func(): parent has a name and it is: %s\n",((struct VyattaNode*)(node->parent->data))->_data._name);
+ dplog("commit2::process_func(): boolean value is: %d", d->_value);
+ if (node->parent != NULL
+ && ((struct VyattaNode*)(node->parent->data))->_data._name
+ != NULL) {
+ dplog("commit2::process_func(): parent has a name: %s",
+ ((struct VyattaNode*)(node->parent->data))->_data._name);
}
- printf("commit2::process_func(): @ value: [NULL]\n");
- syslog(LOG_DEBUG,"commit2::process_func(): @ value: [NULL]\n");
+ dplog("commit2::process_func(): @ value: [NULL]");
}
}
common_set_context(c->_path,d->_path);
- if (g_debug) {
- printf("Executing %s on this node\n", ActionNames[result->_action]);
- syslog(LOG_DEBUG,"Executing %s on this node\n", ActionNames[result->_action]);
- }
+ d_dplog("Executing %s on this node", ActionNames[result->_action]);
if (g_coverage) {
struct timeval t;
gettimeofday(&t,NULL);
- fprintf(out_stream,"[START] %lu:%lu, %s@%s",(unsigned long)t.tv_sec,(unsigned long)t.tv_usec,ActionNames[result->_action],d->_path);
+ fprintf(out_stream, "[START] %lu:%lu, %s@%s",
+ (unsigned long) t.tv_sec, (unsigned long) t.tv_usec,
+ ActionNames[result->_action], d->_path);
}
-
if (result->_action == delete_act) {
set_in_delete_action(TRUE);
}
@@ -652,7 +634,6 @@ process_func(GNode *node, gpointer data)
//set location env
setenv(ENV_DATA_PATH,d->_path,1);
-
if (a->_first && a->_last) {
setenv(ENV_SIBLING_POSITION,"FIRSTLAST",1);
}
@@ -679,44 +660,24 @@ process_func(GNode *node, gpointer data)
if (g_dump_actions == FALSE) {
//need to add g_print_error_location_all, and processed location
if (g_old_print_output == TRUE) {
- status = execute_list(c->_def.actions[result->_action].vtw_list_head,&c->_def,NULL,g_print_error_location_all);
+ status
+ = execute_list(c->_def.actions[result->_action].vtw_list_head,
+ &c->_def, NULL, g_print_error_location_all);
}
else {
char *p = process_script_path(d->_path);
- status = execute_list(c->_def.actions[result->_action].vtw_list_head,&c->_def,p,g_print_error_location_all);
+ status
+ = execute_list(c->_def.actions[result->_action].vtw_list_head,
+ &c->_def, p, g_print_error_location_all);
free(p);
}
- // status = execute_list(c->_def.actions[result->_action].vtw_list_head,&c->_def,NULL,g_print_error_location_all);
-
- /*
- if (strlen(outbuf) > 0) {
- if (strstr(outbuf,"_errloc_:[") != NULL) {
- if (g_print_error_location_all == FALSE) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
- fprintf(out_stream,"%s\n",outbuf+strlen("_errloc_:"));
- }
- else {
- fprintf(out_stream,"%s\n",outbuf);
- }
- }
- else {
- //currently set to format option for GUI client.
- if (p != NULL) {
- if (g_print_error_location_all == FALSE) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
- fprintf(out_stream,"[%s]\n%s\n",p,outbuf);
- }
- else {
- fprintf(out_stream,"_errloc_:[%s]\n%s\n",p,outbuf);
- }
- }
- }
- }
- */
-
- }
- else {
+ } else {
char buf[MAX_LENGTH_DIR_PATH*sizeof(char)];
sprintf(buf,"%s\t:\t%s",ActionNames[result->_action],d->_path);
- if (c->_def.multi) { //need to handle the embedded multinode as a special case--should be fixed!
+ if (c->_def.multi) {
+ /* need to handle the embedded multinode as a special
+ * case--should be fixed!
+ */
char *val = (char*)clind_unescape(d->_name);
strcat(buf,val);
free(val);
@@ -739,15 +700,14 @@ process_func(GNode *node, gpointer data)
}
if (!status) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
- syslog(LOG_ERR,"commit error for %s:[%s]\n",ActionNames[result->_action],d->_path);
+ syslog(LOG_ERR, "commit error for %s:[%s]",
+ ActionNames[result->_action],d->_path);
if (g_display_error_node) {
- fprintf(out_stream,"%s@_errloc_:[%s]\n",ActionNames[result->_action],d->_path);
+ fprintf(out_stream, "%s@_errloc_:[%s]\n",
+ ActionNames[result->_action], d->_path);
}
result->_err_code = 1;
- if (g_debug) {
- printf("commit2::process_func(): FAILURE: status: %d\n",status);
- syslog(LOG_DEBUG,"commit2::process_func(): FAILURE: status: %d",status);
- }
+ d_dplog("commit2::process_func(): FAILURE: status: %d", status);
return TRUE; //WILL STOP AT THIS POINT
}
}
@@ -755,7 +715,6 @@ process_func(GNode *node, gpointer data)
return FALSE;
}
-
/**
*
**/
@@ -803,9 +762,6 @@ process_script_path(char* in)
return ret;
}
-
-
-
/**
*
**/
@@ -814,27 +770,20 @@ complete(GSList *node_coll, boolean test_mode)
{
GSList *l;
for (l = node_coll; l; l = g_slist_next (l)) {
- gpointer gp = ((GNode*)l->data)->data;
- if (g_debug) {
- if (((struct VyattaNode*)gp)->_data._name != NULL) {
- printf("commit2::complete():name: %s, path: %s\n",((struct VyattaNode*)gp)->_data._name,((struct VyattaNode*)gp)->_data._path);
- syslog(LOG_DEBUG,"commit2::complete():name: %s, path: %s",((struct VyattaNode*)gp)->_data._name,((struct VyattaNode*)gp)->_data._path);
- }
- else {
- printf("commit2::complete()\n");
- syslog(LOG_DEBUG,"commit2::complete()");
- }
- }
- //on transactional nodes only, note to avoid calling this if a headless root
+ struct VyattaNode *gp = (struct VyattaNode *) ((GNode *) l->data)->data;
+ const char *np = gp->_data._name;
+ d_dplog("commit2::complete():name: [%s], path: [%s]",
+ (np ? np : ""), (np ? gp->_data._path : ""));
+ /* on transactional nodes only, note to avoid calling this if a
+ * headless root
+ */
common_commit_copy_to_live_config((GNode *) l->data, FALSE, test_mode);
}
return TRUE;
}
-
/**
*
- *
**/
gboolean
sort_func_priority(GNode *node, gpointer data)
@@ -844,7 +793,6 @@ sort_func_priority(GNode *node, gpointer data)
/**
*
- *
**/
gboolean
sort_func_simple(GNode *node, gpointer data)
@@ -852,30 +800,27 @@ sort_func_simple(GNode *node, gpointer data)
return sort_func(node,data,FALSE);
}
-
-
/**
*
- *
**/
gboolean
sort_func_priority_extended(GNode *node, gpointer data)
{
- gpointer gp = ((GNode*)node)->data;
+ struct VyattaNode *gp = (struct VyattaNode *) node->data;
+ struct Config *gcfg = &(gp->_config);
GNode *root_node = (GNode*)data;
//WILL STOP AT DEPTH OF 10 REFERENCES
//GET PARENT WORKING FIRST....
//change action state of node according to enclosing behavior
- if (((struct VyattaNode*)gp)->_config._priority_extended != NULL) { //only if priority is specified.
+ if (gcfg->_priority_extended) {
+ //only if priority is specified.
GNode *new_node = g_node_copy(node);
//NOW, we need to figure out where this node belongs in the priority chain
- if (strncmp(((struct VyattaNode*)gp)->_config._priority_extended,"PARENT",6) == 0) {
+ if (strncmp(gcfg->_priority_extended, "PARENT", 6) == 0) {
//needs to walk up parents until priority is found and insert there....
-
- //walk up chain until priority is found.
GNode *n = node;
while (TRUE) {
n = n->parent;
@@ -886,7 +831,7 @@ sort_func_priority_extended(GNode *node, gpointer data)
if (((struct VyattaNode*)nd)->_config._priority != LOWEST_PRIORITY) {
//means we are done--found anchor in parent
g_node_unlink(node);
- if (IS_DELETE(((struct VyattaNode*)gp)->_data._operation)) {
+ if (IS_DELETE(gp->_data._operation)) {
g_node_insert_before(root_node,n,new_node);
}
else {
@@ -894,80 +839,36 @@ sort_func_priority_extended(GNode *node, gpointer data)
}
break;
}
- /*
- else if (((struct VyattaNode*)gp)->_config._priority_extended != NULL) {
- //need to find references in other node tree....
-
- //PARSE OUT EXTENDED REFERENCES...
- for (int i = 0; i < ct; ++i) {
- //get dependency...what to do with dependencies on dependencies... might get big. recursion buddy....
- if (find_reference_anchor(orig_config, ((struct VyattaNode*)gp)->_config._priority_extended, cur_pri) != 0) {
- cur_pri = LOWEST_PRIORITY;
- }
- }
- break;
- }
- */
}
}
- else {
- /*
- //multiple dependencies should be placed outside the earliest (delete) or latest (create) reference
- if (find_reference_anchor(orig_config, ((struct VyattaNode*)gp)->_config._priority_extended, cur_pri) != 0) {
- cur_pri = LOWEST_PRIORITY;
- }
- */
- }
- /*
- //finds location for insertion
- while (sibling != NULL && cur_pri > ((struct VyattaNode*)(sibling->data))->_config._priority * 10) {
- sibling = sibling->next;
- if (sibling == NULL || ((struct VyattaNode*)gp)->_config._priority < ((struct VyattaNode*)(sibling->data))->_config._priority) {
- break;
- }
- }
-
- //I think that's it then...
- g_node_insert_before(root_node,sibling,new_node);
- }
- */
}
return FALSE;
}
-
/**
*
- *
**/
gboolean
sort_func(GNode *node, gpointer data, boolean priority_mode)
{
- gpointer gp = ((GNode*)node)->data;
+ struct VyattaNode *gp = (struct VyattaNode *) node->data;
+ struct Data *d = &(gp->_data);
GNode *root_node = (GNode*)data;
- if (g_debug) {
- if (((struct VyattaNode*)gp)->_data._name != NULL) {
- printf("commit2::sort_func(): %s, node count: %d\n",((struct VyattaNode*)gp)->_data._name,g_node_n_children(root_node));
- syslog(LOG_DEBUG,"commit2::sort_func(): %s, node count: %d",((struct VyattaNode*)gp)->_data._name,g_node_n_children(root_node));
- }
- else {
- printf("commit2::sort_func(): [n/a], node count: %d\n",g_node_n_children(root_node));
- syslog(LOG_DEBUG,"commit2::sort_func(): [n/a], node count: %d",g_node_n_children(root_node));
- }
- }
+ d_dplog("commit2::sort_func(): %s, node count: %d",
+ (d->_name ? d->_name : "[n/a]"), g_node_n_children(root_node));
- //FIRST LET'S COMPUTE THE DEACTIVATE->ACTIVATE OVERRIDE
- struct Data *d = &((struct VyattaNode*)gp)->_data;
+ // FIRST LET'S COMPUTE THE DEACTIVATE->ACTIVATE OVERRIDE
NODE_OPERATION op = d->_operation;
if (d->_disable_op != K_NO_DISABLE_OP) {
- if (!(d->_disable_op & K_LOCAL_DISABLE_OP) && (d->_disable_op & K_ACTIVE_DISABLE_OP)) {
- //node will be activated on commit
- //LET'S SPOOF the operation... convert it to CREATE
+ if (!(d->_disable_op & K_LOCAL_DISABLE_OP)
+ && (d->_disable_op & K_ACTIVE_DISABLE_OP)) {
+ //node will be activated on commit
+ //LET'S SPOOF the operation... convert it to CREATE
op = K_CREATE_OP;
- }
- else if ((d->_disable_op & K_LOCAL_DISABLE_OP) && !(d->_disable_op & K_ACTIVE_DISABLE_OP)) {
- //node will be deactivated on commit
- //LET'S SPOOF the operation... convert it to DELETE
+ } else if ((d->_disable_op & K_LOCAL_DISABLE_OP)
+ && !(d->_disable_op & K_ACTIVE_DISABLE_OP)) {
+ //node will be deactivated on commit
+ //LET'S SPOOF the operation... convert it to DELETE
op = K_DEL_OP;
}
}
@@ -993,8 +894,7 @@ sort_func(GNode *node, gpointer data, boolean priority_mode)
* on operator precendence to maintain the original logic.
*/
if (((/* c1 */ G_NODE_IS_ROOT(node) == FALSE)
- && (/* c2 */ ((struct VyattaNode*)gp)->_data._disable_op
- != K_NO_DISABLE_OP))
+ && (/* c2 */ d->_disable_op != K_NO_DISABLE_OP))
//added to support enclosing behavior of activated/deactivated
|| (((/* c3 */ IS_SET_OR_CREATE(op)) || (/* c4 */ IS_DELETE(op)))
&& (/* c5 */ IS_NOOP(((struct VyattaNode*)
@@ -1005,7 +905,8 @@ sort_func(GNode *node, gpointer data, boolean priority_mode)
while (TRUE) {
n = n->parent;
vtw_def def = ((struct VyattaNode*)(n->data))->_config._def;
- if (def.actions[end_act].vtw_list_head || def.actions[begin_act].vtw_list_head) {
+ if (def.actions[end_act].vtw_list_head
+ || def.actions[begin_act].vtw_list_head) {
enclosing = TRUE;
break;
}
@@ -1020,9 +921,6 @@ sort_func(GNode *node, gpointer data, boolean priority_mode)
while (TRUE) {
n = n->parent;
vtw_def def = ((struct VyattaNode*)(n->data))->_config._def;
- // ((struct VyattaNode*)(n->data))->_data._operation = ((struct VyattaNode*)gp)->_data._operation;
- //DON'T set active when only in disable state...
- // if (((struct VyattaNode*)(n->data))->_data._disable_op == K_NO_DISABLE_OP) {
if (((struct VyattaNode*)(n->data))->_data._operation == K_NO_OP) {
/* XXX this is ugly. _operation is intended to be a bitmap, in which
* case it doesn't make sense to make it an enum type (should
@@ -1035,7 +933,8 @@ sort_func(GNode *node, gpointer data, boolean priority_mode)
((struct VyattaNode*)(n->data))->_data._operation
= (NODE_OPERATION) op;
}
- if (def.actions[end_act].vtw_list_head || def.actions[begin_act].vtw_list_head) {
+ if (def.actions[end_act].vtw_list_head
+ || def.actions[begin_act].vtw_list_head) {
break;
}
if (G_NODE_IS_ROOT(n) == TRUE) {
@@ -1046,7 +945,9 @@ sort_func(GNode *node, gpointer data, boolean priority_mode)
}
if (priority_mode) {
- if (((struct VyattaNode*)gp)->_config._priority < LOWEST_PRIORITY) { //only if priority is specified.
+ int gprio = gp->_config._priority;
+ if (gprio < LOWEST_PRIORITY) {
+ // only if priority is specified.
//unlink from original tree
g_node_unlink(node);
@@ -1054,30 +955,29 @@ sort_func(GNode *node, gpointer data, boolean priority_mode)
GNode *sibling = root_node->children;
//now iterate through siblings of root_node and compare priority
- while (sibling != NULL && ((struct VyattaNode*)gp)->_config._priority > ((struct VyattaNode*)(sibling->data))->_config._priority) {
+ while (sibling
+ && gprio > ((struct VyattaNode*)(sibling->data))
+ ->_config._priority) {
sibling = sibling->next;
- if (sibling == NULL || ((struct VyattaNode*)gp)->_config._priority < ((struct VyattaNode*)(sibling->data))->_config._priority) {
+ if (!sibling
+ || gprio < ((struct VyattaNode*)(sibling->data))
+ ->_config._priority) {
+ // XXX isn't this redundant??? just cleaning up so not changing it
break;
}
}
- if (g_debug) {
- int pri = LOWEST_PRIORITY;
- if (sibling != NULL) {
- pri = ((struct VyattaNode*)(sibling->data))->_config._priority;
- }
- printf("commit2::sort_func(): inserting %s into transaction, priority: %d BEFORE %d\n", ((struct VyattaNode*)gp)->_data._name, ((struct VyattaNode*)gp)->_config._priority, pri);
- syslog(LOG_DEBUG,"commit2::sort_func(): inserting %s into transaction, priority: %d BEFORE %d\n", ((struct VyattaNode*)gp)->_data._name, ((struct VyattaNode*)gp)->_config._priority, pri);
- }
+ d_dplog("commit2::sort_func(): inserting %s into transaction, "
+ "priority: %d BEFORE %d", d->_name, gprio,
+ (sibling
+ ? ((struct VyattaNode*)(sibling->data))->_config._priority
+ : LOWEST_PRIORITY));
g_node_insert_before(root_node,sibling,new_node);
}
}
else {
if (g_node_depth(node) == 2) {
- if (g_debug) {
- printf("commit2::sort_func(): inserting %s into transaction\n", ((struct VyattaNode*)gp)->_data._name);
- syslog(LOG_DEBUG,"commit2::sort_func(): inserting %s into transaction\n", ((struct VyattaNode*)gp)->_data._name);
- }
+ d_dplog("commit2::sort_func(): insert %s into transaction", d->_name);
GNode *new_node = g_node_copy(node);
g_node_insert(root_node,-1,new_node); //make a flat structure for now
}
@@ -1085,20 +985,13 @@ sort_func(GNode *node, gpointer data, boolean priority_mode)
return FALSE;
}
-
/**
* Gets a flat collection of nodes, sorted by priority
- *
- *
**/
GNode*
get_transactions(GNode *config, boolean priority_mode)
{
- if (g_debug) {
- printf("commit2::get_transactions()\n");
- syslog(LOG_DEBUG,"commit2::get_transactions()\n");
- }
-
+ d_dplog("commit2::get_transactions()");
if (config == NULL) {
return NULL;
}
@@ -1138,10 +1031,8 @@ get_transactions(GNode *config, boolean priority_mode)
return trans_root;
}
-
/**
*
- *
**/
static gboolean
cleanup_func(GNode *node, gpointer data)
@@ -1167,7 +1058,6 @@ cleanup_func(GNode *node, gpointer data)
/**
*
- *
**/
void
cleanup(GNode *root_node)
@@ -1202,112 +1092,104 @@ dump_func(GNode *node, gpointer data)
if (node != NULL) {
guint depth = g_node_depth(node);
-
if (depth == 2) {
fprintf(out,"NEW TRANS\n");
}
- gpointer gp = ((GNode*)node)->data;
- if (((struct VyattaNode*)gp)->_data._name != NULL) {
+ struct VyattaNode *gp = (struct VyattaNode *) node->data;
+ struct Data *gdata = &(gp->_data);
+ struct Config *gcfg = &(gp->_config);
+ if (gdata->_name != NULL) {
unsigned int i;
- char disable_op[2];
- if (((struct VyattaNode*)gp)->_data._disable_op == (K_ACTIVE_DISABLE_OP | K_LOCAL_DISABLE_OP)) {
+ char disable_op[2] = { 0, 0 };
+ NODE_ACTIVATE dop = gdata->_disable_op;
+ if (dop == (K_ACTIVE_DISABLE_OP | K_LOCAL_DISABLE_OP)) {
disable_op[0] = '!';
- }
- else if (((struct VyattaNode*)gp)->_data._disable_op == K_ACTIVE_DISABLE_OP) {
+ } else if (dop == K_ACTIVE_DISABLE_OP) {
disable_op[0] = 'A';
- }
- else if (((struct VyattaNode*)gp)->_data._disable_op == K_LOCAL_DISABLE_OP) {
+ } else if (dop == K_LOCAL_DISABLE_OP) {
disable_op[0] = 'D';
- }
- else {
+ } else {
disable_op[0] = ' ';
}
- disable_op[1] = '\0';
- if (IS_ACTIVE(((struct VyattaNode*)gp)->_data._operation)) {
+ NODE_OPERATION op = gdata->_operation;
+ if (IS_ACTIVE(op)) {
fprintf(out,"%s*",disable_op);
- }
- else if (IS_DELETE(((struct VyattaNode*)gp)->_data._operation)) {
+ } else if (IS_DELETE(op)) {
fprintf(out,"%s-",disable_op);
- }
- else if (IS_CREATE(((struct VyattaNode*)gp)->_data._operation)) {
+ } else if (IS_CREATE(op)) {
fprintf(out,"%s+",disable_op);
- }
- else if (IS_SET(((struct VyattaNode*)gp)->_data._operation)) {
+ } else if (IS_SET(op)) {
fprintf(out,"%s>",disable_op);
- }
- else {
+ } else {
fprintf(out,"%s ",disable_op);
}
for (i = 0; i < depth; ++i) {
fprintf(out," ");
}
- if (((struct VyattaNode*)gp)->_config._def.def_type2 != ERROR_TYPE) {
- fprintf(out,"%s (t: %d-%d, ", ((struct VyattaNode*)gp)->_data._name,((struct VyattaNode*)gp)->_config._def.def_type,((struct VyattaNode*)gp)->_config._def.def_type2);
- }
- else {
- fprintf(out,"%s (t: %d, ", ((struct VyattaNode*)gp)->_data._name,((struct VyattaNode*)gp)->_config._def.def_type);
- }
- if (((struct VyattaNode*)gp)->_config._priority_extended != NULL) {
- fprintf(out, "p: %s)",((struct VyattaNode*)gp)->_config._priority_extended);
+
+ if (gcfg->_def.def_type2 != ERROR_TYPE) {
+ fprintf(out,"%s (t: %d-%d, ", gdata->_name, gcfg->_def.def_type,
+ gcfg->_def.def_type2);
+ } else {
+ fprintf(out,"%s (t: %d, ", gdata->_name, gcfg->_def.def_type);
}
- else {
- fprintf(out, "p: %d)",((struct VyattaNode*)gp)->_config._priority);
+ if (gcfg->_priority_extended) {
+ fprintf(out, "p: %s)", gcfg->_priority_extended);
+ } else {
+ fprintf(out, "p: %d)", gcfg->_priority);
}
- if (((struct VyattaNode*)gp)->_data._value == TRUE) {
+ if (gdata->_value == TRUE) {
fprintf(out," [VALUE]");
}
- if (((struct VyattaNode*)gp)->_config._multi == TRUE) {
- fprintf(out," [MULTI(%d)]",((struct VyattaNode*)gp)->_config._limit);
+ if (gcfg->_multi == TRUE) {
+ fprintf(out," [MULTI(%d)]",gcfg->_limit);
}
- if (((struct VyattaNode*)gp)->_config._def.actions[syntax_act].vtw_list_head &&
- ((struct VyattaNode*)gp)->_config._def.actions[syntax_act].vtw_list_head->vtw_node_aux == 0) {
+ if (gcfg->_def.actions[syntax_act].vtw_list_head
+ && !gcfg->_def.actions[syntax_act].vtw_list_head->vtw_node_aux) {
fprintf(out," [SYNTAX]");
}
- if (((struct VyattaNode*)gp)->_config._def.actions[create_act].vtw_list_head) {
+ if (gcfg->_def.actions[create_act].vtw_list_head) {
fprintf(out," [CREATE]");
}
- if (((struct VyattaNode*)gp)->_config._def.actions[activate_act].vtw_list_head) {
+ if (gcfg->_def.actions[activate_act].vtw_list_head) {
fprintf(out," [ACTIVATE]");
}
- if (((struct VyattaNode*)gp)->_config._def.actions[update_act].vtw_list_head) {
+ if (gcfg->_def.actions[update_act].vtw_list_head) {
fprintf(out," [UPDATE]");
}
- if (((struct VyattaNode*)gp)->_config._def.actions[delete_act].vtw_list_head) {
+ if (gcfg->_def.actions[delete_act].vtw_list_head) {
fprintf(out," [DELETE]");
}
- if (((struct VyattaNode*)gp)->_config._def.actions[syntax_act].vtw_list_head &&
- ((struct VyattaNode*)gp)->_config._def.actions[syntax_act].vtw_list_head->vtw_node_aux == 1) {
+ if (gcfg->_def.actions[syntax_act].vtw_list_head
+ && gcfg->_def.actions[syntax_act].vtw_list_head->vtw_node_aux) {
fprintf(out," [COMMIT]");
}
- if (((struct VyattaNode*)gp)->_config._def.actions[begin_act].vtw_list_head) {
+ if (gcfg->_def.actions[begin_act].vtw_list_head) {
fprintf(out," [BEGIN]");
}
- if (((struct VyattaNode*)gp)->_config._def.actions[end_act].vtw_list_head) {
+ if (gcfg->_def.actions[end_act].vtw_list_head) {
fprintf(out," [END]");
}
- if (((struct VyattaNode*)gp)->_config._help != NULL) {
- // fprintf(out,"[help: %s]",((struct VyattaNode*)gp)->_config._help);
- }
fprintf(out,"\n");
}
-
}
return FALSE;
}
-
/**
*
**/
boolean
process_priority_node(GNode *priority_node)
{
- //on each node that is deleted run the delete action within the context of the transaction
+ /* on each node that is deleted run the delete action within the context
+ * of the transaction
+ */
struct Result result;
result._err_code = 0;
@@ -1316,12 +1198,12 @@ process_priority_node(GNode *priority_node)
}
//if this node is an enclosing node, we'll skip this iteration
- gpointer gp = ((GNode*)priority_node)->data;
- struct Config *c = &((struct VyattaNode*)gp)->_config;
+ struct VyattaNode *gp = (struct VyattaNode *) priority_node->data;
+ struct Config *c = &(gp->_config);
//does this node contain a begin or end statement?
boolean priority_node_is_enclosing_node = FALSE;
- if (c->_def.actions &&
- (c->_def.actions[end_act].vtw_list_head || c->_def.actions[begin_act].vtw_list_head)){
+ if (c->_def.actions && (c->_def.actions[end_act].vtw_list_head
+ || c->_def.actions[begin_act].vtw_list_head)) {
priority_node_is_enclosing_node = TRUE;
}
@@ -1338,7 +1220,9 @@ process_priority_node(GNode *priority_node)
return FALSE;
}
}
- //now perform processing on what's left outside of the enclosing begin/end statements
+ /* now perform processing on what's left outside of the enclosing
+ * begin/end statements
+ */
int i;
for (i = 0; i < g_num_actions; ++i) {
// now _this_ should be enum instead
@@ -1359,17 +1243,14 @@ process_priority_node(GNode *priority_node)
(gpointer)&result);
if (result._err_code != 0) {
- if (g_debug) {
- printf("commit2::process_priority_node(): failure on processing pass: %d\n", i);
- syslog(LOG_DEBUG,"commit2::process_priority_node(): failure on processing pass: %d\n", i);
- }
+ d_dplog("commit2::process_priority_node(): failure on "
+ "processing pass: %d", i);
return FALSE;
}
}
return TRUE;
}
-
/**
* Look for begin/end statements to begin processing
* of actions.
@@ -1382,20 +1263,20 @@ enclosing_process_func(GNode *node, gpointer data)
}
struct Result *result = (struct Result*)data;
- gpointer gp = ((GNode*)node)->data;
- struct Config *c = &((struct VyattaNode*)gp)->_config;
- struct Data *d = &((struct VyattaNode*)gp)->_data;
+ struct VyattaNode *gp = (struct VyattaNode *) node->data;
+ struct Config *c = &(gp->_config);
+ struct Data *d = &(gp->_data);
//does this node contain a begin or end statement?
- if (c->_def.actions &&
- (c->_def.actions[end_act].vtw_list_head || c->_def.actions[begin_act].vtw_list_head)){
- //gotten to this point need to do a call around this enclosing being/end node
+ if (c->_def.actions && (c->_def.actions[end_act].vtw_list_head
+ || c->_def.actions[begin_act].vtw_list_head)) {
+ /* gotten to this point need to do a call around this enclosing
+ * being/end node
+ */
g_node_unlink(node); //removed this...
- if (g_debug) {
- printf("commit2::enclosing_process_func(): enclosing statement found on: %s\n",d->_path);
- syslog(LOG_DEBUG,"commit2::enclosing_process_func(): enclosing statement found on: %s\n",d->_path);
- }
+ d_dplog("commit2::enclosing_process_func(): enclosing statement found "
+ "on: %s", d->_path);
//perform recursive calling on new process node...
int i;
@@ -1417,11 +1298,10 @@ enclosing_process_func(GNode *node, gpointer data)
(GNodeTraverseFunc)process_func,
(gpointer)result);
- if (result->_err_code != 0) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
- if (g_debug) {
- printf("commit2::enclosing_process_func(): FAILURE: status: %d\n",result->_err_code);
- syslog(LOG_DEBUG,"commit2::enclosing_process_func(): FAILURE: status: %d\n",result->_err_code);
- }
+ if (result->_err_code != 0) {
+ //EXECUTE_LIST RETURNS FALSE ON FAILURE....
+ d_dplog("commit2::enclosing_process_func(): FAILURE: status: %d",
+ result->_err_code);
return TRUE; //WILL STOP AT THIS POINT
}
}
@@ -1429,8 +1309,6 @@ enclosing_process_func(GNode *node, gpointer data)
return FALSE;
}
-
-
/**
*
**/
@@ -1457,10 +1335,8 @@ validate_configuration(GNode *root_node, boolean mode,
(gpointer)&result);
if (result._err_code != 0) {
- if (g_debug) {
- printf("commit2::process_priority_node(): failure on processing pass: %d\n", syntax_act);
- syslog(LOG_DEBUG,"commit2::process_priority_node(): failure on processing pass: %d\n", syntax_act);
- }
+ d_dplog("commit2::process_priority_node(): failure on processing "
+ "pass: %d", syntax_act);
return FALSE;
}
@@ -1469,10 +1345,8 @@ validate_configuration(GNode *root_node, boolean mode,
return TRUE;
}
-
/**
* Execute syntax and commit checks
- *
**/
static gboolean
validate_func(GNode *node, gpointer data)
@@ -1481,17 +1355,16 @@ validate_func(GNode *node, gpointer data)
return TRUE;
}
- gpointer gp = ((GNode*)node)->data;
- struct Config *c = &((struct VyattaNode*)gp)->_config;
- struct Data *d = &((struct VyattaNode*)gp)->_data;
- struct Aux *a = &((struct VyattaNode*)gp)->_aux;
+ struct VyattaNode *gp = (struct VyattaNode *) node->data;
+ struct Config *c = &(gp->_config);
+ struct Data *d = &(gp->_data);
+ struct Aux *a = &(gp->_aux);
struct Result *result = (struct Result*)data;
-
-
-
- //let's mark first last nodes here for use later
- //do first/last/only sibling check, restrict to nodes with operations defined
+ /* let's mark first last nodes here for use later
+ * do first/last/only sibling check, restrict to nodes with operations
+ * defined
+ */
GNode *n_last_op = NULL;
GNode *n_first_op = NULL;
@@ -1508,7 +1381,8 @@ validate_func(GNode *node, gpointer data)
sib = g_node_first_sibling(node);
while (sib != NULL) {
- if (IS_SET_OR_CREATE(((struct VyattaNode*)(sib->data))->_data._operation)) {
+ if (IS_SET_OR_CREATE(((struct VyattaNode*)(sib->data))
+ ->_data._operation)) {
if (n_first_op == NULL) {
n_first_op = sib;
}
@@ -1521,14 +1395,18 @@ validate_func(GNode *node, gpointer data)
a->_last = (node == n_last_op);
- //since this visits all working nodes, let's maintain a set of nodes to commit
+ /* since this visits all working nodes, let's maintain a set of nodes
+ * to commit
+ */
GSList *coll = (GSList*)result->_data;
if (d->_path != NULL) {
-
char buf[MAX_LENGTH_DIR_PATH*sizeof(char)];
if (IS_DELETE(d->_operation)) {
sprintf(buf,"- %s",d->_path);
- if (c->_def.multi) { //need to handle the embedded multinode as a special case--should be fixed!
+ if (c->_def.multi) {
+ /* need to handle the embedded multinode as a special
+ * case--should be fixed!
+ */
char *val = (char*)clind_unescape(d->_name);
strcat(buf,val);
free(val);
@@ -1540,7 +1418,10 @@ validate_func(GNode *node, gpointer data)
}
else if (IS_SET_OR_CREATE(d->_operation)) {
sprintf(buf,"+ %s",d->_path);
- if (c->_def.multi) { //need to handle the embedded multinode as a special case--should be fixed!
+ if (c->_def.multi) {
+ /* need to handle the embedded multinode as a special
+ * case--should be fixed!
+ */
char *val = (char*)clind_unescape(d->_name);
strcat(buf,val);
free(val);
@@ -1554,13 +1435,18 @@ validate_func(GNode *node, gpointer data)
}
//don't run syntax check on this node if it is unchanged.
- if (IS_NOOP(d->_operation) && (c->_def.actions[syntax_act].vtw_list_head != NULL && c->_def.actions[syntax_act].vtw_list_head->vtw_node_aux == 0)) {
+ if (IS_NOOP(d->_operation) && c->_def.actions[syntax_act].vtw_list_head
+ && !c->_def.actions[syntax_act].vtw_list_head->vtw_node_aux) {
return FALSE;
}
//don't perform validation checks on disabled nodes
- if ((d->_disable_op == K_LOCAL_DISABLE_OP) || (d->_disable_op == (K_LOCAL_DISABLE_OP | K_ACTIVE_DISABLE_OP))) {
- return FALSE; //SHOULD only hit the case where the node is locally disabled or globally disabled and not in a transition to active state
+ if (d->_disable_op == K_LOCAL_DISABLE_OP
+ || d->_disable_op == (K_LOCAL_DISABLE_OP | K_ACTIVE_DISABLE_OP)) {
+ /* SHOULD only hit the case where the node is locally disabled
+ * or globally disabled and not in a transition to active state
+ */
+ return FALSE;
}
if (IS_DELETE(d->_operation) && !IS_ACTIVE(d->_operation)) {
@@ -1572,8 +1458,10 @@ validate_func(GNode *node, gpointer data)
return FALSE;
}
- //will not call term multi if it is a noop--shouldn't show up in tree in the first place, but
- //will require more rework of unionfs code to fix this.
+ /* will not call term multi if it is a noop--shouldn't show up in tree
+ * in the first place, but will require more rework of unionfs code
+ * to fix this.
+ */
if (c->_def.multi && IS_NOOP(d->_operation)) {
return FALSE;
}
@@ -1581,39 +1469,36 @@ validate_func(GNode *node, gpointer data)
//look at parent for multi tag
if (d->_value && d->_name) {
char *val = d->_name;
- if (c->_def.tag) { //need to handle the embedded multinode as a special case--should be fixed!
+ if (c->_def.tag) {
+ /* need to handle the embedded multinode as a special
+ * case--should be fixed!
+ */
val = (char*)clind_unescape(d->_name);
}
- if (g_debug) {
- printf("commit2::process_func(): @ value: %s\n",(char*)val);
- syslog(LOG_DEBUG,"commit2::process_func(): @ value: %s",(char*)val);
- }
+ d_dplog("commit2::process_func(): @ value: %s",(char *) val);
set_at_string(val); //embedded multinode value
}
else {
if (g_debug) {
- printf("commit2::process_func(): boolean value is: %d\n",d->_value);
- syslog(LOG_DEBUG,"commit2::process_func(): boolean value is: %d",d->_value);
- if (node->parent != NULL && ((struct VyattaNode*)(node->parent->data))->_data._name != NULL) {
- printf("commit2::process_func(): parent has a name and it is: %s\n",((struct VyattaNode*)(node->parent->data))->_data._name);
- syslog(LOG_DEBUG,"commit2::process_func(): parent has a name and it is: %s\n",((struct VyattaNode*)(node->parent->data))->_data._name);
+ dplog("commit2::process_func(): boolean value is: %d", d->_value);
+ if (node->parent
+ && ((struct VyattaNode*)(node->parent->data))->_data._name) {
+ dplog("commit2::process_func(): parent has a name: %s",
+ ((struct VyattaNode*)(node->parent->data))->_data._name);
}
- printf("commit2::process_func(): @ value: [NULL]\n");
- syslog(LOG_DEBUG,"commit2::process_func(): @ value: [NULL]\n");
+ dplog("commit2::process_func(): @ value: [NULL]");
}
}
common_set_context(c->_path,d->_path);
- if (g_debug) {
- printf("Executing %s on this node\n", ActionNames[result->_action]);
- syslog(LOG_DEBUG,"Executing %s on this node\n", ActionNames[result->_action]);
- }
+ d_dplog("Executing %s on this node", ActionNames[result->_action]);
if (g_coverage) {
struct timeval t;
gettimeofday(&t,NULL);
- fprintf(out_stream,"[START] %lu:%lu, %s@%s",(unsigned long)t.tv_sec,(unsigned long)t.tv_usec,ActionNames[result->_action],d->_path);
+ fprintf(out_stream, "[START] %lu:%lu, %s@%s", (unsigned long) t.tv_sec,
+ (unsigned long) t.tv_usec, ActionNames[result->_action], d->_path);
}
boolean status = 1;
@@ -1621,11 +1506,14 @@ validate_func(GNode *node, gpointer data)
//set location env
setenv(ENV_DATA_PATH,d->_path,1);
if (g_old_print_output == TRUE) {
- status = execute_list(c->_def.actions[result->_action].vtw_list_head,&c->_def,NULL,g_print_error_location_all);
- }
- else {
+ status
+ = execute_list(c->_def.actions[result->_action].vtw_list_head,
+ &c->_def, NULL, g_print_error_location_all);
+ } else {
char *p = process_script_path(d->_path);
- status = execute_list(c->_def.actions[result->_action].vtw_list_head,&c->_def,p,g_print_error_location_all);
+ status
+ = execute_list(c->_def.actions[result->_action].vtw_list_head,
+ &c->_def, p, g_print_error_location_all);
free(p);
}
unsetenv(ENV_DATA_PATH);
@@ -1640,7 +1528,10 @@ validate_func(GNode *node, gpointer data)
sprintf(buf,"commit\t:\t%s",d->_path);
}
}
- if (c->_def.multi) { //need to handle the embedded multinode as a special case--should be fixed!
+ if (c->_def.multi) {
+ /* need to handle the embedded multinode as a special
+ * case--should be fixed!
+ */
char *val = (char*)clind_unescape(d->_name);
strcat(buf,val);
free(val);
@@ -1656,36 +1547,22 @@ validate_func(GNode *node, gpointer data)
}
if (!status) { //EXECUTE_LIST RETURNS FALSE ON FAILURE....
- /*
- char *p = process_script_path(d->_path);
- if (p != NULL) {
- if (strlen(outbuf) > 0) {
- if (g_print_error_location_all == TRUE) {
- fprintf(out_stream,"_errloc_:[%s]\n %s\n",p,outbuf);
- }
- else {
- fprintf(out_stream,"[%s] \n %s\n",p,outbuf);
- }
- }
- }
- */
- syslog(LOG_ERR,"commit error for %s:[%s]\n",ActionNames[result->_action],d->_path);
+ syslog(LOG_ERR, "commit error for %s:[%s]",
+ ActionNames[result->_action], d->_path);
if (g_display_error_node) {
- fprintf(out_stream,"%s@_errloc_:[%s]\n",ActionNames[result->_action],d->_path);
+ fprintf(out_stream, "%s@_errloc_:[%s]\n",
+ ActionNames[result->_action], d->_path);
}
result->_err_code = 1;
- if (g_debug) {
- printf("commit2::validate_func(): FAILURE: status: %d\n",status);
- syslog(LOG_DEBUG,"commit2::validate_func(): FAILURE: status: %d",status);
- }
- return result->_mode ? FALSE: TRUE; //WILL STOP AT THIS POINT if mode is not set for full syntax check
+ d_dplog("commit2::validate_func(): FAILURE: status: %d", status);
+ // WILL STOP AT THIS POINT if mode is not set for full syntax check
+ return result->_mode ? FALSE: TRUE;
}
return FALSE;
}
/**
*
- *
**/
static void
update_change_file(FILE *fp, GSList *coll)
diff --git a/src/common/common.c b/src/common/common.c
deleted file mode 100644
index 6cdf3e7..0000000
--- a/src/common/common.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <glib-2.0/glib.h>
-#include "common.h"
-
-
-
-
-boolean
-execute(char *cmd)
-{
- return TRUE;
-}
diff --git a/src/common/common.h b/src/common/common.h
index 1a323ee..9115967 100644
--- a/src/common/common.h
+++ b/src/common/common.h
@@ -8,9 +8,6 @@
extern "C" {
#endif
-boolean
-execute(char *cmd);
-
/**
*
**/
@@ -36,7 +33,8 @@ void
common_set_context(char *cpath, char *dpath);
/**
- * sets system parent context for operation (i.e. hack for unionfs implementation)
+ * sets system parent context for operation (i.e. hack for unionfs
+ * implementation)
**/
void
common_set_parent_context(char *cpath, char *dpath);
diff --git a/src/common/unionfs.c b/src/common/unionfs.c
index 6646e74..e9266cc 100644
--- a/src/common/unionfs.c
+++ b/src/common/unionfs.c
@@ -106,28 +106,18 @@ static void
piecewise_copy(GNode *root_node, boolean test_mode);
/**
+ * Data is stored on the path:
+ * <newcfgroot>/system/login/user/foo/authentication/plaintext-password
*
+ * Template is stored along this path:
+ * <tmplroot>/system/login/user/node.tag/authentication/plaintext-password
*
- Data is stored on the path:
-
- /opt/vyatta/config/tmp/new_config_5425/system/login/user/foo/authentication/plaintext-password
-
- Config is stored along this path:
-
- /opt/vyatta/config/template/vyatta-cfg/system/login/user/node.tag/authentication/plaintext-password
-
- 1) Need to split out relative path
-
- 2) if node is *MULTI* then the path value is the actual value
-
- 3) For the config copy the pointer from an existing config value for each multinode
-<Need to figure out how this is going to happen>
-
-This should allow a combined data/config tree
-
- *
- *
+ * 1) Need to split out relative path
+ * 2) if node is *MULTI* then the path value is the actual value
+ * 3) For the config copy the pointer from an existing config value for each
+ * multinode <Need to figure out how this is going to happen>
*
+ * This should allow a combined data/config tree
**/
char*
get_config_path(GNode *node)
@@ -156,7 +146,9 @@ get_config_path(GNode *node)
char tmp[MAX_LENGTH_DIR_PATH];
strcpy(tmp,buf);
- //need to check the configuration location for the existance of this node to determine if it's a multi
+ /* need to check the configuration location for the existance of
+ * this node to determine if it's a multi
+ */
if (G_NODE_IS_ROOT(n->parent) != TRUE &&
((struct VyattaNode*)(n->parent->data))->_config._multi == TRUE) {
sprintf(buf,"node.tag/%s",tmp);
@@ -258,7 +250,9 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
syslog(LOG_DEBUG,"[FOUND node.def]");
}
- //either multi or tag--shouldn't have made a difference, but arkady was confused.
+ /* either multi or tag--shouldn't have made a difference, but arkady
+ * was confused.
+ */
vn->_config._multi = (def.tag | def.multi);
if (def.def_tag != 0) {
vn->_config._limit = def.def_tag;
@@ -290,24 +284,32 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
if (vn_parent->_config._multi == TRUE) {
((struct VyattaNode*)node->data)->_data._value = TRUE;
- //patch up to preserve multinode behavior on value node, can also put node.def on node.tag with priority
- //Need to do two things:
- // 1. Come to agreement on where the behavior splits on priority multinodes
- // 2. Not check for tag node in the def datastructure but use the new datastructure as at some point tag and multi will be the same
+ /* patch up to preserve multinode behavior on value node, can also
+ * put node.def on node.tag with priority
+ * Need to do two things:
+ * 1. Come to agreement on where the behavior splits on priority
+ * multinodes
+ * 2. Not check for tag node in the def datastructure but use the
+ * new datastructure as at some point tag and multi will be the
+ * same
+ */
//now let's patch up the def multi-nodes
//move the def for the multinode from the parent to the value node
struct VyattaNode* vn2 = (struct VyattaNode*)node->data;
if (final_node == FALSE) { //non-term multi
if (g_node_n_children(node->parent) == 1) {
- vn2->_config._def = ((struct VyattaNode*)node->parent->data)->_config._def;
- memset(&((struct VyattaNode*)node->parent->data)->_config._def, 0, sizeof(vtw_def));
+ vn2->_config._def
+ = ((struct VyattaNode*)node->parent->data)->_config._def;
+ memset(&((struct VyattaNode*)node->parent->data)->_config._def,
+ 0, sizeof(vtw_def));
}
else { //find node other than myself to copy defs across
GNode *first_child = g_node_first_child(node->parent);
if (first_child == node) {
first_child = g_node_next_sibling(first_child);
}
- vn2->_config._def = ((struct VyattaNode*)first_child->data)->_config._def;
+ vn2->_config._def
+ = ((struct VyattaNode*)first_child->data)->_config._def;
}
}
}
@@ -339,9 +341,6 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
}
}
-
-
-
if (final_node == TRUE) {
//move defs to child...
get_term_data_values(node);
@@ -362,13 +361,16 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
if ((dp = opendir(full_data_path)) == NULL){
if (g_debug) {
//could also be a terminating value now
- printf("unionfs::retrieve_data(), failed to open directory: %s\n", full_data_path);
- syslog(LOG_DEBUG,"unionfs::retrieve_data(), failed to open directory: %s\n", full_data_path);
+ printf("unionfs::retrieve_data(), failed to open directory: %s\n",
+ full_data_path);
+ syslog(LOG_DEBUG,
+ "unionfs::retrieve_data(), failed to open directory: %s\n",
+ full_data_path);
}
return;
}
- //finally iterate over valid child directory entries
+ //finally iterate over valid child directory entries
boolean processed = FALSE;
boolean whiteout_file_found = FALSE;
struct dirent *dirp = NULL;
@@ -388,7 +390,9 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
processed = TRUE;
NODE_ACTIVATE deactivated = K_NO_DISABLE_OP;
- if (G_NODE_IS_ROOT(node) == FALSE && ((struct VyattaNode*)node->data)->_data._disable_op != K_NO_DISABLE_OP) {
+ if (G_NODE_IS_ROOT(node) == FALSE
+ && ((struct VyattaNode*)node->data)->_data._disable_op
+ != K_NO_DISABLE_OP) {
deactivated = ((struct VyattaNode*)node->data)->_data._disable_op;
}
else { //do a lstat check in the local dir
@@ -404,18 +408,21 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
char buf[MAX_LENGTH_HELP_STR];
- sprintf(buf,"%s/%s/%s/%s",get_mdirp(),rel_data_path,namebuf,DISABLE_FILE);
+ sprintf(buf, "%s/%s/%s/%s", get_mdirp(), rel_data_path, namebuf,
+ DISABLE_FILE);
if (lstat(buf,&s) == 0) {
- //need to check existence of file in active configuration here as well!
+ /* need to check existence of file in active configuration here
+ * as well!
+ */
deactivated |= K_LOCAL_DISABLE_OP;
}
- sprintf(buf,"%s/%s/%s/%s",get_adirp(),rel_data_path,namebuf,DISABLE_FILE);
+ sprintf(buf, "%s/%s/%s/%s", get_adirp(), rel_data_path, namebuf,
+ DISABLE_FILE);
if (lstat(buf,&s) == 0) {
deactivated |= K_ACTIVE_DISABLE_OP;
}
}
- // char *data_buf = malloc(MAX_LENGTH_DIR_PATH*sizeof(char));
char *data_buf = malloc(strlen(dirp->d_name)+5);
if (strncmp(dirp->d_name,DELETED_NODE,4) == 0) {
struct VyattaNode *vn = calloc(1,sizeof(struct VyattaNode));
@@ -438,10 +445,11 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
sprintf(new_data_path,"%s/%s",rel_data_path,data_buf);
GNode *new_node = g_node_new(vn);
- // new_node = g_node_insert(node, -1, new_node);
new_node = insert_sibling_in_order(node,new_node);
- //will need to enter a special recursion against the active configuration to mark nested delete nodes
+ /* will need to enter a special recursion against the active
+ * configuration to mark nested delete nodes
+ */
retrieve_data(new_data_path,new_node,get_adirp(),K_DEL_OP);
}
else if (deactivated != K_NO_DISABLE_OP) {
@@ -466,11 +474,13 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
sprintf(new_data_path,"%s/%s",rel_data_path,data_buf);
GNode *new_node = g_node_new(vn);
- // new_node = g_node_insert(node, -1, new_node);
new_node = insert_sibling_in_order(node,new_node);
- //will need to enter a special recursion against the active configuration to mark nested delete nodes
- retrieve_data(new_data_path,new_node,get_adirp(),vn->_data._operation);
+ /* will need to enter a special recursion against the active
+ * configuration to mark nested delete nodes
+ */
+ retrieve_data(new_data_path, new_node, get_adirp(),
+ vn->_data._operation);
}
else {
strcpy(data_buf,dirp->d_name);
@@ -500,10 +510,10 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
vn->_data._operation = K_DEL_OP;
}
GNode *new_node = g_node_new(vn);
- // new_node = g_node_insert(node, -1, new_node);
new_node = insert_sibling_in_order(node,new_node);
if (op == K_DEL_OP || vn->_data._disable_op != K_NO_DISABLE_OP) {
- retrieve_data(new_data_path,new_node,get_adirp(),vn->_data._operation);
+ retrieve_data(new_data_path, new_node, get_adirp(),
+ vn->_data._operation);
}
else {
retrieve_data(new_data_path,new_node,root,vn->_data._operation);
@@ -522,8 +532,9 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
}
closedir(dp);
- //if there is a ".wh.__dir_opaque" and were not already
- //iterating the active dir then test for a hidden deletion
+ /* if there is a ".wh.__dir_opaque" and were not already
+ * iterating the active dir then test for a hidden deletion
+ */
if (whiteout_file_found == TRUE && op != K_DEL_OP) {
//scan active dir for entry not found in tmp
DIR *dp_wo;
@@ -533,13 +544,17 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
if ((dp_wo = opendir(active_data_path)) != NULL) {
if (g_debug) {
//could also be a terminating value now
- syslog(LOG_DEBUG,"unionfs::retrieve_data(), failed to open directory: %s\n", active_data_path);
- printf("unionfs::retrieve_data(), failed to open directory: %s\n", active_data_path);
+ syslog(LOG_DEBUG,
+ "unionfs::retrieve_data(), failed to open directory: %s\n",
+ active_data_path);
+ printf("unionfs::retrieve_data(), failed to open directory: %s\n",
+ active_data_path);
}
struct dirent *dirp_wo = NULL;
while ((dirp_wo = readdir(dp_wo)) != NULL) {
char tmp_new_data_path[MAX_LENGTH_DIR_PATH];
- sprintf(tmp_new_data_path,"%s/%s/%s",get_cdirp(),rel_data_path,dirp_wo->d_name);
+ sprintf(tmp_new_data_path, "%s/%s/%s", get_cdirp(), rel_data_path,
+ dirp_wo->d_name);
struct stat s;
if (lstat(tmp_new_data_path,&s) != 0) {
//create new node and insert...
@@ -585,11 +600,11 @@ common_get_local_session_data()
//create first node
GNode *root_node = g_node_new(vn);
- //iterate through recursive calls to parse_new() calls (see original commit())
+ /* iterate through recursive calls to parse_new() calls (see original
+ * commit())
+ */
retrieve_data(data_path,root_node,get_cdirp(),K_SET_OP);
- // apply_priority(root_node);
-
return root_node;
}
@@ -615,7 +630,8 @@ common_set_parent_context(char *cpath, char *dpath)
{
if (g_debug) {
printf("common_set_parent_context(incoming): %s, %s\n",cpath,dpath);
- syslog(LOG_DEBUG,"common_set_parent_context(incoming): %s, %s\n",cpath,dpath);
+ syslog(LOG_DEBUG, "common_set_parent_context(incoming): %s, %s\n",
+ cpath, dpath);
}
//strip off last path and set
int index = strlen(cpath)-1;
@@ -703,16 +719,6 @@ set_path(char *path, boolean config)
int size = end_ptr-start_ptr;
if (size < 1 || size > 1024) {
- /*
- if (g_debug) {
- if (config == FALSE) {
- printf("unionfs::set_path(): %s, %s\n", path,m_path.path);
- }
- else {
- printf("unionfs::set_path(): %s, %s\n", path,t_path.path);
- }
- }
- */
return;
}
@@ -727,16 +733,6 @@ set_path(char *path, boolean config)
}
start_ptr = end_ptr;
}
- /*
- if (g_debug) {
- if (config == FALSE) {
- printf("unionfs::set_path(): %s, %s\n", path,m_path.path);
- }
- else {
- printf("unionfs::set_path(): %s, %s\n", path,t_path.path);
- }
- }
- */
}
/**
@@ -746,7 +742,8 @@ set_path(char *path, boolean config)
*
**/
void
-common_commit_copy_to_live_config(GNode *node, boolean suppress_piecewise_copy, boolean test_mode)
+common_commit_copy_to_live_config(GNode *node, boolean suppress_piecewise_copy,
+ boolean test_mode)
{
//first check for existence of path before committing
char *path = ((struct VyattaNode*)(node->data))->_data._path;
@@ -891,8 +888,6 @@ common_commit_clean_temp_config(GNode *root_node, boolean test_mode)
printf("common_commit_clean_temp_config()\n");
syslog(LOG_DEBUG,"common_commit_clean_temp_config()\n");
}
- //first clean up the root
- // common_commit_copy_to_live_config("/");
char *command;
command = malloc(MAX_LENGTH_DIR_PATH);
@@ -915,11 +910,14 @@ common_commit_clean_temp_config(GNode *root_node, boolean test_mode)
/*
* Need to add to the following func below to clean up dangling .wh. files.
* This pass needs to be prior to the commands below (but after the umount).
- * This fixes a bug when higher priority root nodes are deleted and not removed.
+ * This fixes a bug when higher priority root nodes are deleted and not
+ * removed.
*/
- //Iterate through node hierarchy and remove deleted nodes from active config--insurance
- //to protect against priority whiteouts in parent/child order
+ /* Iterate through node hierarchy and remove deleted nodes from active
+ * config--insurance to protect against priority whiteouts in parent/child
+ * order
+ */
//TOP DOWN
if (root_node != NULL) {
struct SrcDst sd;
@@ -980,7 +978,6 @@ copy_vyatta_node(struct VyattaNode* vn)
new_vn->_config._multi = vn->_config._multi;
new_vn->_config._priority = vn->_config._priority;
new_vn->_config._priority_extended = vn->_config._priority_extended;
- // new_vn->_config._def = new_vn->_config._def; //cpy this?
if (vn->_config._default != NULL) {
new_vn->_config._default = malloc(strlen(vn->_config._default)+1);
strcpy(new_vn->_config._default,vn->_config._default);
@@ -1022,7 +1019,6 @@ get_term_data_values(GNode *node)
tok_str_active = g_strsplit(cp,"\n",0);
}
-
init_path(&vpath, full_new_data_path);
if (value_exists(full_new_data_path) && get_value(&cp, &vpath) == 0) {
tok_str_new = g_strsplit(cp,"\n",0);
@@ -1060,7 +1056,8 @@ get_term_data_values(GNode *node)
(tok_str_new == NULL || tok_str_new[0] == NULL)) {
cp = malloc(sizeof(char));
cp[0] = '\0';
- data->_state = ((struct VyattaNode*)node->parent->data)->_data._operation;
+ data->_state
+ = ((struct VyattaNode*)node->parent->data)->_data._operation;
g_datalist_set_data(&datalist, cp, data);
}
else if (tok_str_active == NULL || tok_str_active[0] == NULL) {
@@ -1091,9 +1088,6 @@ get_term_data_values(GNode *node)
g_strfreev(tok_str_new);
g_strfreev(tok_str_active);
-
- // g_dataset_destroy(&datalist);
-
}
/**
@@ -1115,9 +1109,7 @@ dlist_test_func(GQuark key_id,gpointer data,gpointer user_data)
if (vn->_data._value == TRUE) {
new_vn = copy_vyatta_node(vn);
GNode *new_node = g_node_new(new_vn);
- // g_node_insert(node, -1, new_node);
g_node_insert_after(node, NULL, new_node);
- // insert_sibling_in_order(node,new_node);
new_vn->_config._def = vn->_config._def;
}
else {
@@ -1125,7 +1117,6 @@ dlist_test_func(GQuark key_id,gpointer data,gpointer user_data)
char buf[MAX_LENGTH_DIR_PATH];
strcpy(buf,new_vn->_data._path);
- // new_vn->_data._path = (char*)realloc(new_vn->_data._path,sizeof(new_vn->_data._path)+8);
strcat(buf,"/value:");
if (vn_parent->_config._def.multi == FALSE) {
char *tmp = (char*)g_quark_to_string(key_id);
@@ -1153,7 +1144,7 @@ dlist_test_func(GQuark key_id,gpointer data,gpointer user_data)
new_vn->_config._path = malloc(strlen(vn_parent->_config._path)+10);
sprintf(new_vn->_config._path,"%s/node.tag",vn_parent->_config._path);
- //let's set this nodes disable_op to its parent's value.
+ // let's set this nodes disable_op to its parent's value.
new_vn->_data._disable_op = vn_parent->_data._disable_op;
new_vn->_data._operation = ((struct ValueData*)data)->_state;
@@ -1170,7 +1161,8 @@ insert_sibling_in_order(GNode *parent, GNode *child)
//find alphabetical order to insert child into sibling
GNode *sibling = parent->children;
while (sibling != NULL) {
- if (strcmp((((struct VyattaNode*)(child->data))->_data._name),((struct VyattaNode*)(sibling->data))->_data._name) > 0) {
+ if (strcmp(((struct VyattaNode*)(child->data))->_data._name,
+ ((struct VyattaNode*)(sibling->data))->_data._name) > 0) {
break;
}
sibling = sibling->next;
@@ -1233,10 +1225,15 @@ copy_func(GNode *node, gpointer data)
//THIS IS ONLY FOR NODE.VAL (or leafs, term multis)
- //before copy also need to clear out def file in active directory (will copy over current if found)
- //this is for the case where it is set by default, then unset at the node--i.e. no longer a default value.
- if (((struct VyattaNode*)(node->data))->_config._multi == FALSE) { //only for leaf
- char *parent_path = ((struct VyattaNode*)(node->parent->data))->_data._path;
+ /* before copy also need to clear out def file in active directory
+ * (will copy over current if found)
+ * this is for the case where it is set by default, then unset at the
+ * node--i.e. no longer a default value.
+ */
+ if (((struct VyattaNode*)(node->data))->_config._multi == FALSE) {
+ //only for leaf
+ char *parent_path
+ = ((struct VyattaNode*)(node->parent->data))->_data._path;
if (g_debug) {
printf("rm %s%sdef\n", sd->_dst, parent_path);
syslog(LOG_DEBUG, "rm %s%sdef", sd->_dst, parent_path);
@@ -1308,18 +1305,19 @@ delete_func(GNode *node, gpointer data)
char *command = malloc(MAX_LENGTH_DIR_PATH);
//DONT HAVE THE COMMAND BELOW BLOW AWAY WHITEOUT FILES!!!!!
- static const char format[]="rm -f '%s%s'{*,.*} >&/dev/null;rmdir %s%s >&/dev/null ; /bin/true"; //need to remove opaque file.
- static const char format_force_delete[]="rm -f '%s%s'{*,.*} >&/dev/null;rmdir %s%s >&/dev/null ; /bin/true"; //force delete as this is a delete operation with dependency
+ // need to remove opaque file.
+ static const char format[]
+ = "rm -f '%s%s'{*,.*} >&/dev/null;rmdir %s%s >&/dev/null ; /bin/true";
+ // force delete as this is a delete operation with dependency
+ static const char format_force_delete[]
+ = "rm -f '%s%s'{*,.*} >&/dev/null;rmdir %s%s >&/dev/null ; /bin/true";
static const char delete_format[]="rm %s%s../.wh.%s >&/dev/null";
char *path = ((struct VyattaNode*)(node->data))->_data._path;
//does this node have any children that have not been copied????
-
//NEED RM -FV on changes only directory!!!! for normal removal!!!
-
-
//WILL ONLY REMOVE DIRS WITHOUT CHILD DIRS--just what we want..
//NEED TO PREVENT THE COMMAND BELOW FROM DELETING WHITEOUT FILES....
@@ -1329,7 +1327,9 @@ delete_func(GNode *node, gpointer data)
}
- //DOESN'T QUITE FIX THE PROBLEM, THE PARENT IS CALLED (AND PROBABLY SHOULDN'T BE)
+ /* DOESN'T QUITE FIX THE PROBLEM, THE PARENT IS CALLED (AND PROBABLY
+ * SHOULDN'T BE)
+ */
if (!IS_DELETE(((struct VyattaNode*)(node->data))->_data._operation)) {
sprintf(command,format,sd->_src,path,sd->_src,path);
if (g_debug) {
@@ -1346,10 +1346,12 @@ delete_func(GNode *node, gpointer data)
if (IS_DELETE(((struct VyattaNode*)(node->data))->_data._operation) &&
!IS_ACTIVE(((struct VyattaNode*)(node->data))->_data._operation)) {
- //DO NOT PERFORM THIS STEP IF THERE ARE SUBDIRECTORIES (only the whiteout file)
-
+ /* DO NOT PERFORM THIS STEP IF THERE ARE SUBDIRECTORIES (only the
+ * whiteout file)
+ */
//remove .whiteout file in c directory if encountered in walk.
- sprintf(command,delete_format,sd->_src,path,((struct VyattaNode*)(node->data))->_data._name);
+ sprintf(command, delete_format, sd->_src, path,
+ ((struct VyattaNode*)(node->data))->_data._name);
if (g_debug) {
printf("%s\n",command);
syslog(LOG_DEBUG,"%s\n",command);
@@ -1392,12 +1394,15 @@ delete_wh_func(GNode *node, gpointer data)
GNode *parent_node = node->parent;
- //on node where operation is delete and parent is noop or active then remove directory from active config
- //if this is a deletion operation, need to remove
+ /* on node where operation is delete and parent is noop or active then
+ * remove directory from active config
+ * if this is a deletion operation, need to remove
+ */
if (parent_node != NULL) {
- if (IS_DELETE(((struct VyattaNode*)(node->data))->_data._operation) &&
- !IS_ACTIVE(((struct VyattaNode*)(node->data))->_data._operation) &&
- !IS_DELETE(((struct VyattaNode*)(parent_node->data))->_data._operation)) {
+ NODE_OPERATION op = ((struct VyattaNode*)(node->data))->_data._operation;
+ NODE_OPERATION pop
+ = ((struct VyattaNode*)(parent_node->data))->_data._operation;
+ if (IS_DELETE(op) && !IS_ACTIVE(op) && !IS_DELETE(pop)) {
char *path = ((struct VyattaNode*)(node->data))->_data._path;
sprintf(abuf,"%s%s",get_adirp(),path);