Windows 10 and 11 introduce the timeout.exe command. This is a similar program with same argument options
-- v4: timeout: Windows 10 introduce the timeout command
From: Michele Dionisio michele.dionisio@powersoft.com
--- configure.ac | 1 + programs/timeout/Makefile.in | 8 ++ programs/timeout/main.c | 147 +++++++++++++++++++++++++++++++++++ programs/timeout/timeout.h | 28 +++++++ programs/timeout/timeout.rc | 33 ++++++++ 5 files changed, 217 insertions(+) create mode 100644 programs/timeout/Makefile.in create mode 100644 programs/timeout/main.c create mode 100644 programs/timeout/timeout.h create mode 100644 programs/timeout/timeout.rc
diff --git a/configure.ac b/configure.ac index 3f8be71bd21..0f2bfd93b9b 100644 --- a/configure.ac +++ b/configure.ac @@ -3514,6 +3514,7 @@ WINE_CONFIG_MAKEFILE(programs/tasklist) WINE_CONFIG_MAKEFILE(programs/tasklist/tests) WINE_CONFIG_MAKEFILE(programs/taskmgr) WINE_CONFIG_MAKEFILE(programs/termsv) +WINE_CONFIG_MAKEFILE(programs/timeout) WINE_CONFIG_MAKEFILE(programs/uninstaller) WINE_CONFIG_MAKEFILE(programs/unlodctr) WINE_CONFIG_MAKEFILE(programs/view) diff --git a/programs/timeout/Makefile.in b/programs/timeout/Makefile.in new file mode 100644 index 00000000000..708cca355ff --- /dev/null +++ b/programs/timeout/Makefile.in @@ -0,0 +1,8 @@ +MODULE = timeout.exe +IMPORTS = user32 + +EXTRADLLFLAGS = -mconsole -municode + +SOURCES = \ + timeout.rc \ + main.c diff --git a/programs/timeout/main.c b/programs/timeout/main.c new file mode 100644 index 00000000000..c79c247c150 --- /dev/null +++ b/programs/timeout/main.c @@ -0,0 +1,147 @@ +/* + * Copyright 2024 Michele Dionisio michele.dionisio@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <windows.h> +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <synchapi.h> +#include <stdbool.h> +#include <wchar.h> +#include <conio.h> +#include "timeout.h" + +static int WINAPIV timeout_error_wprintf(int msg, ...) +{ + WCHAR msg_buffer[MAXSTRING]; + va_list va_args; + int ret; + + LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer)); + va_start(va_args, msg); + ret = vfwprintf(stderr, msg_buffer, va_args); + va_end(va_args); + return ret; +} + +static int WINAPIV timeout_message(int msg) +{ + WCHAR msg_buffer[MAXSTRING]; + + LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer)); + return fwprintf(stdout, msg_buffer); +} + +static int WINAPIV timeout_wprintf(int msg, ...) +{ + WCHAR msg_buffer[MAXSTRING]; + va_list va_args; + int ret; + + LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer)); + va_start(va_args, msg); + ret = vfwprintf(stdout, msg_buffer, va_args); + va_end(va_args); + return ret; +} + +static volatile bool stop = false; + +static BOOL WINAPI ctrl_c_handler(DWORD dwCtrlType) +{ + if (dwCtrlType == CTRL_C_EVENT) + { + stop = true; + return TRUE; + } + return FALSE; +} + +int __cdecl wmain(int argc, WCHAR *argv[]) +{ + int ret = 1; + int wait_time = 0; + int wait_time_valid = 0; + int nobreak = 0; + + if (argc <= 1) + { + timeout_error_wprintf(STRING_BAD_COMMAND_LINE); + return 2; + } + + for (int i = 1; i < argc; i++) + { + if (wcscmp(argv[i], L"/?") == 0) + { + timeout_message(STRING_USAGE); + ret = 0; + goto done; + } + else if (wcsicmp(argv[i], L"/t") == 0) + { + if ((i + 1) < argc) + { + i++; + wait_time = _wtoi(argv[i]); + wait_time_valid = 1; + } + else + { + timeout_error_wprintf(STRING_BAD_COMMAND_LINE); + return 2; + } + } + else if (wcsicmp(argv[i], L"/nobreak") == 0) + { + nobreak = 1; + } + else + { + timeout_error_wprintf(STRING_BAD_COMMAND_LINE); + return 2; + } + } + + if (wait_time_valid == 0) + { + timeout_error_wprintf(STRING_BAD_COMMAND_LINE); + return 2; + } + + SetConsoleCtrlHandler(ctrl_c_handler, TRUE); + + for (int i = 0; (wait_time < 0) || (i < wait_time); i++) + { + timeout_wprintf(STRING_WAITING_SINCE, i); + timeout_message((nobreak == 0) ? STRING_PRESS_KEY : STRING_PRESS_CRTLC); + if (stop) + { + break; + } + if ((nobreak == 0) && _kbhit()) + { + break; + } + Sleep(1000); + } + timeout_message(STRING_END); + +done: + return ret; +} diff --git a/programs/timeout/timeout.h b/programs/timeout/timeout.h new file mode 100644 index 00000000000..e25295b6c21 --- /dev/null +++ b/programs/timeout/timeout.h @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Michele Dionisio michele.dionisio@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <windef.h> + +#define MAXSTRING 8192 + +#define STRING_USAGE 101 +#define STRING_BAD_COMMAND_LINE 102 +#define STRING_WAITING_SINCE 103 +#define STRING_PRESS_CRTLC 104 +#define STRING_PRESS_KEY 105 +#define STRING_END 106 diff --git a/programs/timeout/timeout.rc b/programs/timeout/timeout.rc new file mode 100644 index 00000000000..0689374440c --- /dev/null +++ b/programs/timeout/timeout.rc @@ -0,0 +1,33 @@ +/* + * Copyright 2024 Michele Dionisio michele.dionisio@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "timeout.h" + +#pragma makedep po + +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT + +STRINGTABLE +{ + STRING_USAGE, "Usage: timeout /T <timeout> [</NOBREAK>]\n" + STRING_BAD_COMMAND_LINE, "TIMEOUT: Bad command line\n" + STRING_WAITING_SINCE, "waiting since %d sec. " + STRING_PRESS_CRTLC, "press CTRL+C...\r" + STRING_PRESS_KEY, "press a key to continue...\r" + STRING_END, "\n" +}
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=149828
Your paranoid android.
=== debian11b (64 bit WoW report) ===
user32: win.c:4070: Test failed: Expected active window 00000000067C0158, got 0000000000000000. win.c:4071: Test failed: Expected focus window 00000000067C0158, got 0000000000000000.
On Thu Nov 21 10:50:58 2024 +0000, Michele Dionisio wrote:
changed this line in [version 4 of the diff](/wine/wine/-/merge_requests/6869/diffs?diff_id=144435&start_sha=1c326ace6fa9e6d1670472aaf4128b558052e215#87db583be5c13c1f7b3c958b10e03d67b6a2ca06_3551_3552)
done
eric pouech (@epo) commented about programs/timeout/main.c:
- int wait_time_valid = 0;
- int nobreak = 0;
- if (argc <= 1)
- {
timeout_error_wprintf(STRING_BAD_COMMAND_LINE);
return 2;
- }
- for (int i = 1; i < argc; i++)
- {
if (wcscmp(argv[i], L"/?") == 0)
{
timeout_message(STRING_USAGE);
ret = 0;
goto done;
you can simply return 0; and remove the label
eric pouech (@epo) commented about programs/timeout/main.c:
- }
- for (int i = 1; i < argc; i++)
- {
if (wcscmp(argv[i], L"/?") == 0)
{
timeout_message(STRING_USAGE);
ret = 0;
goto done;
}
else if (wcsicmp(argv[i], L"/t") == 0)
{
if ((i + 1) < argc)
{
i++;
wait_time = _wtoi(argv[i]);
two nitpicks here:
* native fails with "/T 10foobar" * valid values for /T arg range from -1 to 99999
eric pouech (@epo) commented about programs/timeout/timeout.rc:
+#include "timeout.h"
+#pragma makedep po
+LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
+STRINGTABLE +{
- STRING_USAGE, "Usage: timeout /T <timeout> [</NOBREAK>]\n"
- STRING_BAD_COMMAND_LINE, "TIMEOUT: Bad command line\n"
- STRING_WAITING_SINCE, "waiting since %d sec. "
- STRING_PRESS_CRTLC, "press CTRL+C...\r"
- STRING_PRESS_KEY, "press a key to continue...\r"
- STRING_END, "\n"
+}
STRING_END looks rather useless to me (doesn't require translation)
eric pouech (@epo) commented about programs/timeout/main.c:
timeout_message((nobreak == 0) ? STRING_PRESS_KEY : STRING_PRESS_CRTLC);
if (stop)
{
break;
}
if ((nobreak == 0) && _kbhit())
{
break;
}
Sleep(1000);
- }
- timeout_message(STRING_END);
+done:
- return ret;
+}
a quick test under windows 10 doesn't seem to match the return values
I get 0 for a normal run (or termination by any key except ctrl-c)
1 for command line syntax error, and ctrl-c being hit in /nobreak mode
and STATUS_CTRL_C_EXIT when ctrl-c being hit without /nobreak mode