summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2025-11-27 17:31:53 +0200
committerGitHub <noreply@github.com>2025-11-27 17:31:53 +0200
commitccb2cfee31613df300563c1d38e78a3fb7283ce9 (patch)
treefd03a395aa36015cbbb0a5be91d87d06b7529b8a /src
parent721a85eb42c3283e30e33f89ca20b8e16d003642 (diff)
parent57f6c33f5523644fc33791ce71ef32874bf5b7f2 (diff)
downloadvyatta-cfg-ccb2cfee31613df300563c1d38e78a3fb7283ce9.tar.gz
vyatta-cfg-ccb2cfee31613df300563c1d38e78a3fb7283ce9.zip
Merge pull request #117 from dmbaturin/T8042-remove-priority.c
misc: T8042: remove the legacy priority utility
Diffstat (limited to 'src')
-rw-r--r--src/priority.c138
1 files changed, 0 insertions, 138 deletions
diff --git a/src/priority.c b/src/priority.c
deleted file mode 100644
index 5f12610..0000000
--- a/src/priority.c
+++ /dev/null
@@ -1,138 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <dirent.h>
-#include <sys/time.h>
-#include <string.h>
-#include <glib-object.h> /* g_type_init */
-
-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;
-
- /* this is needed before calling certain glib functions */
- #if !GLIB_CHECK_VERSION(2,35,0)
- g_type_init();
- #endif
-
- //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);
- }
- return 0;
-}
-
-
-/**
- * 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);
-}