Merge pull request #17114 from Jafaral/getenv

vtysh: fix SA warning, no need to call getenv() twice
This commit is contained in:
Donatas Abraitis 2024-10-16 10:50:02 +03:00 committed by GitHub
commit 40dce0be6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -350,6 +350,7 @@ int main(int argc, char **argv, char **env)
char pathspace[MAXPATHLEN] = ""; char pathspace[MAXPATHLEN] = "";
const char *histfile = NULL; const char *histfile = NULL;
const char *histfile_env = getenv("VTYSH_HISTFILE"); const char *histfile_env = getenv("VTYSH_HISTFILE");
const char *logpath = getenv("VTYSH_LOG");
/* SUID: drop down to calling user & go back up when needed */ /* SUID: drop down to calling user & go back up when needed */
elevuid = geteuid(); elevuid = geteuid();
@ -643,9 +644,7 @@ int main(int argc, char **argv, char **env)
} }
} }
if (getenv("VTYSH_LOG")) { if (logpath != NULL) {
const char *logpath = getenv("VTYSH_LOG");
logfile = fopen(logpath, "a"); logfile = fopen(logpath, "a");
if (!logfile) { if (!logfile) {
fprintf(stderr, "Failed to open logfile (%s): %s\n", fprintf(stderr, "Failed to open logfile (%s): %s\n",