From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Sat, 1 Jan 2022 16:07:29 +0000 (+0100) Subject: No need to cache errno before _() X-Git-Tag: v9.00~45^2^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=62866e179ee28662ad5ea0ca388f8a1ae153a38f;p=users%2Fdwmw2%2Fopenconnect.git No need to cache errno before _() 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> --- diff --git a/auth.c b/auth.c index ad07b2a5..204eece9 100644 --- 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 d607a4e0..67f1608e 100644 --- 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 { diff --git a/gnutls.c b/gnutls.c index 91b95f33..1baa529a 100644 --- 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 a35f1512..ff708aa3 100644 --- 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; diff --git a/mainloop.c b/mainloop.c index 74f0f98c..08bb4ece 100644 --- a/mainloop.c +++ b/mainloop.c @@ -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; } } diff --git a/script.c b/script.c index f3a638da..a491ead4 100644 --- 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 98f59991..8bb6b61c 100644 --- 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; } }