Skip to content

Commit d8bbf98

Browse files
committed
Use in priority /usr/bin/uname to determine the ABI
/usr/bin/uname is always rebuilt on freebsd meaning always up to date regarding OSVERSION, in case this binary does not exists, fallback on /bin/sh as before
1 parent 003a77a commit d8bbf98

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

libpkg/pkg_elf.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#define NT_ABI_TAG 1
7272
#endif
7373

74+
#define _PATH_UNAME "/usr/bin/uname"
75+
7476
/* FFR: when we support installing a 32bit package on a 64bit host */
7577
#define _PATH_ELF32_HINTS "/var/run/ld-elf32.so.hints"
7678

@@ -716,32 +718,41 @@ pkg_get_myarch_elfparse(char *dest, size_t sz, int *osversion)
716718
Elf_Data *data;
717719
Elf_Note note;
718720
Elf_Scn *scn = NULL;
719-
int fd;
721+
int fd, i;
720722
int version_style = 1;
721723
char *src = NULL;
722724
char *osname;
723725
uint32_t version = 0;
724726
int ret = EPKG_OK;
725727
const char *arch, *abi, *endian_corres_str, *wordsize_corres_str, *fpu;
726-
const char *path;
727728
char invalid_osname[] = "Unknown";
728729
char *note_os[6] = {"Linux", "GNU", "Solaris", "FreeBSD", "NetBSD", "Syllable"};
729730
char *(*pnote_os)[6] = &note_os;
730731
uint32_t gnu_abi_tag[4];
731732

732-
path = getenv("ABI_FILE");
733-
if (path == NULL)
734-
path = _PATH_BSHELL;
733+
const char *abi_files[] = {
734+
getenv("ABI_FILE"),
735+
_PATH_UNAME,
736+
_PATH_BSHELL,
737+
};
735738

736739
if (elf_version(EV_CURRENT) == EV_NONE) {
737740
pkg_emit_error("ELF library initialization failed: %s",
738741
elf_errmsg(-1));
739742
return (EPKG_FATAL);
740743
}
741744

742-
if ((fd = open(path, O_RDONLY)) < 0) {
743-
pkg_emit_errno("open", _PATH_BSHELL);
744-
snprintf(dest, sz, "%s", "unknown");
745+
for (fd = -1, i = 0; i < nitems(abi_files); i++) {
746+
if (abi_files[i] == NULL)
747+
continue;
748+
if ((fd = open(abi_files[i], O_RDONLY)) >= 0)
749+
break;
750+
/* if the ABI_FILE was provided we only care about it */
751+
if (i == 0)
752+
break;
753+
}
754+
if (fd == -1) {
755+
pkg_emit_error("Unable to determine the ABI\n");
745756
return (EPKG_FATAL);
746757
}
747758

0 commit comments

Comments
 (0)