From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Thu, 30 Dec 2021 23:19:47 +0000 (+0100) Subject: Fix error reporting in main() and friends X-Git-Tag: v9.00~45^2^2~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a2636e5e11d50a1629b9391ee95bc212e00c67bc;p=users%2Fdwmw2%2Fopenconnect.git 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> --- 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) {