From a2636e5e11d50a1629b9391ee95bc212e00c67bc Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Fri, 31 Dec 2021 00:19:47 +0100 Subject: [PATCH] Fix error reporting in main() and friends - Use POSIX error handling (errno and strerror()) for standard C and POSIX functions, including in Windows-only code. - Add standard error messages with strerror() whenever possible. They are standard and easily recognisable by end-users. - Add missing _() when neeeded. - Remove extra "\n" from vpn_perror() call. Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> --- main.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index f0b89dae..a35f1512 100644 --- a/main.c +++ b/main.c @@ -463,9 +463,7 @@ static void read_stdin(char **string, int hidden, int allow_fail) } else { /* Not a console; maybe reading from a piped stdin? */ if (!fgetws(wbuf, ARRAY_SIZE(wbuf), stdin)) { - char *errstr = openconnect__win32_strerror(GetLastError()); - fprintf(stderr, _("fgetws (stdin): %s\n"), errstr); - free(errstr); + perror(_("fgetws (stdin)")); *string = NULL; return; } @@ -491,7 +489,7 @@ static void read_stdin(char **string, int hidden, int allow_fail) } buf = malloc(nr_read); if (!buf) { - fprintf(stderr, _("Allocation failure for string from stdin\n")); + perror(_("Allocation failure for string from stdin")); exit(1); } @@ -1599,7 +1597,7 @@ static int background_self(struct openconnect_info *vpninfo, char *pidfile) } pid = fork(); if (pid == -1) { - vpn_perror(vpninfo, "Failed to continue in background\n"); + vpn_perror(vpninfo, _("Failed to continue in background")); exit(1); } else if (pid > 0) { if (fp) { -- 2.50.1