Skip to content

Commit 6e2d6b3

Browse files
committed
Stop using jq
The jq is additional tool. Currently it's available in both RHEL and CentOS base bootable container images. But, we better not rely on it if someone removes it in future.
1 parent 15c15c3 commit 6e2d6b3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/XCCDF/xccdf_session.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -1906,14 +1906,19 @@ struct xccdf_rule_result_iterator *xccdf_session_get_rule_results(const struct x
19061906
return xccdf_result_get_rule_results(session->xccdf.result);
19071907
}
19081908

1909-
static int system_is_in_bootc_mode(void)
1909+
static bool _system_is_in_bootc_mode(void)
19101910
{
19111911
#ifdef OS_WINDOWS
1912-
return 0;
1912+
return false;
19131913
#else
1914-
FILE *output = popen("bootc status --format json 2>/dev/null | jq \".status.booted\" 2>/dev/null", "r");
1914+
#define BOOTC_PATH "/usr/bin/bootc"
1915+
struct stat statbuf;
1916+
if (stat(BOOTC_PATH, &statbuf) == -1) {
1917+
return false;
1918+
}
1919+
FILE *output = popen(BOOTC_PATH " status --format json 2>/dev/null", "r");
19151920
if (output == NULL) {
1916-
return 0;
1921+
return false;
19171922
}
19181923
char buf[1024] = {0};
19191924
int c;
@@ -1923,7 +1928,7 @@ static int system_is_in_bootc_mode(void)
19231928
i++;
19241929
}
19251930
pclose(output);
1926-
return *buf != '\0' && strcmp(buf, "null\n") != 0;
1931+
return *buf != '\0' && strstr(buf, "\"status:\"null") == NULL;
19271932
#endif
19281933
}
19291934

@@ -1938,7 +1943,7 @@ int xccdf_session_remediate(struct xccdf_session *session)
19381943
oscap_seterr(OSCAP_EFAMILY_OSCAP, "Can't perform remediation in offline mode: not implemented");
19391944
return 1;
19401945
}
1941-
if (system_is_in_bootc_mode()) {
1946+
if (_system_is_in_bootc_mode()) {
19421947
oscap_seterr(OSCAP_EFAMILY_OSCAP,
19431948
"Detected running Image Mode operating system. OpenSCAP can't "
19441949
"perform remediation of this system because majority of the "

0 commit comments

Comments
 (0)