Skip to content

Commit

Permalink
systemd: Clean up availableMitigations() caching
Browse files Browse the repository at this point in the history
Don't put the cache onto the function object, that confuses the type
checker. Make it an internal global variable instead.

Fixes

> pkg/systemd/hwinfo.jsx(133,39): error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

(There is another instance of this error which the next commit will
address).
  • Loading branch information
martinpitt authored and mvollmer committed Dec 20, 2024
1 parent 7006c07 commit 9b877aa
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/systemd/hwinfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ const SystemInfo = ({ info, onSecurityClick }) => {
);
};

let cachedMitigations;

function availableMitigations() {
if (availableMitigations.cachedMitigations !== undefined)
return Promise.resolve(availableMitigations.cachedMitigations);
if (cachedMitigations !== undefined)
return Promise.resolve(cachedMitigations);
/* nosmt */
const promises = [cockpit.spawn(["lscpu"], { environ: ["LC_ALL=C.UTF-8"], }), cockpit.file("/proc/cmdline").read()];
return Promise.all(promises).then(values => {
Expand All @@ -146,12 +148,12 @@ function availableMitigations() {
const nosmt_available = threads_per_core > 1 && (values[1].indexOf("nosmt=") === -1 || values[1].indexOf("nosmt=force") !== -1);
const mitigations_match = values[1].match(/\bmitigations=(\S*)\b/);

availableMitigations.cachedMitigations = {
cachedMitigations = {
available: nosmt_available,
nosmt_enabled,
mitigations_arg: mitigations_match ? mitigations_match[1] : undefined,
};
return availableMitigations.cachedMitigations;
return cachedMitigations;
});
}

Expand All @@ -172,7 +174,7 @@ const CPUSecurityMitigationsDialog = () => {
options = ['set', 'nosmt'];
} else {
// this may either be an argument of its own, or part of mitigations=
const ma = availableMitigations.cachedMitigations.mitigations_arg;
const ma = cachedMitigations.mitigations_arg;
if (ma && ma.indexOf("nosmt") >= 0) {
const new_args = ma.split(',').filter(opt => opt != 'nosmt');
options = ['set', 'mitigations=' + new_args.join(',')];
Expand Down

0 comments on commit 9b877aa

Please sign in to comment.