This has come up a few times in the past, and I agree the right solution is "don't use them", but popular GNU/Linux distros have carried patches in the past (similar to the attached) and people have gotten used to them producing *something*, and things broke when the patches got dropped. Canonicalizing "it's just -m" might help people switch, too.
I am also contemplating an extension to glibc's confstr() that can return something more specific than "uname -m" that might be more useful but less compatible than past behavior, but I don't know if it would make the portability situation better or worse ;-) The patch only falls back to -m if the user explicitly asked for -p or -i, it does not affect -a/-A. It also does not complain if uname() fails. commit 396b58967e57b564bc37eed3ae4901c095967758 Author: DJ Delorie <[email protected]> Date: Wed Nov 11 14:18:08 2026 -0500 uname: fallbacks for -p and -i Neither -p nor -i are portable, but there should at least be a fallback for systems that don't have anything more specific than utsname.machine. If the user has explicitly requested -p or -i, and no other mechanism is available to obtain such information, fall back to utsname.machine. diff --git a/src/uname.c b/src/uname.c index d41dabe49..dbc694bb7 100644 --- a/src/uname.c +++ b/src/uname.c @@ -311,6 +311,7 @@ int main (int argc, char **argv) { static char const unknown[] = "unknown"; + struct utsname name; /* Mask indicating which elements to print. */ unsigned int toprint = 0; @@ -332,8 +333,6 @@ main (int argc, char **argv) & (PRINT_KERNEL_NAME | PRINT_NODENAME | PRINT_KERNEL_RELEASE | PRINT_KERNEL_VERSION | PRINT_MACHINE)) { - struct utsname name; - if (uname (&name) == -1) error (EXIT_FAILURE, errno, _("cannot get system name")); @@ -379,6 +378,12 @@ main (int argc, char **argv) element = processor; } #endif + if (element == unknown && toprint != UINT_MAX) + { + /* If all else fails, try the -m value. */ + if (uname (&name) != -1) + element = name.machine; + } if (! (toprint == UINT_MAX && element == unknown)) print_element (element, _("Processor")); } @@ -404,6 +409,12 @@ main (int argc, char **argv) element = hardware_platform; } #endif + if (element == unknown && toprint != UINT_MAX) + { + /* If all else fails, try the -m value. */ + if (uname (&name) != -1) + element = name.machine; + } if (! (toprint == UINT_MAX && element == unknown)) print_element (element, _("Hardware platform")); }
