1 From df0a1cf61188b5b7bb98675d746cb63d9300f148 Mon Sep 17 00:00:00 2001
2 From: rnhmjoj <rnhmjoj@inventati.org>
3 Date: Sat, 1 Jul 2023 18:47:05 +0200
4 Subject: [PATCH] Add mode to validate the atomic configuration
7 src/usr/argp/main.c | 6 ++++++
8 src/usr/argp/wargp/file.c | 26 +++++++++++++++++++++++++-
9 src/usr/argp/wargp/file.h | 1 +
10 src/usr/nl/file.c | 32 ++++++++++++++++++++++----------
11 src/usr/nl/file.h | 3 ++-
12 5 files changed, 56 insertions(+), 12 deletions(-)
14 diff --git a/src/usr/argp/main.c b/src/usr/argp/main.c
15 index 744a6df0..d04917da 100644
16 --- a/src/usr/argp/main.c
17 +++ b/src/usr/argp/main.c
18 @@ -238,6 +238,12 @@ static struct cmd_option file_ops[] = {
19 .handler = handle_file_update,
20 .handle_autocomplete = autocomplete_file_update,
25 + .handler = handle_file_check,
26 + .handle_autocomplete = autocomplete_file_update,
31 diff --git a/src/usr/argp/wargp/file.c b/src/usr/argp/wargp/file.c
32 index 0951b544..27ee3e64 100644
33 --- a/src/usr/argp/wargp/file.c
34 +++ b/src/usr/argp/wargp/file.c
35 @@ -26,6 +26,30 @@ static struct wargp_option update_opts[] = {
39 +int handle_file_check(char *iname, int argc, char **argv, void const *arg)
41 + struct update_args uargs = { 0 };
42 + struct joolnl_socket sk = { 0 };
43 + struct jool_result result;
45 + result.error = wargp_parse(update_opts, argc, argv, &uargs);
47 + return result.error;
49 + if (!uargs.file_name.value) {
50 + struct requirement reqs[] = {
51 + { false, "a file name" },
54 + return requirement_print(reqs);
57 + result = joolnl_file_parse(&sk, xt_get(), iname, uargs.file_name.value,
58 + uargs.force.value, true);
60 + return pr_result(&result);
63 int handle_file_update(char *iname, int argc, char **argv, void const *arg)
65 struct update_args uargs = { 0 };
66 @@ -49,7 +73,7 @@ int handle_file_update(char *iname, int argc, char **argv, void const *arg)
67 return pr_result(&result);
69 result = joolnl_file_parse(&sk, xt_get(), iname, uargs.file_name.value,
71 + uargs.force.value, false);
74 return pr_result(&result);
75 diff --git a/src/usr/argp/wargp/file.h b/src/usr/argp/wargp/file.h
76 index ce5de508..8ea4a4d2 100644
77 --- a/src/usr/argp/wargp/file.h
78 +++ b/src/usr/argp/wargp/file.h
80 #define SRC_USR_ARGP_WARGP_FILE_H_
82 int handle_file_update(char *iname, int argc, char **argv, void const *arg);
83 +int handle_file_check(char *iname, int argc, char **argv, void const *arg);
84 void autocomplete_file_update(void const *args);
86 #endif /* SRC_USR_ARGP_WARGP_FILE_H_ */
87 diff --git a/src/usr/nl/file.c b/src/usr/nl/file.c
88 index f9413236..51a668bd 100644
89 --- a/src/usr/nl/file.c
90 +++ b/src/usr/nl/file.c
91 @@ -29,6 +29,7 @@ static struct joolnl_socket sk;
92 static char const *iname;
93 static xlator_flags flags;
98 char const *name; /* This being NULL signals the end of the array. */
99 @@ -163,9 +164,11 @@ static struct jool_result handle_array(cJSON *json, int attrtype, char *name,
102 nla_nest_end(msg, root);
103 - result = joolnl_request(&sk, msg, NULL, NULL);
107 + result = joolnl_request(&sk, msg, NULL, NULL);
114 @@ -179,6 +182,8 @@ static struct jool_result handle_array(cJSON *json, int attrtype, char *name,
115 return result_success();
117 nla_nest_end(msg, root);
119 + return result_success();
120 return joolnl_request(&sk, msg, NULL, NULL);
123 @@ -244,6 +249,8 @@ static struct jool_result handle_global(cJSON *json)
125 nla_nest_end(msg, root);
128 + return result_success();
129 return joolnl_request(&sk, msg, NULL, NULL);
132 @@ -654,9 +661,11 @@ static struct jool_result send_ctrl_msg(bool init)
134 NLA_PUT(msg, JNLAR_ATOMIC_END, 0, NULL);
136 - result = joolnl_request(&sk, msg, NULL, NULL);
140 + result = joolnl_request(&sk, msg, NULL, NULL);
145 return result_success();
147 @@ -683,9 +692,11 @@ static struct jool_result do_parsing(char const *iname, char *buffer)
151 - result = send_ctrl_msg(true);
155 + result = send_ctrl_msg(true);
160 switch (xlator_flags2xt(flags)) {
162 @@ -718,12 +729,13 @@ fail:
165 struct jool_result joolnl_file_parse(struct joolnl_socket *_sk, xlator_type xt,
166 - char const *iname, char const *file_name, bool _force)
167 + char const *iname, char const *file_name, bool _force, bool _check)
170 struct jool_result result;
175 force = _force ? JOOLNLHDR_FLAGS_FORCE : 0;
177 diff --git a/src/usr/nl/file.h b/src/usr/nl/file.h
178 index 51802aaf..8b4a66dd 100644
179 --- a/src/usr/nl/file.h
180 +++ b/src/usr/nl/file.h
181 @@ -9,7 +9,8 @@ struct jool_result joolnl_file_parse(
184 char const *file_name,
190 struct jool_result joolnl_file_get_iname(