|
|
2b2a45 |
From 3ee4cabcfad3a9ccc3c59be21245b57c17e7ae75 Mon Sep 17 00:00:00 2001
|
|
|
2b2a45 |
From: Ondrej Holy <oholy@redhat.com>
|
|
|
2b2a45 |
Date: Thu, 21 Jan 2021 14:21:09 +0100
|
|
|
2b2a45 |
Subject: [PATCH 1/3] client: Fix exit codes for /help and similar option
|
|
|
2b2a45 |
|
|
|
2b2a45 |
Currently, non-zero exit code is returned for /version, /buildconfig, /help,
|
|
|
2b2a45 |
/monitor-list, /kbd-list and /kbd-lang-list command-line options for several
|
|
|
2b2a45 |
clients. This is against conventions because 0 is usually returned in
|
|
|
2b2a45 |
such cases. Also, there is potentially another problem that the returned
|
|
|
2b2a45 |
codes overflow on UNIX systems (where the exit code is a number between 0
|
|
|
2b2a45 |
and 255). Let's fix the clients to return 0 in the mentioned cases to honor
|
|
|
2b2a45 |
conventions and 1 for the command-line parsing errors (or -1 for clients
|
|
|
2b2a45 |
who already use that value).
|
|
|
2b2a45 |
|
|
|
2b2a45 |
Fixes: https://github.com/FreeRDP/FreeRDP/issues/6686
|
|
|
2b2a45 |
---
|
|
|
2b2a45 |
client/Sample/tf_freerdp.c | 9 +++++----
|
|
|
2b2a45 |
client/Wayland/wlfreerdp.c | 13 +++++++------
|
|
|
2b2a45 |
client/Windows/cli/wfreerdp.c | 4 ++++
|
|
|
2b2a45 |
client/X11/cli/xfreerdp.c | 22 +++++++++++++---------
|
|
|
2b2a45 |
winpr/include/winpr/cmdline.h | 1 +
|
|
|
2b2a45 |
5 files changed, 30 insertions(+), 19 deletions(-)
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/Sample/tf_freerdp.c b/client/Sample/tf_freerdp.c
|
|
|
2b2a45 |
index 3ba82c78338..49412cb417c 100644
|
|
|
2b2a45 |
--- a/client/Sample/tf_freerdp.c
|
|
|
2b2a45 |
+++ b/client/Sample/tf_freerdp.c
|
|
|
2b2a45 |
@@ -338,12 +338,13 @@ int main(int argc, char* argv[])
|
|
|
2b2a45 |
goto fail;
|
|
|
2b2a45 |
|
|
|
2b2a45 |
status = freerdp_client_settings_parse_command_line(context->settings, argc, argv, FALSE);
|
|
|
2b2a45 |
- status =
|
|
|
2b2a45 |
- freerdp_client_settings_command_line_status_print(context->settings, status, argc, argv);
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
if (status)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
- rc = 0;
|
|
|
2b2a45 |
+ freerdp_client_settings_command_line_status_print(context->settings, status, argc, argv);
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
+ if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
+ rc = 0;
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
goto fail;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c
|
|
|
2b2a45 |
index 329d1200941..d77b47986ea 100644
|
|
|
2b2a45 |
--- a/client/Wayland/wlfreerdp.c
|
|
|
2b2a45 |
+++ b/client/Wayland/wlfreerdp.c
|
|
|
2b2a45 |
@@ -628,18 +628,19 @@ int main(int argc, char* argv[])
|
|
|
2b2a45 |
settings = context->settings;
|
|
|
2b2a45 |
|
|
|
2b2a45 |
status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
|
|
|
2b2a45 |
- status = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
if (status)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
BOOL list = settings->ListMonitors;
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
+ freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
if (list)
|
|
|
2b2a45 |
wlf_list_monitors(wlc);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- freerdp_client_context_free(context);
|
|
|
2b2a45 |
- if (list)
|
|
|
2b2a45 |
- return 0;
|
|
|
2b2a45 |
- return status;
|
|
|
2b2a45 |
+ if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
+ rc = 0;
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
+ goto fail;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
if (freerdp_client_start(context) != 0)
|
|
|
2b2a45 |
diff --git a/client/Windows/cli/wfreerdp.c b/client/Windows/cli/wfreerdp.c
|
|
|
2b2a45 |
index 7a76eeb9b59..b623067e98e 100644
|
|
|
2b2a45 |
--- a/client/Windows/cli/wfreerdp.c
|
|
|
2b2a45 |
+++ b/client/Windows/cli/wfreerdp.c
|
|
|
2b2a45 |
@@ -108,6 +108,10 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|
|
2b2a45 |
if (status)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
+ if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
+ rc = 0;
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/X11/cli/xfreerdp.c b/client/X11/cli/xfreerdp.c
|
|
|
2b2a45 |
index c8a77f335f4..a3505b24d3c 100644
|
|
|
2b2a45 |
--- a/client/X11/cli/xfreerdp.c
|
|
|
2b2a45 |
+++ b/client/X11/cli/xfreerdp.c
|
|
|
2b2a45 |
@@ -34,6 +34,7 @@
|
|
|
2b2a45 |
|
|
|
2b2a45 |
int main(int argc, char* argv[])
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
+ int rc = 1;
|
|
|
2b2a45 |
int status;
|
|
|
2b2a45 |
HANDLE thread;
|
|
|
2b2a45 |
xfContext* xfc;
|
|
|
2b2a45 |
@@ -56,31 +57,34 @@ int main(int argc, char* argv[])
|
|
|
2b2a45 |
xfc = (xfContext*)context;
|
|
|
2b2a45 |
|
|
|
2b2a45 |
status = freerdp_client_settings_parse_command_line(context->settings, argc, argv, FALSE);
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
- status = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
if (status)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
BOOL list = settings->ListMonitors;
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
+ freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
if (list)
|
|
|
2b2a45 |
xf_list_monitors(xfc);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- freerdp_client_context_free(context);
|
|
|
2b2a45 |
- if (list)
|
|
|
2b2a45 |
- return 0;
|
|
|
2b2a45 |
- return status;
|
|
|
2b2a45 |
+ if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
+ rc = 0;
|
|
|
2b2a45 |
+
|
|
|
2b2a45 |
+ goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- freerdp_client_start(context);
|
|
|
2b2a45 |
+ if (freerdp_client_start(context) != 0)
|
|
|
2b2a45 |
+ goto out;
|
|
|
2b2a45 |
|
|
|
2b2a45 |
thread = freerdp_client_get_thread(context);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
WaitForSingleObject(thread, INFINITE);
|
|
|
2b2a45 |
GetExitCodeThread(thread, &dwExitCode);
|
|
|
2b2a45 |
+ rc = xf_exit_code_from_disconnect_reason(dwExitCode);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
freerdp_client_stop(context);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
+out:
|
|
|
2b2a45 |
freerdp_client_context_free(context);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- return xf_exit_code_from_disconnect_reason(dwExitCode);
|
|
|
2b2a45 |
+ return rc;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
diff --git a/winpr/include/winpr/cmdline.h b/winpr/include/winpr/cmdline.h
|
|
|
2b2a45 |
index 865ee8f25c7..9276cda8eb1 100644
|
|
|
2b2a45 |
--- a/winpr/include/winpr/cmdline.h
|
|
|
2b2a45 |
+++ b/winpr/include/winpr/cmdline.h
|
|
|
2b2a45 |
@@ -81,6 +81,7 @@
|
|
|
2b2a45 |
#define COMMAND_LINE_STATUS_PRINT_HELP -2002
|
|
|
2b2a45 |
#define COMMAND_LINE_STATUS_PRINT_VERSION -2003
|
|
|
2b2a45 |
#define COMMAND_LINE_STATUS_PRINT_BUILDCONFIG -2004
|
|
|
2b2a45 |
+#define COMMAND_LINE_STATUS_PRINT_LAST -2999
|
|
|
2b2a45 |
|
|
|
2b2a45 |
/* Command-Line Macros */
|
|
|
2b2a45 |
|
|
|
2b2a45 |
|
|
|
2b2a45 |
From 531dd81836f2c97fcfcfeabdb9671fb76409ce8d Mon Sep 17 00:00:00 2001
|
|
|
2b2a45 |
From: akallabeth <akallabeth@posteo.net>
|
|
|
2b2a45 |
Date: Fri, 22 Jan 2021 08:40:03 +0100
|
|
|
2b2a45 |
Subject: [PATCH 2/3] Refactored
|
|
|
2b2a45 |
freerdp_client_settings_command_line_status_print_ex
|
|
|
2b2a45 |
|
|
|
2b2a45 |
Now returns 0 if help or version information was requested.
|
|
|
2b2a45 |
---
|
|
|
2b2a45 |
client/Sample/tf_freerdp.c | 7 ++-----
|
|
|
2b2a45 |
client/Wayland/wlfreerdp.c | 5 +----
|
|
|
2b2a45 |
client/Windows/cli/wfreerdp.c | 6 +-----
|
|
|
2b2a45 |
client/X11/cli/xfreerdp.c | 5 +----
|
|
|
2b2a45 |
client/common/cmdline.c | 14 +++++++++-----
|
|
|
2b2a45 |
5 files changed, 14 insertions(+), 23 deletions(-)
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/Sample/tf_freerdp.c b/client/Sample/tf_freerdp.c
|
|
|
2b2a45 |
index 49412cb417c..e9b9fe8397e 100644
|
|
|
2b2a45 |
--- a/client/Sample/tf_freerdp.c
|
|
|
2b2a45 |
+++ b/client/Sample/tf_freerdp.c
|
|
|
2b2a45 |
@@ -340,11 +340,8 @@ int main(int argc, char* argv[])
|
|
|
2b2a45 |
status = freerdp_client_settings_parse_command_line(context->settings, argc, argv, FALSE);
|
|
|
2b2a45 |
if (status)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
- freerdp_client_settings_command_line_status_print(context->settings, status, argc, argv);
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
- if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
- rc = 0;
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
+ rc = freerdp_client_settings_command_line_status_print(context->settings, status, argc,
|
|
|
2b2a45 |
+ argv);
|
|
|
2b2a45 |
goto fail;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c
|
|
|
2b2a45 |
index d77b47986ea..4a583068968 100644
|
|
|
2b2a45 |
--- a/client/Wayland/wlfreerdp.c
|
|
|
2b2a45 |
+++ b/client/Wayland/wlfreerdp.c
|
|
|
2b2a45 |
@@ -632,14 +632,11 @@ int main(int argc, char* argv[])
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
BOOL list = settings->ListMonitors;
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
+ rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
if (list)
|
|
|
2b2a45 |
wlf_list_monitors(wlc);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
- rc = 0;
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
goto fail;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/Windows/cli/wfreerdp.c b/client/Windows/cli/wfreerdp.c
|
|
|
2b2a45 |
index b623067e98e..e325f84771f 100644
|
|
|
2b2a45 |
--- a/client/Windows/cli/wfreerdp.c
|
|
|
2b2a45 |
+++ b/client/Windows/cli/wfreerdp.c
|
|
|
2b2a45 |
@@ -107,11 +107,7 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|
|
2b2a45 |
|
|
|
2b2a45 |
if (status)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
- freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
- if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
- rc = 0;
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
+ ret = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/X11/cli/xfreerdp.c b/client/X11/cli/xfreerdp.c
|
|
|
2b2a45 |
index a3505b24d3c..5b702194448 100644
|
|
|
2b2a45 |
--- a/client/X11/cli/xfreerdp.c
|
|
|
2b2a45 |
+++ b/client/X11/cli/xfreerdp.c
|
|
|
2b2a45 |
@@ -61,14 +61,11 @@ int main(int argc, char* argv[])
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
BOOL list = settings->ListMonitors;
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
+ rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
if (list)
|
|
|
2b2a45 |
xf_list_monitors(xfc);
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
- rc = 0;
|
|
|
2b2a45 |
-
|
|
|
2b2a45 |
goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/common/cmdline.c b/client/common/cmdline.c
|
|
|
2b2a45 |
index ed467afb7d0..dc8367b7cd2 100644
|
|
|
2b2a45 |
--- a/client/common/cmdline.c
|
|
|
2b2a45 |
+++ b/client/common/cmdline.c
|
|
|
2b2a45 |
@@ -1403,14 +1403,14 @@ int freerdp_client_settings_command_line_status_print_ex(rdpSettings* settings,
|
|
|
2b2a45 |
if (status == COMMAND_LINE_STATUS_PRINT_VERSION)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
freerdp_client_print_version();
|
|
|
2b2a45 |
- return COMMAND_LINE_STATUS_PRINT_VERSION;
|
|
|
2b2a45 |
+ goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
if (status == COMMAND_LINE_STATUS_PRINT_BUILDCONFIG)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
freerdp_client_print_version();
|
|
|
2b2a45 |
freerdp_client_print_buildconfig();
|
|
|
2b2a45 |
- return COMMAND_LINE_STATUS_PRINT_BUILDCONFIG;
|
|
|
2b2a45 |
+ goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
else if (status == COMMAND_LINE_STATUS_PRINT)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
@@ -1465,15 +1465,19 @@ int freerdp_client_settings_command_line_status_print_ex(rdpSettings* settings,
|
|
|
2b2a45 |
settings->ListMonitors = TRUE;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- return COMMAND_LINE_STATUS_PRINT;
|
|
|
2b2a45 |
+ goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
else if (status < 0)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
freerdp_client_print_command_line_help_ex(argc, argv, custom);
|
|
|
2b2a45 |
- return COMMAND_LINE_STATUS_PRINT_HELP;
|
|
|
2b2a45 |
+ status = COMMAND_LINE_STATUS_PRINT_HELP;
|
|
|
2b2a45 |
+ goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
- return 0;
|
|
|
2b2a45 |
+out:
|
|
|
2b2a45 |
+ if (status <= COMMAND_LINE_STATUS_PRINT && status >= COMMAND_LINE_STATUS_PRINT_LAST)
|
|
|
2b2a45 |
+ return 0;
|
|
|
2b2a45 |
+ return status;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|
|
|
2b2a45 |
static BOOL ends_with(const char* str, const char* ext)
|
|
|
2b2a45 |
|
|
|
2b2a45 |
From 050a68fec901030c7428852f8f536ace055eb2f7 Mon Sep 17 00:00:00 2001
|
|
|
2b2a45 |
From: akallabeth <akallabeth@posteo.net>
|
|
|
2b2a45 |
Date: Fri, 22 Jan 2021 09:32:51 +0100
|
|
|
2b2a45 |
Subject: [PATCH 3/3] Do not eliminate original error status.
|
|
|
2b2a45 |
|
|
|
2b2a45 |
---
|
|
|
2b2a45 |
client/common/cmdline.c | 1 -
|
|
|
2b2a45 |
1 file changed, 1 deletion(-)
|
|
|
2b2a45 |
|
|
|
2b2a45 |
diff --git a/client/common/cmdline.c b/client/common/cmdline.c
|
|
|
2b2a45 |
index dc8367b7cd2..66d3c4fffef 100644
|
|
|
2b2a45 |
--- a/client/common/cmdline.c
|
|
|
2b2a45 |
+++ b/client/common/cmdline.c
|
|
|
2b2a45 |
@@ -1470,7 +1470,6 @@ int freerdp_client_settings_command_line_status_print_ex(rdpSettings* settings,
|
|
|
2b2a45 |
else if (status < 0)
|
|
|
2b2a45 |
{
|
|
|
2b2a45 |
freerdp_client_print_command_line_help_ex(argc, argv, custom);
|
|
|
2b2a45 |
- status = COMMAND_LINE_STATUS_PRINT_HELP;
|
|
|
2b2a45 |
goto out;
|
|
|
2b2a45 |
}
|
|
|
2b2a45 |
|