summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-09-11 08:59:02 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-09-11 08:59:02 -0700
commit9b6b62c3792ffcea6d9ae240a6dbe5b04065bf1e (patch)
treed3b6b64e6c4a905476306b2b9af64ea9a07188d6 /src
parente7239a890911aa7a169f02986e08b0e6e6de7159 (diff)
parent2cdab905bb8b92a00c8e57e638a9ccbc3244df65 (diff)
downloadvyatta-cfg-9b6b62c3792ffcea6d9ae240a6dbe5b04065bf1e.tar.gz
vyatta-cfg-9b6b62c3792ffcea6d9ae240a6dbe5b04065bf1e.zip
Merge branch 'kenwood' of suva.vyatta.com:/git/vyatta-cfg into kenwood
Diffstat (limited to 'src')
-rw-r--r--src/common/unionfs.c3
-rw-r--r--src/priority.c132
2 files changed, 134 insertions, 1 deletions
diff --git a/src/common/unionfs.c b/src/common/unionfs.c
index 5ef6618..6d71402 100644
--- a/src/common/unionfs.c
+++ b/src/common/unionfs.c
@@ -1039,7 +1039,8 @@ dlist_test_func(GQuark key_id,gpointer data,gpointer user_data)
else {
new_vn = vn;
// strcat(new_vn->_data._path,"/");
- strcat(new_vn->_data._path,"/value");
+ strcat(new_vn->_data._path,"/value:");
+ strcat(new_vn->_data._path,(char*)g_quark_to_string(key_id));
}
new_vn->_data._value = TRUE;
strcpy(new_vn->_data._name,(char*)g_quark_to_string(key_id));
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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <dirent.h>
+#include <sys/time.h>
+#include <string.h>
+
+
+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);
+}