Skip to content

Commit 25c8f8e

Browse files
committed
flux-job: fix wait-event --match-context
Problem: The `flux job wait-event --match-context` option returns a match when the context value matches but they does not. Fix the logic in wait_event_test_context(). Fixes #5845
1 parent ed07466 commit 25c8f8e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/cmd/job/eventlog.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,30 +234,30 @@ struct wait_event_ctx {
234234
static bool wait_event_test_context (struct wait_event_ctx *ctx,
235235
json_t *context)
236236
{
237-
void *iter;
238-
bool match = false;
237+
const char *key;
238+
json_t *value;
239239

240-
iter = json_object_iter (context);
241-
while (iter && !match) {
242-
const char *key = json_object_iter_key (iter);
243-
json_t *value = json_object_iter_value (iter);
240+
json_object_foreach (context, key, value) {
244241
if (streq (key, ctx->context_key)) {
242+
bool match;
245243
char *str = json_dumps (value, JSON_ENCODE_ANY|JSON_COMPACT);
246-
if (streq (str, ctx->context_value))
247-
match = true;
244+
match = streq (str, ctx->context_value);
248245
free (str);
249-
}
250-
/* special case, json_dumps() will put quotes around string
251-
* values. Consider the case when user does not surround
252-
* string value with quotes */
253-
if (!match && json_is_string (value)) {
254-
const char *str = json_string_value (value);
255-
if (streq (str, ctx->context_value))
246+
247+
/* Also try json_string_value() when value is a string:
248+
*/
249+
if (!match
250+
&& json_is_string (value)
251+
&& streq (json_string_value (value), ctx->context_value))
256252
match = true;
253+
254+
/* Return immediately if a match was found:
255+
*/
256+
if (match)
257+
return true;
257258
}
258-
iter = json_object_iter_next (context, iter);
259259
}
260-
return match;
260+
return false;
261261
}
262262

263263
static bool wait_event_test (struct wait_event_ctx *ctx, json_t *event)

0 commit comments

Comments
 (0)