Skip to content

Commit b1d73af

Browse files
committed
Prevent broken output in "--progress" mode
In "--progress" mode we print out the rule id and ': ' before the rule evaluation starts and the rest of the line after the rule evaluation finishes. If any warning occurs during the evaluation, it's printed in the middle, which looks ugly. We can fix this by printing the whole line at the same moment, after the rule evaluation finishes. Also, the warnings should use dW macros in order to be able to turn them on/off using `--verbose` option. Related to https://bugzilla.redhat.com/show_bug.cgi?id=1640889
1 parent 39e91cf commit b1d73af

7 files changed

+11
-26
lines changed

src/XCCDF_POLICY/xccdf_policy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,10 @@ _xccdf_policy_rule_get_applicable_check(struct xccdf_policy *policy, struct xccd
592592

593593
// Only print a warning if we didn't select a check but could've otherwise.
594594
if (print_oval_warning) {
595-
printf("WARNING: Skipping rule that uses OVAL but is possibly malformed; "
595+
dW("Skipping rule that uses OVAL but is possibly malformed; "
596596
"an incorrect content reference prevents this check from being evaluated.\n");
597597
} else if (print_general_warning && result == NULL) {
598-
printf("WARNING: Skipping rule that requires an unregistered check system "
598+
dW("Skipping rule that requires an unregistered check system "
599599
"or incorrect content reference to evaluate. "
600600
"Please consider providing a valid SCAP/OVAL instead of %s\n",
601601
warning_check_system);

tests/API/XCCDF/unittests/test_xccdf_check_processing_selector_empty.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $OSCAP xccdf eval --profile xccdf_moc.elpmaxe.www_profile_1 --results $result $s
1212

1313
echo "Stderr file = $stderr"
1414
echo "Result file = $result"
15-
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
15+
rm $stderr
1616

1717
$OSCAP xccdf validate-xml $result
1818

tests/API/XCCDF/unittests/test_xccdf_check_unsupported_check_system.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ stderr=`mktemp`
88

99
$OSCAP xccdf eval --results $result $srcdir/test_xccdf_check_unsupported_check_system.xml 2> $stderr
1010
echo "Stderr file = $stderr"
11-
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
11+
rm $stderr
1212

1313
$OSCAP xccdf validate-xml $result
1414

tests/API/XCCDF/unittests/test_xccdf_check_without_content_refs.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ $OSCAP xccdf eval --results $result $srcdir/test_xccdf_check_without_content_ref
1010

1111
echo "Stderr file = $stderr"
1212
echo "Result file = $result"
13-
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
13+
[ -f $stderr ]
14+
rm $stderr
1415

1516
$OSCAP xccdf validate-xml $result
1617

tests/API/XCCDF/unittests/test_xccdf_multiple_testresults.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tmpdir=$(dirname $result)
1616
for i in {1..5}; do
1717
$OSCAP xccdf eval --results $result $result 2> $stderr
1818
[ -f $stderr ]
19-
[ "`cat $stderr`" == "WARNING: Skipping $tmpdir/non_existent.oval.xml file which is referenced from XCCDF content" ]
19+
grep "Skipping $tmpdir/non_existent\.oval\.xml file which is referenced from XCCDF content" $stderr
2020
:> $stderr
2121

2222
$OSCAP xccdf validate-xml $result

tests/API/XCCDF/unittests/test_xccdf_notchecked_has_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $OSCAP xccdf eval --results $result $srcdir/${name}.xccdf.xml 2> $stderr
1313
echo "Stderr file = $stderr"
1414
echo "Result file = $result"
1515
[ -f $stderr ]
16-
[ "WARNING: Skipping $srcdir/_non_existent_.oval.xml file which is referenced from XCCDF content" == "`cat $stderr`" ]
16+
grep "Skipping $srcdir/_non_existent_\.oval\.xml file which is referenced from XCCDF content" $stderr
1717
rm $stderr
1818

1919
$OSCAP xccdf validate-xml $result

utils/oscap-xccdf.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -374,21 +374,6 @@ static int callback_scr_result(struct xccdf_rule_result *rule_result, void *arg)
374374
return 0;
375375
}
376376

377-
static int callback_scr_rule_progress(struct xccdf_rule *rule, void *arg)
378-
{
379-
const char * rule_id = xccdf_rule_get_id(rule);
380-
381-
/* is rule selected? we print only selected rules */
382-
const bool selected = xccdf_policy_is_item_selected((struct xccdf_policy *) arg, rule_id);
383-
if (!selected)
384-
return 0;
385-
386-
printf("%s:", rule_id);
387-
fflush(stdout);
388-
389-
return 0;
390-
}
391-
392377
static int callback_scr_result_progress(struct xccdf_rule_result *rule_result, void *arg)
393378
{
394379
xccdf_test_result_type_t result = xccdf_rule_result_get_result(rule_result);
@@ -398,9 +383,10 @@ static int callback_scr_result_progress(struct xccdf_rule_result *rule_result, v
398383
return 0;
399384

400385
/* print result */
401-
const char * result_str = xccdf_test_result_type_get_text(result);
386+
const char *rule_id = xccdf_rule_result_get_idref(rule_result);
387+
const char *result_str = xccdf_test_result_type_get_text(result);
402388

403-
printf("%s\n", result_str);
389+
printf("%s:%s\n", rule_id, result_str);
404390
fflush(stdout);
405391

406392
return 0;
@@ -442,8 +428,6 @@ static void _register_progress_callback(struct xccdf_session *session, bool prog
442428
{
443429
struct xccdf_policy_model *policy_model = xccdf_session_get_policy_model(session);
444430
if (progress) {
445-
xccdf_policy_model_register_start_callback(policy_model, callback_scr_rule_progress,
446-
(void *) xccdf_session_get_xccdf_policy(session));
447431
xccdf_policy_model_register_output_callback(policy_model, callback_scr_result_progress, NULL);
448432
}
449433
else {

0 commit comments

Comments
 (0)