]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
No need to cache errno before _()
authorDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sat, 1 Jan 2022 16:07:29 +0000 (17:07 +0100)
committerDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sat, 26 Feb 2022 15:43:17 +0000 (16:43 +0100)
Indeed _() is an alias of dgettext(), and the  dgettext(3) man page
is clear about that:
errno is not modified

Consistently use err as the cache name when caching errno is needed.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
auth.c
esp.c
gnutls.c
main.c
mainloop.c
script.c
tun.c

diff --git a/auth.c b/auth.c
index ad07b2a55e89e879ba806ade81656fc00b99c662..204eece95599ce3203919fcd1253b7da1fb8b5c5 100644 (file)
--- a/auth.c
+++ b/auth.c
@@ -1052,41 +1052,41 @@ int set_csd_user(struct openconnect_info *vpninfo)
 
        if (vpninfo->uid_csd_given && vpninfo->uid_csd != getuid()) {
                struct passwd *pw;
-               int e;
+               int err;
 
                if (setgid(vpninfo->gid_csd)) {
-                       e = errno;
+                       err = errno;
                        fprintf(stderr, _("Failed to set gid %ld: %s\n"),
-                               (long)vpninfo->uid_csd, strerror(e));
-                       return -e;
+                               (long)vpninfo->uid_csd, strerror(err));
+                       return -err;
                }
 
                if (setgroups(1, &vpninfo->gid_csd)) {
-                       e = errno;
+                       err = errno;
                        fprintf(stderr, _("Failed to set groups to %ld: %s\n"),
-                               (long)vpninfo->uid_csd, strerror(e));
-                       return -e;
+                               (long)vpninfo->uid_csd, strerror(err));
+                       return -err;
                }
 
                if (setuid(vpninfo->uid_csd)) {
-                       e = errno;
+                       err = errno;
                        fprintf(stderr, _("Failed to set uid %ld: %s\n"),
-                               (long)vpninfo->uid_csd, strerror(e));
-                       return -e;
+                               (long)vpninfo->uid_csd, strerror(err));
+                       return -err;
                }
 
                if (!(pw = getpwuid(vpninfo->uid_csd))) {
-                       e = errno;
+                       err = errno;
                        fprintf(stderr, _("Invalid user uid=%ld: %s\n"),
-                               (long)vpninfo->uid_csd, strerror(e));
-                       return -e;
+                               (long)vpninfo->uid_csd, strerror(err));
+                       return -err;
                }
                setenv("HOME", pw->pw_dir, 1);
                if (chdir(pw->pw_dir)) {
-                       e = errno;
+                       err = errno;
                        fprintf(stderr, _("Failed to change to CSD home directory '%s': %s\n"),
-                               pw->pw_dir, strerror(e));
-                       return -e;
+                               pw->pw_dir, strerror(err));
+                       return -err;
                }
        }
        return 0;
diff --git a/esp.c b/esp.c
index d607a4e0df8bc4c707baee13dd0cea3c1abc930f..67f1608efefcf89eed5158df4609a249dfb85568 100644 (file)
--- a/esp.c
+++ b/esp.c
@@ -367,12 +367,11 @@ int esp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable)
                if (ret < 0) {
                        /* Not that this is likely to happen with UDP, but... */
                        if (errno == ENOBUFS || errno == EAGAIN || errno == EWOULDBLOCK) {
-                               int err = errno;
                                vpninfo->deflate_pkt = this;
                                this->len = len;
                                vpn_progress(vpninfo, PRG_DEBUG,
                                             _("Requeueing failed ESP send: %s\n"),
-                                            strerror(err));
+                                            strerror(errno));
                                monitor_write_fd(vpninfo, dtls);
                                return work_done;
                        } else {
index 91b95f3373fc5292b359fa187000a2927cd3dcc2..1baa529a25706f4391f2688f19696ee5afa5d488 100644 (file)
--- a/gnutls.c
+++ b/gnutls.c
@@ -408,7 +408,7 @@ static int load_datum(struct openconnect_info *vpninfo,
                      gnutls_datum_t *datum, const char *fname)
 {
        struct stat st;
-       int fd, err;
+       int fd;
 
 #ifdef ANDROID_KEYSTORE
        if (!strncmp(fname, "keystore:", 9)) {
@@ -435,17 +435,15 @@ static int load_datum(struct openconnect_info *vpninfo,
 
        fd = openconnect_open_utf8(vpninfo, fname, O_RDONLY|O_CLOEXEC|O_BINARY);
        if (fd == -1) {
-               err = errno;
                vpn_progress(vpninfo, PRG_ERR,
                             _("Failed to open key/certificate file %s: %s\n"),
-                            fname, strerror(err));
+                            fname, strerror(errno));
                return -ENOENT;
        }
        if (fstat(fd, &st)) {
-               err = errno;
                vpn_progress(vpninfo, PRG_ERR,
                             _("Failed to stat key/certificate file %s: %s\n"),
-                            fname, strerror(err));
+                            fname, strerror(errno));
                close(fd);
                return -EIO;
        }
@@ -459,10 +457,9 @@ static int load_datum(struct openconnect_info *vpninfo,
        }
        errno = EAGAIN;
        if (read(fd, datum->data, datum->size) != datum->size) {
-               err = errno;
                vpn_progress(vpninfo, PRG_ERR,
                             _("Failed to read certificate into memory: %s\n"),
-                            strerror(err));
+                            strerror(errno));
                close(fd);
                gnutls_free(datum->data);
                return -EIO;
diff --git a/main.c b/main.c
index a35f151204f58f6a9e109a788ec83e9c4bf39a46..ff708aa3d33ba9ced400a5c49fc016ff5c7c2581 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1193,15 +1193,13 @@ static void get_uids(const char *config_arg, uid_t *uid, gid_t *gid)
 {
        char *strend;
        struct passwd *pw;
-       int e;
 
        *uid = strtol(config_arg, &strend, 0);
        if (strend[0]) {
                pw = getpwnam(config_arg);
                if (!pw) {
-                       e = errno;
                        fprintf(stderr, _("Invalid user \"%s\": %s\n"),
-                               config_arg, strerror(e));
+                               config_arg, strerror(errno));
                        exit(1);
                }
                *uid = pw->pw_uid;
@@ -1209,9 +1207,8 @@ static void get_uids(const char *config_arg, uid_t *uid, gid_t *gid)
        } else {
                pw = getpwuid(*uid);
                if (!pw) {
-                       e = errno;
                        fprintf(stderr, _("Invalid user ID \"%d\": %s\n"),
-                               (int)*uid, strerror(e));
+                               (int)*uid, strerror(errno));
                        exit(1);
                }
                *gid = pw->pw_gid;
index 74f0f98c5b7b388733c810fc8ebb979acbab5868..08bb4ece648aab22cd514aa91ec4c566e8756a94 100644 (file)
@@ -133,26 +133,21 @@ static int setup_tun_device(struct openconnect_info *vpninfo)
 
 #if !defined(_WIN32) && !defined(__native_client__)
        if (vpninfo->uid != getuid()) {
-               int e;
-
                if (setgid(vpninfo->gid)) {
-                       e = errno;
                        vpn_progress(vpninfo, PRG_ERR, _("Failed to set gid %ld: %s\n"),
-                                    (long)vpninfo->gid, strerror(e));
+                                    (long)vpninfo->gid, strerror(errno));
                        return -EPERM;
                }
 
                if (setgroups(1, &vpninfo->gid)) {
-                       e = errno;
                        vpn_progress(vpninfo, PRG_ERR, _("Failed to set groups to %ld: %s\n"),
-                                    (long)vpninfo->gid, strerror(e));
+                                    (long)vpninfo->gid, strerror(errno));
                        return -EPERM;
                }
 
                if (setuid(vpninfo->uid)) {
-                       e = errno;
                        vpn_progress(vpninfo, PRG_ERR, _("Failed to set uid %ld: %s\n"),
-                                    (long)vpninfo->uid, strerror(e));
+                                    (long)vpninfo->uid, strerror(errno));
                        return -EPERM;
                }
        }
index f3a638da07901795ee3edf9a81b8c8423673a1ab..a491ead42e50b8cf3960cda5011d2527b97cabb5 100644 (file)
--- a/script.c
+++ b/script.c
@@ -668,11 +668,11 @@ int script_config_tun(struct openconnect_info *vpninfo, const char *reason)
                exit(127);
        }
        if (pid == -1 || waitpid(pid, &ret, 0) == -1) {
-               int e = errno;
+               int err = errno;
                vpn_progress(vpninfo, PRG_ERR,
                             _("Failed to spawn script '%s' for %s: %s\n"),
-                            vpninfo->vpnc_script, reason, strerror(e));
-               return -e;
+                            vpninfo->vpnc_script, reason, strerror(err));
+               return -err;
        }
 
        if (!WIFEXITED(ret)) {
diff --git a/tun.c b/tun.c
index 98f59991cdf94d4c94c1cd1935cfbb7deaf3f046..8bb6b61cd48cabd7e6e60b75b47c04b9a821f19a 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -393,10 +393,9 @@ intptr_t os_setup_tun(struct openconnect_info *vpninfo)
                         "/dev/%s", vpninfo->ifname);
                tun_fd = bsd_open_tun(tun_name);
                if (tun_fd < 0) {
-                       int err = errno;
                        vpn_progress(vpninfo, PRG_ERR,
                                     _("Cannot open '%s': %s\n"),
-                                    tun_name, strerror(err));
+                                    tun_name, strerror(errno));
                        return -EINVAL;
                }
        }