python312Packages.vdf: avoid using pname for src.repo
[NixPkgs.git] / pkgs / os-specific / linux / jool / validate-config.patch
blob8841b6fb14f34bd098bc42077f881c97af16d76d
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
6 ---
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,
22 + {
23 + .label = "check",
24 + .xt = XT_ANY,
25 + .handler = handle_file_check,
26 + .handle_autocomplete = autocomplete_file_update,
27 + },
28 { 0 },
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[] = {
36 { 0 },
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);
46 + if (result.error)
47 + return result.error;
49 + if (!uargs.file_name.value) {
50 + struct requirement reqs[] = {
51 + { false, "a file name" },
52 + { 0 }
53 + };
54 + return requirement_print(reqs);
55 + }
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,
70 - uargs.force.value);
71 + uargs.force.value, false);
73 joolnl_teardown(&sk);
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
79 @@ -2,6 +2,7 @@
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;
94 static __u8 force;
95 +static bool check;
97 struct json_meta {
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,
100 goto too_small;
102 nla_nest_end(msg, root);
103 - result = joolnl_request(&sk, msg, NULL, NULL);
104 - if (result.error)
105 - return result;
106 + if (!check) {
107 + result = joolnl_request(&sk, msg, NULL, NULL);
108 + if (result.error)
109 + return result;
112 msg = NULL;
113 json = json->prev;
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);
118 + if (check)
119 + return result_success();
120 return joolnl_request(&sk, msg, NULL, NULL);
122 too_small:
123 @@ -244,6 +249,8 @@ static struct jool_result handle_global(cJSON *json)
125 nla_nest_end(msg, root);
126 free(meta);
127 + if (check)
128 + return result_success();
129 return joolnl_request(&sk, msg, NULL, NULL);
131 revert_meta:
132 @@ -654,9 +661,11 @@ static struct jool_result send_ctrl_msg(bool init)
133 else
134 NLA_PUT(msg, JNLAR_ATOMIC_END, 0, NULL);
136 - result = joolnl_request(&sk, msg, NULL, NULL);
137 - if (result.error)
138 - return result;
139 + if (!check) {
140 + result = joolnl_request(&sk, msg, NULL, NULL);
141 + if (result.error)
142 + return result;
145 return result_success();
147 @@ -683,9 +692,11 @@ static struct jool_result do_parsing(char const *iname, char *buffer)
148 if (result.error)
149 goto fail;
151 - result = send_ctrl_msg(true);
152 - if (result.error)
153 - goto fail;
154 + if (!check) {
155 + result = send_ctrl_msg(true);
156 + if (result.error)
157 + goto fail;
160 switch (xlator_flags2xt(flags)) {
161 case XT_SIIT:
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)
169 char *buffer;
170 struct jool_result result;
172 sk = *_sk;
173 + check = _check;
174 flags = xt;
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(
182 xlator_type xt,
183 char const *iname,
184 char const *file_name,
185 - bool force
186 + bool force,
187 + bool check
190 struct jool_result joolnl_file_get_iname(
192 2.40.1