summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cli_new.c28
-rw-r--r--src/cli_path_utils.c6
-rw-r--r--src/commit.c20
-rw-r--r--src/delete.c23
-rw-r--r--src/set.c31
5 files changed, 63 insertions, 45 deletions
diff --git a/src/cli_new.c b/src/cli_new.c
index 630bf9f..97af812 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -94,6 +94,9 @@ static int set_reference_environment(const char* var_reference,
/*************************************************
GLOBAL FUNCTIONS
***************************************************/
+
+char *cli_operation_name = NULL;
+
/* it is executed as "eval `my_set` in order to be able to
modify BASH env
therefore, all error will be reported as
@@ -103,6 +106,9 @@ static int set_reference_environment(const char* var_reference,
void bye(char *msg, ...)
{
va_list ap;
+
+ fprintf(out_stream, "%s failed\n",
+ (cli_operation_name) ? cli_operation_name : "Operation");
if (is_silent_msg())
exit(-1);
@@ -323,8 +329,7 @@ void vtw_sort(valstruct *valp, vtw_sorted *sortp)
}
break;
default:
- printf("Unknown value in switch on line %d\n", __LINE__);
- exit(-5);
+ bye("Unknown value in switch on line %d\n", __LINE__);
}
if (sortp->num < 2)
return;
@@ -685,6 +690,8 @@ boolean val_cmp(valstruct *left, valstruct *right, vtw_cond_e cond)
rval = right->val;
else
rval = right->vals[rcur];
+
+ parts_num = 0;
switch (val_type) {
case IPV6_TYPE:
parts_num = 8;
@@ -713,8 +720,7 @@ boolean val_cmp(valstruct *left, valstruct *right, vtw_cond_e cond)
res = strcmp(lval, rval);
goto done_comp;
default:
- printf("Unknown value in switch on line %d\n", __LINE__);
- exit(-5);
+ bye("Unknown value in switch on line %d\n", __LINE__);
}
/* here to do a multistep int compare */
for (step = 0; step < parts_num; ++ step) {
@@ -1032,15 +1038,14 @@ static boolean check_syn_func(vtw_node *cur,const char* func,int line)
return ret;
case VAL_OP:
- printf("VAL op in check_syn\n");
- exit(-4);
+ bye("VAL op in check_syn\n");
case VAR_OP:
- printf("VAR op in check_syn\n");
- exit(-4);
+ bye("VAR op in check_syn\n");
default:
- printf("unknown op %d in check_syn\n", cur->vtw_node_oper);
- exit(-4);
+ bye("unknown op %d in check_syn\n", cur->vtw_node_oper);
}
+ /* not reachable */
+ return FALSE;
}
/*************************************************
@@ -1526,8 +1531,7 @@ int get_value_to_at_string(vtw_path *pathp) {
*****************************************************/
void out_of_memory()
{
- printf("\n\t!!! OUT OF MEMORY !!!\n");
- exit(-1);
+ bye("\n\t!!! OUT OF MEMORY !!!\n");
}
/*************************************************
diff --git a/src/cli_path_utils.c b/src/cli_path_utils.c
index 4045516..84a2bc0 100644
--- a/src/cli_path_utils.c
+++ b/src/cli_path_utils.c
@@ -483,8 +483,7 @@ char *clind_unescape(const char *name)
else if (*cp >='0' && *cp<='9')
*rcp = (*cp-'0')*16;
else {
- printf("Bad escape in |%s|\n", name);
- exit(-1);
+ bye("Bad escape in |%s|\n", name);
}
++cp;
if (*cp >='a' && *cp<='f')
@@ -494,8 +493,7 @@ char *clind_unescape(const char *name)
else if (*cp >='0' && *cp<='9')
*rcp += (*cp-'0');
else {
- printf("Bad escape in |%s|\n", name);
- exit(-1);
+ bye("Bad escape in |%s|\n", name);
}
}else
*rcp = *cp;
diff --git a/src/commit.c b/src/commit.c
index a73adac..4820094 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -32,6 +32,8 @@ static boolean commit_delete_children(vtw_def *defp, boolean deleting,
static boolean commit_update_children(vtw_def *defp, boolean creating,
boolean in_txn, boolean *parent_update);
+extern char *cli_operation_name;
+
#if BITWISE
static void make_dir()
{
@@ -94,7 +96,7 @@ static boolean validate_dir_for_commit()
if ((status = parse_def(&def, t_path.path,
FALSE))) {
- exit(status);
+ bye("parse error: %d\n", status);
}
}
@@ -257,8 +259,10 @@ int main(int argc, char **argv)
int st;
boolean update_pending = FALSE;
+ cli_operation_name = "Commit";
+
if (initialize_output() == -1) {
- exit(-1);
+ bye("can't initialize output\n");
}
set_in_commit(TRUE);
@@ -421,9 +425,9 @@ boolean commit_update_child(vtw_def *pdefp, char *child,
#ifdef DEBUG1
printf("Parsing definition\n");
#endif
- if ((status = parse_def(&def, t_path.path,
- FALSE)))
- exit(status);
+ if ((status = parse_def(&def, t_path.path, FALSE))) {
+ bye("parse error: %d\n", status);
+ }
my_defp = act_defp = &def;
if (def.tag)
multi_tag = TRUE;
@@ -754,9 +758,9 @@ static boolean commit_delete_child(vtw_def *pdefp, char *child,
#ifdef DEBUG1
printf("Parsing definition\n");
#endif
- if ((status = parse_def(&def, t_path.path,
- FALSE)))
- exit(status);
+ if ((status = parse_def(&def, t_path.path, FALSE))) {
+ bye("parse error: %d\n", status);
+ }
my_defp = act_defp = &def;
if (def.tag)
multi_tag = TRUE; /* tag node itself*/
diff --git a/src/delete.c b/src/delete.c
index f048f46..1b7b62e 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -8,6 +8,8 @@
#include "cli_val.h"
#include "cli_objects.h"
+extern char *cli_operation_name;
+
static void remove_rf(boolean do_umount)
{
char *command;
@@ -52,8 +54,9 @@ boolean set_validate(vtw_def *defp, char *valp)
}
/* defniition present */
memset(defp, 0, sizeof(vtw_def));
- if ((status = parse_def(defp, t_path.path, FALSE)))
- exit(status);
+ if ((status = parse_def(defp, t_path.path, FALSE))) {
+ bye("parse error: %d\n", status);
+ }
res = validate_value(defp, valp);
pop_path(&t_path);
return res;
@@ -71,13 +74,15 @@ int main(int argc, char **argv)
char *cp, *delp, *endp;
boolean do_umount;
+ cli_operation_name = "Delete";
+
if (initialize_output() == -1) {
- exit(-1);
+ bye("can't initialize output\n");
}
if (argc < 2) {
fprintf(out_stream, "Need to specify the config node to delete\n");
- exit(1);
+ bye("nothing to delete\n");
}
dump_log( argc, argv);
@@ -160,8 +165,9 @@ int main(int argc, char **argv)
(statbuf.st_mode & S_IFMT) == S_IFREG) {
/* defniition present */
memset(&def, 0, sizeof(vtw_def));
- if ((status = parse_def(&def, t_path.path, FALSE)))
- exit(status);
+ if ((status = parse_def(&def, t_path.path, FALSE))) {
+ bye("parse error: %d\n", status);
+ }
if (!def.tag && !def.multi && def.def_type!= ERROR_TYPE) {
/* signgle value */
/* is it modified ==
@@ -209,8 +215,9 @@ int main(int argc, char **argv)
}
/* defniition present */
memset(&def, 0, sizeof(vtw_def));
- if ((status = parse_def(&def, t_path.path, FALSE)))
- exit(status);
+ if ((status = parse_def(&def, t_path.path, FALSE))) {
+ bye("parse error: %d\n", status);
+ }
if (def.multi) {
/* delete from multivalue */
valstruct new_value, old_value;
diff --git a/src/set.c b/src/set.c
index 09f3ec6..4308d45 100644
--- a/src/set.c
+++ b/src/set.c
@@ -10,6 +10,8 @@
#include "cli_objects.h"
#include "cli_path_utils.h"
+extern char *cli_operation_name;
+
static void make_dir(void);
static void handle_defaults(void);
@@ -37,7 +39,7 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val)
if (valp[i] == '\'') {
fprintf(out_stream, "Cannot use the \"'\" (single quote) character "
"in a value string\n");
- exit(1);
+ bye("single quote in value string\n");
}
}
@@ -67,8 +69,9 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val)
}
/* defniition present */
memset(defp, 0, sizeof(vtw_def));
- if ((status = parse_def(defp, t_path.path, FALSE)))
- exit(status);
+ if ((status = parse_def(defp, t_path.path, FALSE))) {
+ bye("parse error: %d\n", status);
+ }
pop_path(&t_path);
if(path_end) {
push_path(&t_path,path_end);
@@ -108,8 +111,10 @@ int main(int argc, char **argv)
boolean need_mod = FALSE, not_new = FALSE;
boolean empty_val = FALSE;
+ cli_operation_name = "Set";
+
if (initialize_output() == -1) {
- exit(-1);
+ bye("can't initialize output\n");
}
dump_log( argc, argv);
@@ -147,7 +152,7 @@ int main(int argc, char **argv)
last_tag = TRUE;
/* every time tag match, need to verify*/
if(!set_validate(&def, argv[ai], FALSE)) {
- exit(1);
+ bye("value \"%s\" is not valid\n", argv[ai]);
}
continue;
}
@@ -168,8 +173,9 @@ int main(int argc, char **argv)
push_path(&t_path, DEF_NAME);
if (lstat(t_path.path, &statbuf) >= 0) {
memset(&def, 0, sizeof(vtw_def));
- if ((status = parse_def(&def, t_path.path, FALSE)))
- exit(status);
+ if ((status = parse_def(&def, t_path.path, FALSE))) {
+ bye("parse error: %d\n", status);
+ }
if (def.def_type != ERROR_TYPE && !def.tag) {
fprintf(out_stream,
"The specified configuration node requires a value\n");
@@ -178,7 +184,7 @@ int main(int argc, char **argv)
if (def.def_type == ERROR_TYPE && !def.tag) {
pop_path(&t_path);
if(!validate_value(&def, "")) {
- exit(1);
+ bye("validate_value failed\n");
}
push_path(&t_path, DEF_NAME);
}
@@ -190,10 +196,9 @@ int main(int argc, char **argv)
exit(0);
}
if(ai < argc -1 || last_tag) {
- fprintf(stderr, "There is no appropriate template for %s",
- m_path.path + strlen(get_mdirp()));
fprintf(out_stream, "The specified configuration node is not valid\n");
- exit(1);
+ bye("There is no appropriate template for %s",
+ m_path.path + strlen(get_mdirp()));
}
/*ai == argc -1, must be actual value */
if (!empty_val) {
@@ -203,7 +208,7 @@ int main(int argc, char **argv)
handle_defaults();
if(!set_validate(&def, argv[argc-1], empty_val)) {
- exit(1);
+ bye("value \"%s\" is not valid\n", argv[argc - 1]);
}
push_path(&m_path, VAL_NAME);
/* set value */
@@ -292,7 +297,7 @@ handle_default(vtw_path *mpath, vtw_path *tpath, char *exclude)
if ((dp = opendir(tpath->path)) == NULL) {
perror("handle_default: opendir");
- exit(-1);
+ bye("opendir failed\n");
}
while ((dirp = readdir(dp)) != NULL) {