From 028e8e12c5e15efc0a316641f2b02e46d5c77210 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Mon, 6 Jul 2009 17:44:29 -0700 Subject: fix for ptr magic on 64 bit system. looks like double ptr was getting the missing the last 4 bytes on 64 bit copy. --- src/commit2.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/commit2.c b/src/commit2.c index 5f70aa4..a324bab 100644 --- a/src/commit2.c +++ b/src/commit2.c @@ -943,7 +943,7 @@ validate_configuration(GNode *root_node, boolean mode, GSList **nodes_visited_co struct Result result; result._err_code = 0; result._mode = (int)mode; - result._data = (void*)nodes_visited_coll; + result._data = (void*)*nodes_visited_coll; //handles both syntax and commit result._action = syntax_act; @@ -963,7 +963,7 @@ validate_configuration(GNode *root_node, boolean mode, GSList **nodes_visited_co } GList **c_tmp = (GList**)result._data; - *nodes_visited_coll = (GSList*)*c_tmp; + *nodes_visited_coll = (GSList*)c_tmp; return TRUE; } @@ -985,8 +985,7 @@ validate_func(GNode *node, gpointer data) struct Result *result = (struct Result*)data; //since this visits all working nodes, let's maintain a set of nodes to commit - GList **c_tmp = (GList**)result->_data; - GList *coll = *c_tmp; + GList *coll = (GList*)result->_data; if (d->_path != NULL) { char *buf = malloc(MAX_LENGTH_DIR_PATH*sizeof(char)); if (IS_DELETE(d->_operation)) { @@ -996,7 +995,7 @@ validate_func(GNode *node, gpointer data) strcat(buf,val); } coll = g_slist_append(coll,buf); - result->_data = (void*)&coll; + result->_data = (void*)coll; } else if (IS_SET_OR_CREATE(d->_operation)) { sprintf(buf,"+ %s",d->_path); @@ -1005,7 +1004,7 @@ validate_func(GNode *node, gpointer data) strcat(buf,val); } coll = g_slist_append(coll,buf); - result->_data = (void*)&coll; + result->_data = (void*)coll; } } -- cgit v1.2.3 From 09a684d6481868b501e5fb2df579ff6216dd111c Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Wed, 9 Sep 2009 16:27:42 -0700 Subject: Priority file generator. This program will iterate over the complete template tree and build the priority file from "priority: val" tags found in node.def files. This will now allow us to migrate the priority statements found to the specified nodes. Currently the program does not order the priority nodes according to values (cosmetic feature). Finally once all the priority values have been migrated to the infected node.defs the priority program can be added as a postinst hook on debian package install. --- Makefile.am | 5 ++- src/priority.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/priority.c diff --git a/Makefile.am b/Makefile.am index 217de7e..14a6cda 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,14 +27,15 @@ CLEANFILES = src/cli_parse.c src/cli_parse.h src/cli_def.c src/cli_val.c LDADD = src/libvyatta-cfg.la LDADD += /usr/lib/libglib-2.0.la - -sbin_PROGRAMS = src/my_commit1 +sbin_PROGRAMS = src/priority +sbin_PROGRAMS += src/my_commit1 sbin_PROGRAMS += src/my_commit2 sbin_PROGRAMS += src/exe_action sbin_PROGRAMS += src/dump sbin_PROGRAMS += src/my_delete sbin_PROGRAMS += src/my_set sbin_PROGRAMS += src/check_tmpl +src_priority_SOURCES = src/priority.c src_my_commit1_SOURCES = src/commit.c src_my_commit2_SOURCES = src/commit2.c src_exe_action_SOURCES = src/exe_action.c diff --git a/src/priority.c b/src/priority.c new file mode 100644 index 0000000..3b113f3 --- /dev/null +++ b/src/priority.c @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include +#include +#include + + +void recurse(char *cur_dir,FILE *out); + +/** + * + * + **/ +void +usage(void) +{ + printf("priority: recurses templates and generates priority file\n"); + printf("\t-h\thelp\n"); + printf("\t-f\toutput file\n"); +} + + +/** + * + * + **/ +int +main(int argc, char** argv) +{ + int ch; + char *filename = NULL; + + //grab inputs + while ((ch = getopt(argc, argv, "hf:")) != -1) { + switch (ch) { + case 'h': + usage(); + exit(0); + case 'f': + filename = optarg; + //GET OUT FILE HERE + } + + if (filename == NULL) { + strcpy(filename,"priority"); + } + + FILE *fp = fopen(filename,"w"); + if (fp == NULL) { + printf("cannot open priority file. exiting...\n"); + } + + char root_dir[2048] = ""; + recurse(root_dir,fp); + fclose(fp); + } +} + + +/** + * On each priority node write out location and value and continue recursion + * + **/ +void +recurse(char *cur_dir,FILE *out) +{ + char root_path[] = "/opt/vyatta/share/vyatta-cfg/templates"; + char str[2048]; + //open and scan node.def + + char file[2048]; + sprintf(file,"%s/%s/node.def",root_path,cur_dir); + FILE *fp = fopen(file,"r"); + // printf("found node.def at: %s\n",file); + + if (fp != NULL) { + while (fgets(str, 1024, fp) != 0) { + if (strncmp("priority:",str,9) == 0) { + //retrieve value and write out... + + const char delimiters[] = " "; + char *running; + char *token; + + running = strdup(str); + token = strsep(&running, delimiters); + token = strsep(&running, delimiters); + + unsigned long val = strtoul(token,NULL,10); + if (val > 0 && val <= 1000) { + fwrite(token,1,strlen(token)-1,out); + fwrite(" ",1,1,out); + + //remove fixed path + //offset by 1 to remove the leading slash + fwrite(cur_dir+1,1,strlen(cur_dir)-1,out); + fwrite("\n",1,1,out); + } + break; + } + } + fclose(fp); + } + + + //now recurse the other directories here. + //iterate over directory here + + char path[2048]; + sprintf(path,"%s/%s",root_path,cur_dir); + DIR *dp; + if ((dp = opendir(path)) == NULL) { + return; + } + + //finally iterate over valid child directory entries + struct dirent *dirp = NULL; + while ((dirp = readdir(dp)) != NULL) { + if (strcmp(dirp->d_name, ".") != 0 && + strcmp(dirp->d_name, "..") != 0 && + strcmp(dirp->d_name, "node.def") != 0) { + char local_dir[2048]; + strcpy(local_dir,cur_dir); + strcat(local_dir,"/"); + strcat(local_dir,dirp->d_name); + recurse(local_dir,out); + } + } + closedir(dp); +} -- cgit v1.2.3