From 633e3a5eae29c5074ada2655caac74902df1acc0 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 2 Mar 2021 11:54:14 +0000 Subject: ash: correctly identify applet in getopt() error messages With the default configuration most applets are run from the shell via run_noexec_applet_and_exit(). If the applet runs getopt() and an error is detected the message takes the form: sh: unknown option -- q This happens because mingw-w64's implementation of getopt() uses the global variable __argv[0] as the name of the program. Avoid the misleading message by setting __argv[0] as appropriate. --- shell/ash.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 8cc7a5c75..3d6f25802 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -8689,6 +8689,8 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) const char *cmd, char **argv, c struct forkshell *fs = (struct forkshell *)sticky_mem_start; if (applet_main[applet_no] != ash_main || (fs && fs->fpid == FS_SHELLEXEC)) { + /* mingw-w64's getopt() uses __argv[0] as the program name */ + __argv[0] = (char *)cmd; # else if (APPLET_IS_NOEXEC(applet_no)) { # endif -- cgit v1.2.3-55-g6feb