]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Fix error reporting in main() and friends
authorDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Thu, 30 Dec 2021 23:19:47 +0000 (00:19 +0100)
committerDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sat, 26 Feb 2022 15:43:17 +0000 (16:43 +0100)
- 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

diff --git a/main.c b/main.c
index f0b89daeb90047c53caca77f31768bf503be6c38..a35f151204f58f6a9e109a788ec83e9c4bf39a46 100644 (file)
--- 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) {