Skip to content

Commit 628a308

Browse files
committed
Parse jobspec attributes.system optionally
Problem: Per RFC14, the "system" key under "attributes" is not required. However, while parsing the jobspec a number of unpacking code instances did something similar to the following: json_unpack ("{s:{s:{s?s}}}", "attributes", "system", "foo", &s); The code is attempting to unpack the optional field "attributes.system.foo", but is saying "attributes" and "attributes.system" are required. This has the potential to lead to unintentional parsing errors. Note that for JobspecV1 in RFC25, the "system" field is required under attributes due to the requirement for the "duration" field. This is likely why code was written this way. Solution: Update all code like the above into a style like: json_unpack ("{s:{s?{s?s}}}", "attributes", "system", "foo", &s); Where the "system" key is optional. Note that we do NOT update unpacking instances like this: json_unpack ("{s:{s:{s:s}}}", "attributes", "system", "foo", &s); In instances like this, "attributes.system.foo" is required for that particular circumstance. Therefore "attributes.system" is also required.
1 parent d1bc865 commit 628a308

File tree

11 files changed

+17
-17
lines changed

11 files changed

+17
-17
lines changed

src/modules/job-exec/sdexec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static struct sdexec *sdexec_create (flux_t *h,
262262
se->stderrlog = SDEXEC_LOG_EVENTLOG;
263263

264264
(void) json_unpack_ex (job->jobspec, NULL, 0,
265-
"{s:{s:{s:{s:{s?b s?s s?s s?b}}}}}",
265+
"{s:{s?{s?{s?{s?b s?s s?s s?b}}}}}",
266266
"attributes", "system", "exec", "sd",
267267
"test_exec_fail", &se->test_exec_fail,
268268
"stdoutlog", &stdoutlog,

src/modules/job-list/job_data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static int parse_per_resource (struct job *job,
175175
json_t *o = NULL;
176176

177177
if (json_unpack_ex (job->jobspec, &error, 0,
178-
"{s:{s:{s?:{s?:{s?:o}}}}}",
178+
"{s:{s?{s?:{s?:{s?:o}}}}}",
179179
"attributes",
180180
"system",
181181
"shell",
@@ -276,7 +276,7 @@ static int parse_jobspec (struct job *job, const char *s, bool allow_nonfatal)
276276
}
277277

278278
if (json_unpack_ex (job->jobspec, &error, 0,
279-
"{s:{s:{s?:o}}}",
279+
"{s:{s?{s?:o}}}",
280280
"attributes",
281281
"system",
282282
"job",
@@ -309,7 +309,7 @@ static int parse_jobspec (struct job *job, const char *s, bool allow_nonfatal)
309309
goto nonfatal_error;
310310

311311
if (json_unpack_ex (job->jobspec, &error, 0,
312-
"{s:{s:{s?:s s?s}}}",
312+
"{s:{s?{s?:s s?s}}}",
313313
"attributes",
314314
"system",
315315
"cwd", &job->cwd,

src/modules/job-manager/job.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static int jobspec_redacted_parse_queue (struct job *job)
161161
* optional
162162
*/
163163
if (json_unpack (job->jobspec_redacted,
164-
"{s?{s?{s?s}}}",
164+
"{s:{s?{s?s}}}",
165165
"attributes",
166166
"system",
167167
"queue", &job->queue) < 0) {

src/modules/job-manager/plugins/alloc-bypass.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static int validate_cb (flux_plugin_t *p,
182182

183183
if (flux_plugin_arg_unpack (args,
184184
FLUX_PLUGIN_ARG_IN,
185-
"{s:i s:{s:{s:{s?{s?o}}}}}",
185+
"{s:i s:{s:{s?{s?{s?o}}}}}",
186186
"userid", &userid,
187187
"jobspec",
188188
"attributes",

src/modules/job-manager/plugins/limit-job-size.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static int validate_cb (flux_plugin_t *p,
393393
if (json_unpack_ex (jobspec,
394394
&jerror,
395395
0,
396-
"{s?{s?{s?s}}}",
396+
"{s:{s?{s?s}}}",
397397
"attributes",
398398
"system",
399399
"queue", &queue) < 0) {

src/modules/sched-simple/sched.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobreq_create (const flux_msg_t *msg)
127127
job->errnum = errno;
128128
}
129129
if (json_unpack (jobspec,
130-
"{s?{s?{s?O}}}",
130+
"{s:{s?{s?O}}}",
131131
"attributes",
132132
"system",
133133
"constraints", &job->constraints) < 0) {
@@ -618,7 +618,7 @@ static void feasibility_cb (flux_t *h,
618618
"jobspec", &jobspec) < 0)
619619
goto err;
620620
if (json_unpack (jobspec,
621-
"{s?{s?{s?o}}}",
621+
"{s:{s?{s?o}}}",
622622
"attributes",
623623
"system",
624624
"constraints", &constraints) < 0)

src/shell/batch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int batch_init (flux_plugin_t *p,
213213
return shell_log_errno ("failed to unpack jobspec");
214214
json_error_t err;
215215
if (json_unpack_ex (jobspec, &err, 0,
216-
"{s:{s:{s?o}}}",
216+
"{s:{s?{s?o}}}",
217217
"attributes",
218218
"system",
219219
"batch", &batch) < 0) {

src/shell/files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int files_init (flux_plugin_t *p,
8383
return shell_log_errno ("flux_shell_getenv");
8484

8585
if (flux_shell_info_unpack (shell,
86-
"{s:{s:{s:{s?o}}}}",
86+
"{s:{s:{s?{s?o}}}}",
8787
"jobspec",
8888
"attributes",
8989
"system",

src/shell/jobspec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ struct jobspec *jobspec_parse (const char *jobspec, json_error_t *error)
235235
* json_t * objects)
236236
*/
237237
if (json_unpack_ex (job->jobspec, error, 0,
238-
"{s:i s:o s:o s:{s:{s?:s s?:O s?:{s?:O}}}}",
238+
"{s:i s:o s:o s:{s?{s?:s s?:O s?:{s?:O}}}}",
239239
"version", &job->version,
240240
"resources", &resources,
241241
"tasks", &tasks,

t/job-manager/plugins/dependency-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int depend_cb (flux_plugin_t *p,
132132

133133
if (flux_plugin_arg_unpack (args,
134134
FLUX_PLUGIN_ARG_IN,
135-
"{s:I s:{s:{s:{s?s}}}}",
135+
"{s:I s:{s:{s?{s?s}}}}",
136136
"id", &id,
137137
"jobspec",
138138
"attributes",

0 commit comments

Comments
 (0)