1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-11 20:58:27 +03:00

ukify: print all remaining log-like output to stderr

We want to be able to capture stdout for json and such, so convert
all remaining logging to stderr.

(cherry picked from commit cf4deeaf1e822ade5c1fbbe2584b23a2d0988439)
(cherry picked from commit 3110d46f4a7b6a41c9d6fc6a9f65cf7058bb4001)
This commit is contained in:
Luca Boccassi 2025-02-17 19:44:15 +00:00
parent f2d7b71376
commit 6fc9646401

View File

@ -202,7 +202,7 @@ def maybe_decompress(filename):
return lz4.frame.decompress(f.read())
if start.startswith(b'\x04\x22\x4d\x18'):
print('Newer lz4 stream format detected! This may not boot!')
print('Newer lz4 stream format detected! This may not boot!', file=sys.stderr)
lz4 = try_import('lz4.frame', 'lz4')
return lz4.frame.decompress(f.read())
@ -297,7 +297,7 @@ class Uname:
print(f'Found uname version: {version}', file=sys.stderr)
return version
except ValueError as e:
print(str(e))
print(str(e), file=sys.stderr)
return None
DEFAULT_SECTIONS_TO_SHOW = {
@ -703,14 +703,14 @@ def merge_sbat(input_pe: [pathlib.Path], input_text: [str]) -> str:
try:
pe = pefile.PE(f, fast_load=True)
except pefile.PEFormatError:
print(f"{f} is not a valid PE file, not extracting SBAT section.")
print(f"{f} is not a valid PE file, not extracting SBAT section.", file=sys.stderr)
continue
for section in pe.sections:
if section.Name.rstrip(b"\x00").decode() == ".sbat":
split = section.get_data().rstrip(b"\x00").decode().splitlines()
if not split[0].startswith('sbat,'):
print(f"{f} does not contain a valid SBAT section, skipping.")
print(f"{f} does not contain a valid SBAT section, skipping.", file=sys.stderr)
continue
# Filter out the sbat line, we'll add it back later, there needs to be only one and it
# needs to be first.
@ -721,7 +721,7 @@ def merge_sbat(input_pe: [pathlib.Path], input_text: [str]) -> str:
t = pathlib.Path(t[1:]).read_text()
split = t.splitlines()
if not split[0].startswith('sbat,'):
print(f"{t} does not contain a valid SBAT section, skipping.")
print(f"{t} does not contain a valid SBAT section, skipping.", file=sys.stderr)
continue
sbat += split[1:]
@ -1022,10 +1022,10 @@ def generate_keys(opts):
common_name=cn,
valid_days=opts.sb_cert_validity,
)
print(f'Writing SecureBoot private key to {opts.sb_key}')
print(f'Writing SecureBoot private key to {opts.sb_key}', file=sys.stderr)
with temporary_umask(0o077):
opts.sb_key.write_bytes(key_pem)
print(f'Writing SecureBoot certificate to {opts.sb_cert}')
print(f'Writing SecureBoot certificate to {opts.sb_cert}', file=sys.stderr)
opts.sb_cert.write_bytes(cert_pem)
work = True
@ -1033,11 +1033,11 @@ def generate_keys(opts):
for priv_key, pub_key, _ in key_path_groups(opts):
priv_key_pem, pub_key_pem = generate_priv_pub_key_pair()
print(f'Writing private key for PCR signing to {priv_key}')
print(f'Writing private key for PCR signing to {priv_key}', file=sys.stderr)
with temporary_umask(0o077):
pathlib.Path(priv_key).write_bytes(priv_key_pem)
if pub_key:
print(f'Writing public key for PCR signing to {pub_key}')
print(f'Writing public key for PCR signing to {pub_key}', file=sys.stderr)
pub_key.write_bytes(pub_key_pem)
work = True
@ -1073,7 +1073,7 @@ def inspect_section(opts, section):
try:
struct['text'] = data.decode()
except UnicodeDecodeError as e:
print(f"Section {name!r} is not valid text: {e}")
print(f"Section {name!r} is not valid text: {e}", file=sys.stderr)
struct['text'] = '(not valid UTF-8)'
if config and config.content:
@ -1569,7 +1569,7 @@ def apply_config(namespace, filename=None):
if item := CONFIGFILE_ITEMS.get(f'{section_name}/{key}'):
item.apply_config(namespace, section_name, group, key, value)
else:
print(f'Unknown config setting [{section_name}] {key}=')
print(f'Unknown config setting [{section_name}] {key}=', file=sys.stderr)
def config_example():