1
0
mirror of https://github.com/systemd/systemd synced 2026-04-12 01:55:10 +02:00

Compare commits

...

13 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
5f74fcd41c basic/log: allow errno values higher than 255
When the support for "synthetic errno" was added, we started truncating
the errno value to just the least significant byte. This is generally OK,
because errno values are defined up to ~130.

The docs don't really say what the maximum value is. But at least in principle
higher values could be added in the future. So let's stop truncating
the values needlessly.

The kernel (or libbpf?) have an error where they return 524 as an errno
value (https://bugzilla.redhat.com/show_bug.cgi?id=2036145). We would
confusingly truncate this to 12 (ENOMEM). It seems much nicer to let
strerror() give us "Unknown error 524" rather than to print the bogus
message about ENOMEM.
2022-01-03 22:46:32 +00:00
Zbigniew Jędrzejewski-Szmek
c790632cab coredump: do not crash if we failed to acquire exe path
The COREDUMP_EXE attribute is "optional", i.e. we continue to process the
crash even if we didn't acquire it. The coredump generation code assumed
that it is always available:

 #5 endswith at ../src/fundamental/string-util-fundamental.c:41
 [ endswith() is called with NULL here, and an assertion fails. ]
 #6 submit_coredump at ../src/coredump/coredump.c:823
 #7 process_socket at ../src/coredump/coredump.c:1038
 #8 run at ../src/coredump/coredump.c:1413

We use the exe path for loop detection, and also (ultimately) pass it to
dwfl_core_file_report(). The latter seems to be fine will NULL, so let's just
change our code to look at COMM, which should be more reliable anyway.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2036517.
2022-01-03 22:44:44 +00:00
Luca Boccassi
73dfeb0c6e
Merge pull request #21985 from yuwata/elf-util-cleanups
elf-util: several cleanups
2022-01-03 22:44:20 +00:00
Yu Watanabe
633c3e8aa2 coredump: drop unnecessary parentheses 2022-01-04 04:27:11 +09:00
Yu Watanabe
80b241f2ec elf-util: add missing assertion 2022-01-04 04:27:11 +09:00
Yu Watanabe
fe8fdc4760 elf-util: reduce variable scope 2022-01-04 04:27:11 +09:00
Yu Watanabe
d090049c01 elf-util: executable argument for parse_elf() may be NULL
Fixes assertion triggered by parse_package_metadata() and json_build().
2022-01-04 04:27:09 +09:00
Yu Watanabe
3876cfafd0 elf-util: reduce variable scope and indentation 2022-01-04 04:11:55 +09:00
Yu Watanabe
e794bcaf1c elf-util: reduce variable scope and indentation 2022-01-04 04:11:55 +09:00
Zbigniew Jędrzejewski-Szmek
e97a300148
Merge pull request #21941 from yuwata/hostname-handle-empty
hostname-setup: support kernel with empty CONFIG_DEFAULT_HOSTNAME
2022-01-03 19:56:57 +01:00
Jan Janssen
8fb16fee96 boot: Do not warn if an initializing driver returns EFI_ABORTED
Fixes: #21965
2022-01-03 19:42:36 +01:00
Yu Watanabe
9383fa08bd hostname-util: drop GET_HOSTNAME_ALLOW_NONE flag and always refuse "(none)"
The flag is now only used in test-sysctl-util.c, and it should be
replaced with uname(), because of the same reason as the previous
commit.
2021-12-31 04:05:38 +09:00
Yu Watanabe
d8d6b2275f hostname-setup: gracefully handle kernel with empty CONFIG_DEFAULT_HOSTNAME
Previously, sethostname_idempotent_full() calls gethostname_full() with
GET_HOSTNAME_ALLOW_NONE and GET_HOSTNAME_ALLOW_LOCALHOST flags. That
intended to get any values set by kernel. But, that does not work, as
the hostname may be empty.

Let's simplify the logic. The function sethostname_idempotent_full()
intends to set the requested hostname only when the current hostname
is different from the requested one. So, no check in getostname_full()
is required. Hence, simply use the result of uname() here.

Fixes #21896.
2021-12-31 03:58:06 +09:00
8 changed files with 119 additions and 104 deletions

View File

@ -46,8 +46,7 @@ int gethostname_full(GetHostnameFlags flags, char **ret) {
assert_se(uname(&u) >= 0); assert_se(uname(&u) >= 0);
s = u.nodename; s = u.nodename;
if (isempty(s) || if (isempty(s) || streq(s, "(none)") ||
(!FLAGS_SET(flags, GET_HOSTNAME_ALLOW_NONE) && streq(s, "(none)")) ||
(!FLAGS_SET(flags, GET_HOSTNAME_ALLOW_LOCALHOST) && is_localhost(s)) || (!FLAGS_SET(flags, GET_HOSTNAME_ALLOW_LOCALHOST) && is_localhost(s)) ||
(FLAGS_SET(flags, GET_HOSTNAME_SHORT) && s[0] == '.')) { (FLAGS_SET(flags, GET_HOSTNAME_SHORT) && s[0] == '.')) {
if (!FLAGS_SET(flags, GET_HOSTNAME_FALLBACK_DEFAULT)) if (!FLAGS_SET(flags, GET_HOSTNAME_FALLBACK_DEFAULT))

View File

@ -9,10 +9,9 @@
#include "strv.h" #include "strv.h"
typedef enum GetHostnameFlags { typedef enum GetHostnameFlags {
GET_HOSTNAME_ALLOW_NONE = 1 << 0, /* accepts "(none)". */ GET_HOSTNAME_ALLOW_LOCALHOST = 1 << 0, /* accepts "localhost" or friends. */
GET_HOSTNAME_ALLOW_LOCALHOST = 1 << 1, /* accepts "localhost" or friends. */ GET_HOSTNAME_FALLBACK_DEFAULT = 1 << 1, /* use default hostname if no hostname is set. */
GET_HOSTNAME_FALLBACK_DEFAULT = 1 << 2, /* use default hostname if no hostname is set. */ GET_HOSTNAME_SHORT = 1 << 2, /* kills the FQDN part if present. */
GET_HOSTNAME_SHORT = 1 << 3, /* kills the FQDN part if present. */
} GetHostnameFlags; } GetHostnameFlags;
int gethostname_full(GetHostnameFlags flags, char **ret); int gethostname_full(GetHostnameFlags flags, char **ret);

View File

@ -31,10 +31,10 @@ typedef enum LogTarget{
* used a regular log level. */ * used a regular log level. */
#define LOG_NULL (LOG_EMERG - 1) #define LOG_NULL (LOG_EMERG - 1)
/* Note to readers: << and >> have lower precedence than & and | */ /* Note to readers: << and >> have lower precedence (are evaluated earlier) than & and | */
#define SYNTHETIC_ERRNO(num) (1 << 30 | (num)) #define SYNTHETIC_ERRNO(num) (1 << 30 | (num))
#define IS_SYNTHETIC_ERRNO(val) ((val) >> 30 & 1) #define IS_SYNTHETIC_ERRNO(val) ((val) >> 30 & 1)
#define ERRNO_VALUE(val) (abs(val) & 255) #define ERRNO_VALUE(val) (abs(val) & ~(1 << 30))
/* The callback function to be invoked when syntax warnings are seen /* The callback function to be invoked when syntax warnings are seen
* in the unit files. */ * in the unit files. */

View File

@ -43,8 +43,13 @@ static EFI_STATUS load_one_driver(
return log_error_status_stall(EFI_INVALID_PARAMETER, L"Image %s is not a driver, refusing: %r", fname); return log_error_status_stall(EFI_INVALID_PARAMETER, L"Image %s is not a driver, refusing: %r", fname);
err = BS->StartImage(image, NULL, NULL); err = BS->StartImage(image, NULL, NULL);
if (EFI_ERROR(err)) if (EFI_ERROR(err)) {
return log_error_status_stall(err, L"Failed to start image %s: %r", fname, err); /* EFI_ABORTED signals an initializing driver. It uses this error code on success
* so that it is unloaded after. */
if (err != EFI_ABORTED)
log_error_stall(L"Failed to start image %s: %r", fname, err);
return err;
}
TAKE_PTR(image); TAKE_PTR(image);
return EFI_SUCCESS; return EFI_SUCCESS;

View File

@ -793,10 +793,9 @@ static int submit_coredump(
r = maybe_remove_external_coredump(filename, coredump_node_fd >= 0 ? coredump_compressed_size : coredump_size); r = maybe_remove_external_coredump(filename, coredump_node_fd >= 0 ? coredump_compressed_size : coredump_size);
if (r < 0) if (r < 0)
return r; return r;
if (r == 0) { if (r == 0)
(void) iovw_put_string_field(iovw, "COREDUMP_FILENAME=", filename); (void) iovw_put_string_field(iovw, "COREDUMP_FILENAME=", filename);
else if (arg_storage == COREDUMP_STORAGE_EXTERNAL)
} else if (arg_storage == COREDUMP_STORAGE_EXTERNAL)
log_info("The core will not be stored: size %"PRIu64" is greater than %"PRIu64" (the configured maximum)", log_info("The core will not be stored: size %"PRIu64" is greater than %"PRIu64" (the configured maximum)",
coredump_node_fd >= 0 ? coredump_compressed_size : coredump_size, arg_external_size_max); coredump_node_fd >= 0 ? coredump_compressed_size : coredump_size, arg_external_size_max);
@ -813,16 +812,19 @@ static int submit_coredump(
return log_error_errno(r, "Failed to drop privileges: %m"); return log_error_errno(r, "Failed to drop privileges: %m");
/* Try to get a stack trace if we can */ /* Try to get a stack trace if we can */
if (coredump_size > arg_process_size_max) { if (coredump_size > arg_process_size_max)
log_debug("Not generating stack trace: core size %"PRIu64" is greater " log_debug("Not generating stack trace: core size %"PRIu64" is greater "
"than %"PRIu64" (the configured maximum)", "than %"PRIu64" (the configured maximum)",
coredump_size, arg_process_size_max); coredump_size, arg_process_size_max);
} else if (coredump_fd >= 0) else if (coredump_fd >= 0) {
bool skip = startswith(context->meta[META_COMM], "systemd-coredum"); /* COMM is 16 bytes usually */
(void) parse_elf_object(coredump_fd, (void) parse_elf_object(coredump_fd,
context->meta[META_EXE], context->meta[META_EXE],
/* fork_disable_dump= */endswith(context->meta[META_EXE], "systemd-coredump"), /* avoid loops */ /* fork_disable_dump= */ skip, /* avoid loops */
&stacktrace, &stacktrace,
&json_metadata); &json_metadata);
}
log: log:
core_message = strjoina("Process ", context->meta[META_ARGV_PID], core_message = strjoina("Process ", context->meta[META_ARGV_PID],
@ -857,21 +859,24 @@ log:
(void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_JSON=", formatted_json); (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_JSON=", formatted_json);
} }
JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, json_metadata) { /* In the unlikely scenario that context->meta[META_EXE] is not available,
JsonVariant *package_name, *package_version; * let's avoid guessing the module name and skip the loop. */
if (context->meta[META_EXE])
JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, json_metadata) {
JsonVariant *t;
/* We only add structured fields for the 'main' ELF module */ /* We only add structured fields for the 'main' ELF module, and only if we can identify it. */
if (!path_equal_filename(module_name, context->meta[META_EXE])) if (!path_equal_filename(module_name, context->meta[META_EXE]))
continue; continue;
package_name = json_variant_by_key(module_json, "name"); t = json_variant_by_key(module_json, "name");
if (package_name) if (t)
(void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_NAME=", json_variant_string(package_name)); (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_NAME=", json_variant_string(t));
package_version = json_variant_by_key(module_json, "version"); t = json_variant_by_key(module_json, "version");
if (package_version) if (t)
(void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_VERSION=", json_variant_string(package_version)); (void) iovw_put_string_field(iovw, "COREDUMP_PACKAGE_VERSION=", json_variant_string(t));
} }
/* Optionally store the entire coredump in the journal */ /* Optionally store the entire coredump in the journal */
if (arg_storage == COREDUMP_STORAGE_JOURNAL && coredump_fd >= 0) { if (arg_storage == COREDUMP_STORAGE_JOURNAL && coredump_fd >= 0) {
@ -1181,7 +1186,7 @@ static int gather_pid_metadata(struct iovec_wrapper *iovw, Context *context) {
if (r < 0) if (r < 0)
return r; return r;
/* The following are optional but we used them if present */ /* The following are optional, but we use them if present. */
r = get_process_exe(pid, &t); r = get_process_exe(pid, &t);
if (r >= 0) if (r >= 0)
r = iovw_put_string_field_free(iovw, "COREDUMP_EXE=", t); r = iovw_put_string_field_free(iovw, "COREDUMP_EXE=", t);
@ -1191,7 +1196,6 @@ static int gather_pid_metadata(struct iovec_wrapper *iovw, Context *context) {
if (cg_pid_get_unit(pid, &t) >= 0) if (cg_pid_get_unit(pid, &t) >= 0)
(void) iovw_put_string_field_free(iovw, "COREDUMP_UNIT=", t); (void) iovw_put_string_field_free(iovw, "COREDUMP_UNIT=", t);
/* The next are optional */
if (cg_pid_get_user_unit(pid, &t) >= 0) if (cg_pid_get_user_unit(pid, &t) >= 0)
(void) iovw_put_string_field_free(iovw, "COREDUMP_USER_UNIT=", t); (void) iovw_put_string_field_free(iovw, "COREDUMP_USER_UNIT=", t);

View File

@ -178,8 +178,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(Elf *, sym_elf_end, NULL);
static int frame_callback(Dwfl_Frame *frame, void *userdata) { static int frame_callback(Dwfl_Frame *frame, void *userdata) {
StackContext *c = userdata; StackContext *c = userdata;
Dwarf_Addr pc, pc_adjusted, bias = 0; Dwarf_Addr pc, pc_adjusted;
_cleanup_free_ Dwarf_Die *scopes = NULL;
const char *fname = NULL, *symbol = NULL; const char *fname = NULL, *symbol = NULL;
Dwfl_Module *module; Dwfl_Module *module;
bool is_activation; bool is_activation;
@ -198,29 +197,32 @@ static int frame_callback(Dwfl_Frame *frame, void *userdata) {
module = sym_dwfl_addrmodule(c->dwfl, pc_adjusted); module = sym_dwfl_addrmodule(c->dwfl, pc_adjusted);
if (module) { if (module) {
Dwarf_Die *s, *cudie; Dwarf_Addr start, bias = 0;
int n; Dwarf_Die *cudie;
Dwarf_Addr start;
cudie = sym_dwfl_module_addrdie(module, pc_adjusted, &bias); cudie = sym_dwfl_module_addrdie(module, pc_adjusted, &bias);
if (cudie) { if (cudie) {
_cleanup_free_ Dwarf_Die *scopes = NULL;
int n;
n = sym_dwarf_getscopes(cudie, pc_adjusted - bias, &scopes); n = sym_dwarf_getscopes(cudie, pc_adjusted - bias, &scopes);
if (n > 0) if (n > 0)
for (s = scopes; s && s < scopes + n; s++) { for (Dwarf_Die *s = scopes; s && s < scopes + n; s++) {
if (IN_SET(sym_dwarf_tag(s), DW_TAG_subprogram, DW_TAG_inlined_subroutine, DW_TAG_entry_point)) { Dwarf_Attribute *a, space;
Dwarf_Attribute *a, space;
a = sym_dwarf_attr_integrate(s, DW_AT_MIPS_linkage_name, &space); if (!IN_SET(sym_dwarf_tag(s), DW_TAG_subprogram, DW_TAG_inlined_subroutine, DW_TAG_entry_point))
if (!a) continue;
a = sym_dwarf_attr_integrate(s, DW_AT_linkage_name, &space);
if (a)
symbol = sym_dwarf_formstring(a);
if (!symbol)
symbol = sym_dwarf_diename(s);
if (symbol) a = sym_dwarf_attr_integrate(s, DW_AT_MIPS_linkage_name, &space);
break; if (!a)
} a = sym_dwarf_attr_integrate(s, DW_AT_linkage_name, &space);
if (a)
symbol = sym_dwarf_formstring(a);
if (!symbol)
symbol = sym_dwarf_diename(s);
if (symbol)
break;
} }
} }
@ -286,7 +288,6 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e
/* Iterate over all program headers in that ELF object. These will have been copied by /* Iterate over all program headers in that ELF object. These will have been copied by
* the kernel verbatim when the core file is generated. */ * the kernel verbatim when the core file is generated. */
for (size_t i = 0; i < n_program_headers; ++i) { for (size_t i = 0; i < n_program_headers; ++i) {
size_t note_offset = 0, name_offset, desc_offset;
GElf_Phdr mem, *program_header; GElf_Phdr mem, *program_header;
GElf_Nhdr note_header; GElf_Nhdr note_header;
Elf_Data *data; Elf_Data *data;
@ -311,8 +312,11 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e
if (!data) if (!data)
continue; continue;
while (note_offset < data->d_size && for (size_t note_offset = 0, name_offset, desc_offset;
(note_offset = sym_gelf_getnote(data, note_offset, &note_header, &name_offset, &desc_offset)) > 0) { note_offset < data->d_size &&
(note_offset = sym_gelf_getnote(data, note_offset, &note_header, &name_offset, &desc_offset)) > 0;) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
const char *note_name = (const char *)data->d_buf + name_offset; const char *note_name = (const char *)data->d_buf + name_offset;
const char *payload = (const char *)data->d_buf + desc_offset; const char *payload = (const char *)data->d_buf + desc_offset;
@ -321,50 +325,50 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e
/* Package metadata might have different owners, but the /* Package metadata might have different owners, but the
* magic ID is always the same. */ * magic ID is always the same. */
if (note_header.n_type == ELF_PACKAGE_METADATA_ID) { if (note_header.n_type != ELF_PACKAGE_METADATA_ID)
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL; continue;
r = json_parse(payload, 0, &v, NULL, NULL); r = json_parse(payload, 0, &v, NULL, NULL);
if (r < 0) if (r < 0)
return log_error_errno(r, "json_parse on %s failed: %m", payload); return log_error_errno(r, "json_parse on %s failed: %m", payload);
/* First pretty-print to the buffer, so that the metadata goes as /* First pretty-print to the buffer, so that the metadata goes as
* plaintext in the journal. */ * plaintext in the journal. */
if (c->f) { if (c->f) {
fprintf(c->f, "Metadata for module %s owned by %s found: ", fprintf(c->f, "Metadata for module %s owned by %s found: ",
name, note_name); name, note_name);
json_variant_dump(v, JSON_FORMAT_NEWLINE|JSON_FORMAT_PRETTY, c->f, NULL); json_variant_dump(v, JSON_FORMAT_NEWLINE|JSON_FORMAT_PRETTY, c->f, NULL);
fputc('\n', c->f); fputc('\n', c->f);
} }
/* Secondly, if we have a build-id, merge it in the same JSON object /* Secondly, if we have a build-id, merge it in the same JSON object
* so that it appears all nicely together in the logs/metadata. */ * so that it appears all nicely together in the logs/metadata. */
if (id_json) { if (id_json) {
r = json_variant_merge(&v, id_json); r = json_variant_merge(&v, id_json);
if (r < 0)
return log_error_errno(r, "json_variant_merge of package meta with buildid failed: %m");
}
/* Then we build a new object using the module name as the key, and merge it
* with the previous parses, so that in the end it all fits together in a single
* JSON blob. */
r = json_build(&w, JSON_BUILD_OBJECT(JSON_BUILD_PAIR(name, JSON_BUILD_VARIANT(v))));
if (r < 0)
return log_error_errno(r, "Failed to build JSON object: %m");
r = json_variant_merge(c->package_metadata, w);
if (r < 0) if (r < 0)
return log_error_errno(r, "json_variant_merge of package meta with buildid failed: %m"); return log_error_errno(r, "json_variant_merge of package meta with buildid failed: %m");
/* Finally stash the name, so we avoid double visits. */
r = set_put_strdup(c->modules, name);
if (r < 0)
return log_error_errno(r, "set_put_strdup failed: %m");
if (ret_interpreter_found)
*ret_interpreter_found = interpreter_found;
return 1;
} }
/* Then we build a new object using the module name as the key, and merge it
* with the previous parses, so that in the end it all fits together in a single
* JSON blob. */
r = json_build(&w, JSON_BUILD_OBJECT(JSON_BUILD_PAIR(name, JSON_BUILD_VARIANT(v))));
if (r < 0)
return log_error_errno(r, "Failed to build JSON object: %m");
r = json_variant_merge(c->package_metadata, w);
if (r < 0)
return log_error_errno(r, "json_variant_merge of package meta with buildid failed: %m");
/* Finally stash the name, so we avoid double visits. */
r = set_put_strdup(c->modules, name);
if (r < 0)
return log_error_errno(r, "set_put_strdup failed: %m");
if (ret_interpreter_found)
*ret_interpreter_found = interpreter_found;
return 1;
} }
} }
@ -384,6 +388,7 @@ static int parse_buildid(Dwfl_Module *mod, Elf *elf, const char *name, StackCont
int r; int r;
assert(mod || elf); assert(mod || elf);
assert(name);
assert(c); assert(c);
if (mod) if (mod)
@ -572,7 +577,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
.package_metadata = &package_metadata, .package_metadata = &package_metadata,
.modules = &modules, .modules = &modules,
}; };
const char *elf_architecture = NULL, *elf_type; const char *elf_type;
GElf_Ehdr elf_header; GElf_Ehdr elf_header;
size_t sz = 0; size_t sz = 0;
int r; int r;
@ -610,19 +615,20 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
elf_type = "coredump"; elf_type = "coredump";
} else { } else {
_cleanup_(json_variant_unrefp) JsonVariant *id_json = NULL; _cleanup_(json_variant_unrefp) JsonVariant *id_json = NULL;
const char *e = executable ?: "(unnamed)";
bool interpreter_found = false; bool interpreter_found = false;
r = parse_buildid(NULL, c.elf, executable, &c, &id_json); r = parse_buildid(NULL, c.elf, e, &c, &id_json);
if (r < 0) if (r < 0)
return log_warning_errno(r, "Failed to parse build-id of ELF file: %m"); return log_warning_errno(r, "Failed to parse build-id of ELF file: %m");
r = parse_package_metadata(executable, id_json, c.elf, &interpreter_found, &c); r = parse_package_metadata(e, id_json, c.elf, &interpreter_found, &c);
if (r < 0) if (r < 0)
return log_warning_errno(r, "Failed to parse package metadata of ELF file: %m"); return log_warning_errno(r, "Failed to parse package metadata of ELF file: %m");
/* If we found a build-id and nothing else, return at least that. */ /* If we found a build-id and nothing else, return at least that. */
if (!package_metadata && id_json) { if (!package_metadata && id_json) {
r = json_build(&package_metadata, JSON_BUILD_OBJECT(JSON_BUILD_PAIR(executable, JSON_BUILD_VARIANT(id_json)))); r = json_build(&package_metadata, JSON_BUILD_OBJECT(JSON_BUILD_PAIR(e, JSON_BUILD_VARIANT(id_json))));
if (r < 0) if (r < 0)
return log_warning_errno(r, "Failed to build JSON object: %m"); return log_warning_errno(r, "Failed to build JSON object: %m");
} }
@ -640,8 +646,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
return log_warning_errno(r, "Failed to build JSON object: %m"); return log_warning_errno(r, "Failed to build JSON object: %m");
#if HAVE_DWELF_ELF_E_MACHINE_STRING #if HAVE_DWELF_ELF_E_MACHINE_STRING
elf_architecture = sym_dwelf_elf_e_machine_string(elf_header.e_machine); const char *elf_architecture = sym_dwelf_elf_e_machine_string(elf_header.e_machine);
#endif
if (elf_architecture) { if (elf_architecture) {
_cleanup_(json_variant_unrefp) JsonVariant *json_architecture = NULL; _cleanup_(json_variant_unrefp) JsonVariant *json_architecture = NULL;
@ -657,6 +662,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
if (ret) if (ret)
fprintf(c.f, "ELF object binary architecture: %s\n", elf_architecture); fprintf(c.f, "ELF object binary architecture: %s\n", elf_architecture);
} }
#endif
/* We always at least have the ELF type, so merge that (and possibly the arch). */ /* We always at least have the ELF type, so merge that (and possibly the arch). */
r = json_variant_merge(&elf_metadata, package_metadata); r = json_variant_merge(&elf_metadata, package_metadata);
@ -683,6 +689,8 @@ int parse_elf_object(int fd, const char *executable, bool fork_disable_dump, cha
_cleanup_free_ char *buf = NULL; _cleanup_free_ char *buf = NULL;
int r; int r;
assert(fd >= 0);
r = dlopen_dw(); r = dlopen_dw();
if (r < 0) if (r < 0)
return r; return r;

View File

@ -20,16 +20,13 @@
#include "util.h" #include "util.h"
static int sethostname_idempotent_full(const char *s, bool really) { static int sethostname_idempotent_full(const char *s, bool really) {
_cleanup_free_ char *buf = NULL; struct utsname u;
int r;
assert(s); assert(s);
r = gethostname_full(GET_HOSTNAME_ALLOW_NONE | GET_HOSTNAME_ALLOW_LOCALHOST, &buf); assert_se(uname(&u) >= 0);
if (r < 0)
return r;
if (streq(buf, s)) if (streq_ptr(s, u.nodename))
return 0; return 0;
if (really && if (really &&

View File

@ -1,5 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <sys/utsname.h>
#include "sd-id128.h" #include "sd-id128.h"
#include "errno-util.h" #include "errno-util.h"
@ -38,7 +40,8 @@ TEST(sysctl_normalize) {
} }
TEST(sysctl_read) { TEST(sysctl_read) {
_cleanup_free_ char *s = NULL, *h = NULL; _cleanup_free_ char *s = NULL;
struct utsname u;
sd_id128_t a, b; sd_id128_t a, b;
int r; int r;
@ -63,8 +66,8 @@ TEST(sysctl_read) {
s = mfree(s); s = mfree(s);
assert_se(sysctl_read("kernel/hostname", &s) >= 0); assert_se(sysctl_read("kernel/hostname", &s) >= 0);
assert_se(gethostname_full(GET_HOSTNAME_ALLOW_NONE|GET_HOSTNAME_ALLOW_LOCALHOST, &h) >= 0); assert_se(uname(&u) >= 0);
assert_se(streq(s, h)); assert_se(streq_ptr(s, u.nodename));
r = sysctl_write("kernel/hostname", s); r = sysctl_write("kernel/hostname", s);
assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS); assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS);